Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

backtesting with stopp loss change

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    backtesting with stopp loss change

    Hi,

    I asked this question unfortunately in a wrong thread, so I hope someone can help me here.
    I want to know if it's possible to backtest/optimize a strategy with adjusting the stop loss when entry and adjustment trigger are calculated in the same candle.
    I'm using 240min candles and I want to backtest a strategy that moves the stop to breakeven after some ticks in the direction of the trade.
    So if I call and my stop is 20 ticks below the entry price, it will put the stop to the entry price after the stock gained for example 50 ticks trying afterwards to hit the target of 100 ticks.
    So if I'm backtesting this strategy I don't think it moves the stop after gaining 50 ticks within the same 240min candle where it entered the call. afterwards, at the next candles the backtest would show the adjustment i think. The problem shows up only in the same candle as the entry.
    My code is pretty similar to the code published once as an example for modifying the price of stop loss and profit target orders here in the forum by the Ninjatrader Customer Service.

    What do I have to change to get the stop moving during backtest within the same candle as the entry?

    Find the sample code attached.


    Thanks in advance!
    Attached Files

    #2
    Hello Hanko,

    Thanks for your post.

    Historical data is processed following CalculateOnBarClose=true rules. The strategy will not process OnBarUpdate following CalculateOnBarClose=false rules for backtesting. If you would like to test your strategy following CalculateOnBarClose=false rules so your logic is processed with each tick, you could test with the Market Replay connection to mimic realtime data. Alternatively, a single tick data series can be added to the script to have your strategy take actions with each new tick.

    Market Replay - https://ninjatrader.com/support/help...ket_replay.htm

    Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim!
      I will try to make it by using multi frame.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by zstheorist, Today, 07:52 PM
      0 responses
      3 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      149 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Working...
      X