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 time of EntryStop action

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

    Backtesting time of EntryStop action

    Hi,

    Firstly, there may be nothing wrong here but I just want to check my understanding.

    As an example, in a backtest I want to place an EntryStop based on the last candles volume say. (note: my data is 'end of time period' timestamped). The time recorded for the action is not the time the candle is recorded as being but rather the start time of the candle.

    Example: at 09:00 I check the volume of the last candle, that last candle being the 09:00 candle that is the recorded traded data between 08:59 and 09:00. If the volume is high enough I place an entry stop during the same OnBarUpdate loop at 09:00. If a trade happens immediately this would be during the 09:01 candle (that is, between 09:00- and 09:01 in my data) but the time of entry is recorded as 09:00 within OnExecution. The chart shows the activity on the 09:01 candle. Is it the case that the backtester is noting the trade as always occurring at the start of the candle rather than at the candle's specified time (that being the end point in my case)?

    This just seems odd because when I see a reported time of trade of 09:00 I tend to think I should look at the 09:00 candle for the trade. As long as what I have written above is correct it is slightly irrelevant.

    Hopefully that's clear.

    Thanks in advance,
    darmbk.

    #2
    Hi darmbk,

    Thanks for your note.

    Your understanding is correct. In backtest if an order is submitted it is submitted immediately after a bar closes. Let say the bar closed at 9:00 and then then order is submitted. This would be like 1 millisecond after the 9:00 bar closed and would be included with the 9:00 to 9:01 bar. This means the execution will read 9:00 (and probably 1 millisecond) but will show on the chart with the 9:01 bar.

    Basically, its because the order is submitted immediately after the bar closes.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the quick response. Ok, orders are submitted at the end of the bar, got it. However, now I am puzzled about the OnExecution call. Within OnExecution I also want to collect the volume of the candle within which the order is executed. In my earlier example, this would be the volume of the 09:01 candle. However, referring to Volume[0] in OnExecution returns the volume of the last candle, the 09:00 candle, that triggered the order to be submitted. How might I record the volume of the candle in which the EntryStop was activated, that being the 09:01 candle?

      Thanks again,
      darmbk.

      Comment


        #4
        Hi darmbk,

        You would need to run the strategy with CalculateOnBarClose set to false to access the volume of the currently being built bar (after only a few milliseconds I would expect the volume of the currently being built bar to very very low).

        Below is a link to the help guide on CalculateOnBarClose.
        http://www.ninjatrader.com/support/h...onbarclose.htm

        Also, here is a link to the help guide on Multi-Time Frame & Instruments. Please see the section 'How Bar Data is Referenced'.
        http://www.ninjatrader.com/support/h...nstruments.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          Many thanks for getting back to me.

          I have found that by using Volume[-1], I can get the volume of the bar in which the stop is actioned. That is the future closing volume of the current bar that has just started with the stop being actioned.

          Cheers,
          darmbk.

          Comment


            #6
            Hi darmbk,

            That was actually a bit of a surprise to me. NinjaTrader does create a -1 bar as it is collecting the data, however, I wasn't aware that could be accessed.

            Officially, this is not supported.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by yertle, Today, 08:38 AM
            5 responses
            14 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by frankthearm, Today, 09:08 AM
            2 responses
            5 views
            0 likes
            Last Post frankthearm  
            Started by adeelshahzad, Today, 03:54 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by bill2023, Yesterday, 08:51 AM
            6 responses
            27 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
            80 responses
            19,667 views
            5 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X