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

NT8 Entry 2 bars too late...

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

    NT8 Entry 2 bars too late...

    Ok so I have read 1 bar is normal for the strategy analyzer but what I am experiencing is 2 bars too late. See attached image.

    As a preface I have a custom indicator with a custom data series for signals. The indicator is added to the strategy in the State.Configure within OnStateChange. When a signal is generated in the indicator it is added to the custom data series. The strategy then looks for signals from the indicator data series property and takes trades based off of this.

    Couple of notes:

    1) This is NT8
    2) Both indicator and strategy have Calculate.OnPriceChange
    a) I understand this will not work as expected for backtesting but changing to OnBarClose makes no difference. With the OnPriceChange in both indicator and strategy I have basic logic for actions that should only be taken when the bar actually closes. Something as simple as

    Code:
      private long lastBar = -1;
      
       protected override void OnBarUpdate()
       {
           ...// do OnPriceChange stuff here
           if(lastBar == CurrentBar) return;
           
           lastBar = CurrentBar;
           ...// do OnBarUpdate stuff here
    Since the max lookback is 256 for the signals data series the indicator will add a dummy signal on each bar unless overridden by an actual signal object for that bar once calculated.

    The strategy then looks for an actual signal object in the indicators data series, similar to this:

    Code:
        Signal signal = someCustomIndicator.Signals[0];
    In the attached image the white arrow shows where the indicator plotted a signal OnBarClose and the other arrow 2 bars later when the strategy took the trade....
    Thoughts...thanks!

    It's almost as if the strategy is running its code before the indicator can...
    Attached Files

    #2
    So in thinking about this I think this is happening:

    Bar 1 -> OnBarClose -> Determines pattern happened, draws arrow 1 bar ago and stores signal in data series as Signals[0] (which is actually bar 2 as bar 1 closed)
    Bar 2 -> OnBarClose -> See's the signal and places the trade on Bar 3.

    What is the ideal way around this when using a custom data series in NT? I tried adding the signal to Signals[1] but this doesn't work

    Comment


      #3
      Hello fxRichard,

      What is the condition that places the order?

      Do you have a print that prints the values of the variables used in the condition along with a timestamp?
      May we see this output?

      If an order is placed after a bar is closed, that order would have been placed as the new bar opens and will show on the new bar.

      I can demonstrate this by creating an example script that places an order every 10 minutes on a 1 minute chart. Each order will show on the ':01' or ':11' minute bar. Would you like a simple script that demonstrates this?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks for the response Chelsea. No need for the script. I think what is happening is a bar closes, my indicator looks for a pattern from the recently closed bar, if found places a signal. The strategy see's the signal and performs an enter trade which shows up on the next bar (2 bars after the signal was drawn.

        If I follow your guide for developing for tick-by-tick replay will this solve the problem or any other way to back test with tick-by-tick?

        Comment


          #5
          Hello fxRichard,

          This would be due to the logic in the script.

          I'm guessing that OnBarUpdate makes a pass after a bar closes and the condition sets a variable to a specific value. Then after the next bar closes a condition checks this variable and places an order. The order then appears on the next bar after this because it was submitted after a bar closes.

          Change your logic so that order is submitted immediately instead of waiting to submit the order on the next bar.


          I am uncertain how to address your question "If I follow your guide for developing for tick-by-tick replay will this solve the problem or any other way to back test with tick-by-tick?".

          This does not appear to be related to your initial inquiry, however, in general if you develop with tick replay in mind then you will not have issues with tick replay.

          As an example, if tick replay is on then the script cannot have any added data series.
          Last edited by NinjaTrader_ChelseaB; 08-16-2016, 04:02 PM.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X