PDA

View Full Version : How to test stop loss and target strategies



Kor-Shachmupe
05-19-2016,
I have discovered that using SetProfitTarget and SetStopLoss functions in a strategy only work in real time. Is there a way to perform backtesting for stops and targets?

krystlekajadlj
05-21-2016,
SetStopLoss and SetProfitTarget do work in backtest as well as historical data.

These should be set before the order is placed.

Attached is an example made with the Strategy Wizard to demonstrate.

Please run this in the Strategy Analyzer or add to a chart. Ensure you have historical data showing in the backtest or chart.

The strategy will only enter a new order if the strategy is in a flat position.

This means after the first order, there will only be a second if the stop loss or profit target closes the order. (or the ExitOnClose)

Kristofer4
05-22-2016,
I assume this is an example stategy? I'm trying to figure out what to do with this file to allow me to open it in the Wizard or put it on a chart. I'll see if there is info on this.

KurtTuh
05-23-2016,
Yes, the attachment is an example strategy.

Follow these steps to import the NinjaScript:

1. Download the script to your desktop, keep it in the compressed .zip file.
2. From the Control Center window select the menu File > Utilities > Import NinjaScript
3. Select the downloaded .zip file
4. NinjaTrader will then confirm if the import has been successful.

Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

LapGofssags
05-24-2016,
Once imported, to view the strategy in the Strategy Wizard:

Click Tools -> Edit NinjaScript -> Strategy... -> StopLossTargetExampleWizard -> OK


To add the strategy to a chart:

Right-click the Chart -> select Strategies...
Select StopLossTargetExampleWizard from the list -> click the New button
In the parameters on the right -> set Enabled to True
Click OK


To backtest this in the Strategy Analyzer:

Click File -> New -> Strategy Analyzer...
Right-click an instrument from your instrument lists -> select Backtest
Click Run Backtest