Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy not executing in real time

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

    Strategy not executing in real time

    Dear NT Support,

    Could you please help me with a challenge?

    Scenario background:
    We have a strategy that uses multi-time frames of a single instrument (e.g. GBPUSD). This strategy executes very well during backtesting and optimisation in the Strategy Analyser.

    The strategy is time dependent, looking to trade between certain hours.

    I have a full subscription to Esignal and all necessary data is available.

    I have code in our strategy that automatically tests to ensure that there are sufficient days to prime the inter-day indicator. I have copied it here:


    Code:
         
      [COLOR=blue][FONT=&quot]protected[/FONT][/COLOR][COLOR=blue][FONT=&quot]override[/FONT][/COLOR][COLOR=blue][FONT=&quot]void[/FONT][/COLOR][COLOR=black][FONT=&quot] Initialize()[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]        {[/FONT][/COLOR]
      
      
      
      [COLOR=black][FONT=&quot]                  ClearOutputWindow();[/FONT][/COLOR]
      
      
      [COLOR=black][FONT=&quot]                  Add(PeriodType.Minute, [/FONT][/COLOR][COLOR=purple][FONT=&quot]1440[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  Add(PeriodType.Minute, [/FONT][/COLOR][COLOR=purple][FONT=&quot]15[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
      
      
      
      [COLOR=black][FONT=&quot]                  TraceOrders        = [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]            CalculateOnBarClose = [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                  AccountSize = [/FONT][/COLOR][COLOR=purple][FONT=&quot]10000[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]        }[/FONT][/COLOR]
      
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=gray][FONT=&quot]<summary>[/FONT][/COLOR]
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=green][FONT=&quot] Called on each bar update event.[/FONT][/COLOR]
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=gray][FONT=&quot]</summary>[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]protected[/FONT][/COLOR][COLOR=blue][FONT=&quot]override[/FONT][/COLOR][COLOR=blue][FONT=&quot]void[/FONT][/COLOR][COLOR=black][FONT=&quot] OnBarUpdate()[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]        {[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                  Print([/FONT][/COLOR][COLOR=maroon][FONT=&quot]"@ line 98"[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
      
      
      
      [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (BarsInProgress == [/FONT][/COLOR][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][COLOR=black][FONT=&quot])[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  {[/FONT][/COLOR]
      
      [COLOR=green][FONT=&quot]// Recalcuate ATR but do nothing else[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                        Print([/FONT][/COLOR][COLOR=maroon][FONT=&quot]"@ line 89"[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
      
      [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (CurrentBar < [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot]){[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                              Print([/FONT][/COLOR][COLOR=maroon][FONT=&quot]"@ line 93"[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
      
      [COLOR=green][FONT=&quot]//Print(BarsArray[1].Count);[/FONT][/COLOR]
      
      [COLOR=blue][FONT=&quot]return[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                        }[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                        dATR = ATR([/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot])[[/FONT][/COLOR][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][COLOR=black][FONT=&quot]];[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                        Print([/FONT][/COLOR][COLOR=maroon][FONT=&quot]"Current dATR = "[/FONT][/COLOR][COLOR=black][FONT=&quot]+dATR);[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                        trade_counter = [/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]; [/FONT][/COLOR][COLOR=green][FONT=&quot]// Reset the trade counter to 0 as no trade taken today[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                        dEMA = EMA(Typical, [/FONT][/COLOR][COLOR=purple][FONT=&quot]14[/FONT][/COLOR][COLOR=black][FONT=&quot])[[/FONT][/COLOR][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][COLOR=black][FONT=&quot]];[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                  }[/FONT][/COLOR]
    Problem statement:
    The strategy does not execute in real time. No error messages are found in the log (Control Centre). Suggestions other than putting out large chucks of code would be greatly appreciated. There are now over a 1000 lines of code attached to this strategy in distributed classes.

    Testing completed to date:
    I have adapted the standard SampleMACrossOver to include some print statements looking for execution. This runs as one would expect, executing trades until it arrives at the most recent data.

    I apply my strategy in the same way (Control Centre -> Strategies -> New Strategy).

    Test scenario 1:
    I set the required days to 1.

    The inserted print statements for debugging purposes execute as expected. (PDF screen shots emailed to support [at] ninjatrader.com referring to this thread). It gets through the 14 days required to prime the EMA indicator. I have also put debugging Print statements in the onbarupdate() function to ensure it is running. It appears to be doing so.

    Test scenario 2:

    I set the required days to 40 to ensure trades are taken to validate the strategy is executing. However, no output is put into the output window. (See PDF)

    Lesson learned (for myself and those coming across this post):
    As part of your development / unit testing cycle make sure you always apply the strategy in “live mode” to ensure it works.

    Thanks and regards,

    Dan

    #2
    Dan,

    When you bump it to 40 that means you require 40 bars in ALL of your bars series before your strategy will begin executing. 40 bars of 1440 minute is 40 days of lookback at the minimum. If you are running a strategy from the Strategies tab your default lookback on a minute chart is only 15 days. You are not loading enough days back to build the 40 bars required to start the strategy and as such the strategy never started.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      Thank you very much for your prompt reply.

      I don't think the number of days is the issue, however, I may have misunderstood your reply. I have attempted to execute the strategy using 1, 15 and 40 days. Regardless of this setting the strategy does not execute in real time.

      As for your point about data, I have a full subscription to Esignal, I have about 120 days of intra-day data available as standard. This should not be an issue with 40 days.

      Please see the screen shots emailed to the support email address. This shows the different output in the output window given the different settings of the number of days used for the "Min. Bars Required" field (15 & 40).

      Of course, if you need any additional information please don't hesitate to let me know. And if I have misunderstood your reply, please don't hesitate to let me know.

      Thanks and regards,

      Dan

      Comment


        #4
        Dan,

        "Min bars required" means ALL series in your strategy need at least that minimum amount of bars before the strategy will start. 1440min means 40 days minimum. That means you need to tell your strategy to use more than 40 days lookback to actually get the strategy to start. When you start loading strategies from the strategy the lookback period is determined in Tools->Options. Default is 15 days which is not enough to start your strategy with a bars required of 40.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          Thank you for your reply.

          I think I’ve identified the cause of the confusion: My strategy does not require 40 days of data. As per the code segment included in the initial post it only requires 15. This is to prime a 14EMA on the “daily” data. This data series is in the BarsArray element 1 (i.e. the second element). Please note “daily data”, I am not using 1440 min simulation. I am using daily bars. I find the daily bars are easier to align the daily bars produced by Esignal.

          I am specific in pointing out the daily data as you and your team has helped me clarify something before around using imported historical data (see thread here: http://www.ninjatrader-support2.com/...ad.php?t=17372). Is there something related around mixing these timeframes with a live strategy?

          Thanks and regards,

          Dan

          Comment


            #6
            Dan,

            It is very simple. You have a setting of "Min bars required". You need at least that amount of bars in ALL series before the strategy will start. If there are not enough bars in even one of them then the strategy doesn't start. You need to figure out how many days you need to load to get hit that minimum requirement across ALL series. For a secondary daily series, loading only 15 days is NOT enough to hit your minimum requirement.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh,

              Thank you for your reply.

              Unfortunately, I am not sure I understand. Can you please think of a other way to communicate your solution? What setting should I use?

              Thanks and regards,

              Dan

              Comment


                #8
                All you need to do is increase the number of days to load to allow you to have enough bars across all of your series.

                Tools->Options->Data
                Change the lookback for "Minute bars" to more than 40 days if you are trying to use "Min bars required = 40".
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Josh,

                  Thank you very much for your persistence in getting this solved.

                  I have now followed your suggestion as used value “40” in the Control Centre -> Options -> Data -> Chart default look back period (days) menu option. And the strategy now appears to be working, processing the minute bars as it should do.

                  Again, thank you for your help.

                  Kind regards,

                  Dan

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  668 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  377 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  110 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  575 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  580 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X