> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# Creating the Strategy via Self Programming

If you have not done so already, press the "Unlock Code" button within the wizard to launch the NinjaScript Editor.

The **OnBarUpdate()** method is called for each incoming tick or on the close of a bar (user defined) when performing real-time calculations. Therefore, this is the main method called for strategy calculation and we will use this method to enter the script that checks for entry and exit conditions.

## The Entry and Exit Condition

Enter the code contained within the **OnBarUpdate()** method in the image below into the **OnBarUpdate()** method in the NinjaScript Editor:

```csharp
protected override void OnBarUpdate()
{
    if (CrossAbove(SMA(Fast), SMA(Slow), 1))
        EnterLong();

    if (CrossBelow(SMA(Fast), SMA(Slow), 1))
        EnterShort();
}
```

Translated into English, the code contained within the **OnBarUpdate()** method above reads:

if the fast simple moving average crosses above the slow simple moving average within the last bar, go long

if the fast simple moving average crosses below the slow simple moving average within the last bar, go short

To accomplish this we used the following methods:

* [CrossAbove](/developer/desktop-sdk/references/common/analytical/crossabove) - Checks for a cross above condition and returns true or false
* [CrossBelow](/developer/desktop-sdk/references/common/analytical/crossbelow) - Checks for a cross below condition and returns true or false
* [SMA](/developer/desktop-sdk/references/common/system-indicator-methods/moving-average-simple-sma) - Returns the value of a simple moving average
* [EnterLong](/developer/desktop-sdk/references/strategy/order-methods/managed-approach/enterlong) - Enters a market order long
* [EnterShort](/developer/desktop-sdk/references/strategy/order-methods/managed-approach/entershort) - Enters a market order short