Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting when "on bar close" is "false"

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

    Backtesting when "on bar close" is "false"

    Hi guys,

    I'm wondering how to backtest few ideas based on 30 min bar when condition "calculate on bar close" is "false". Is there any way to look into bar and go through every tick move ?

    Thanks for tips.

    #2
    Hello KingElephant,

    To have code trigger for every tick, a 1 tick data series will need to be added to the script.

    Add(PeriodType.Tick, 1);

    Below is a link to the help guide on Add().
    http://www.ninjatrader.com/support/h...s/nt7/add3.htm

    Once the series is added, use BarsInProgress to have code trigger for a particular series.

    Below is a link to the help guide on BarsInProgress.
    http://www.ninjatrader.com/support/h...inprogress.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello

      I used this command:

      ...
      private PeriodType timeFrameUnit = PeriodType.Minute;
      private int timeFrameValue = 15;
      ...
      Add(timeFrameUnit, timeFrameValue);
      ...

      I use primary timeframe 1min (for backtest) and secondary timeframe 15min (for signal trigger) -everything is OK, but if I want change primary timeframe for 1tick, it doesnot work together with 15min secondar timeframe. can you help me what is wrong?

      Comment


        #4
        Hello Libri,

        This means you are adding a 15 minute series to your script.

        If you want your script to evaluate on every tick, you will need to add a 1 tick series to your script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you, it seems I didnot understand adding new timeframe. But now I cannot understand this thing:
          I have primary timeframe 15min, which is drawn on chart in backtest and I added 1tick timeframe.
          when backtest open position after signal from 15min, than close position on another price than generated PT (10tick) or SL(5tick) from unmanaged approach. I attached orders screen. my first question is what can do that time for open position is later than time for close position. and second question is about diferent between expected SL and real SL. i cannot imagine what can do it. i set SL and PT only in one place in script
          ...
          SetProfitTarget("ZZLow", CalculationMode.Ticks, profitTarget);
          SetStopLoss("ZZLow", CalculationMode.Ticks, stopLoss, false);
          ...
          and from chart i can see that real filled SL has the same price as open price of 15min bar in every cases.
          Attached Files

          Comment


            #6
            Originally posted by Libri View Post
            Thank you, it seems I didnot understand adding new timeframe. But now I cannot understand this thing:
            I have primary timeframe 15min, which is drawn on chart in backtest and I added 1tick timeframe.
            when backtest open position after signal from 15min, than close position on another price than generated PT (10tick) or SL(5tick) from unmanaged approach. I attached orders screen. my first question is what can do that time for open position is later than time for close position. and second question is about diferent between expected SL and real SL. i cannot imagine what can do it. i set SL and PT only in one place in script
            ...
            SetProfitTarget("ZZLow", CalculationMode.Ticks, profitTarget);
            SetStopLoss("ZZLow", CalculationMode.Ticks, stopLoss, false);
            ...
            and from chart i can see that real filled SL has the same price as open price of 15min bar in every cases.
            Set() methods work only relative to the primary chart barSeries. Try using the Exit()Stop methods instead.

            Comment


              #7
              Hello Libri,

              koganam is correct. SetStopLoss and SetProfitTarget are synced with the primary data series.

              This means that these orders are only able to process when the primary series is processing.


              The best approach may be the unmanaged approach using OCO ID's for the stop loss and profit target.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Sparkyboy, Today, 10:57 AM
              0 responses
              1 view
              0 likes
              Last Post Sparkyboy  
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              21 responses
              3,916 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              152 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              810 views
              1 like
              Last Post grayfrog  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Erick  
              Working...
              X