Thread: How to test stop loss and target strategies

Results 1 to 5 of 5

  1. #1
    Kor-Shachmupe
    Guest

    Default How to test stop loss and target strategies

    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?
  2. #2
    krystlekajadlj
    Guest

    Default

    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)
  3. #3
    Kristofer4
    Guest

    Default

    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.
  4. #4
    KurtTuh
    Guest

    Default

    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.
  5. #5
    LapGofssags
    Guest

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts