BreakEven Builder Strategy for NinjaTrader
BreakEven Builder Strategy for NinjaTrader
TriggerState is a numerical variable used to track the progression of trade conditions and actions in the strategy. It holds different values indicating the trade's lifecycle stages: from initiating a trade (value 1), modifying the stop price to breakeven (value 2), to adjusting the stop price once the TriggerPrice is met (value 3). Managing these states is crucial for executing precise trade actions, synchronizing trade operations, and ensuring coherent state transitions during the trade's lifecycle .
Within the "BreakEvenBuilderExampleUNLOCKE" strategy, several chart indicators are added to enhance visual analysis and decision-making. Specifically, EMA1 is plotted using a Goldenrod brush, WMA1 with a White brush, EMA2 with Dark Cyan, and EMA3 with Dark Red. These visual cues help traders quickly interpret market conditions and crossovers through color-coded indicators directly on the chart, aligning with the strategy's logic and facilitating the trader’s situational awareness .
The property "IsInstantiatedOnEachOptimizationIteration" is disabled to improve the performance of strategy analyzer optimizations. By default, each optimization creates a new instance of the strategy, which can be resource-intensive when running multiple iterations. Setting this property to false reduces the overhead by reusing instances where possible, thereby speeding up the optimization process and consuming fewer system resources .
The "BreakEvenBuilderExampleUNLOCKE" strategy employs both Exponential Moving Averages (EMA) and Weighted Moving Average (WMA) to generate entry signals. Specifically, the strategy enters a long position if there is a crossover where EMA1 crosses above WMA1, coupled with a condition that EMA2 is greater than EMA3 during the specified trading hours. Conversely, for a short position, the strategy looks for EMA1 crossing below WMA1 with EMA2 being less than EMA3 .
The "OrderFillResolution" option set to "Standard" determines the granularity at which order fills are simulated within the strategy. A "Standard" resolution provides a balanced level of detail in fill simulation, which is sufficient for many strategies while maintaining computational efficiency. It affects how accurately the backtesting environment represents market conditions, influencing the strategy's historical performance analysis and real-world execution similarity .
The strategy is configured to start trading at 2:00 AM and end at 11:00 AM. These times are crucial as they define the trading window during which the strategy will actively monitor and execute trades. This time frame might align with specific market sessions that the strategy designer considers beneficial for trading, possibly due to higher liquidity or volatility .
The breakeven trigger in the "BreakEvenBuilderExampleUNLOCKE" strategy is used to adjust the position's stop price based on certain trade conditions. When a position reaches the specified number of ticks beyond the entry price (as defined by BreakEvenTrigger), the stop price is adjusted to the entry price for minimizing potential losses and locking in profits. This mechanism changes the trade's risk profile by reducing the possibility of a loss once the market has moved favorably .
The "InitialStopLong" and "InitialStopShort" parameters determine the initial placement of stop-loss orders when entering long and short positions, respectively. "InitialStopLong" is expressed as a negative number, representing the number of ticks below the entry price for a long position, while "InitialStopShort" is a positive number for ticks above the entry price for a short position. These parameters are critical for setting the initial risk level of each trade .
Once the unrealized profit of a position reaches or exceeds the Take Profit (TP) threshold specified in ticks, the strategy executes an exit order. It closes both long and short positions via the "ExitLong" and "ExitShort" methods with the label "You Win,” ensuring that profits are locked in and positions are closed once the specified profit target is met .
The "ExitOnSessionClose" functionality is designed to exit positions a specified number of seconds before the market close. In this strategy, the positions are exited 30 seconds before the session closes. This feature ensures that all open trades are closed within the current trading session, mitigating risks related to overnight price gaps and ensuring the strategy does not hold positions outside its defined active window .