Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy that works in Market Replay and exploits in Analizer

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

    Strategy that works in Market Replay and exploits in Analizer

    Hello.
    I have the following problem, I am programming a strategy that uses 2 series one of 2 minutes and another of 2 seconds ( the secondary one ).
    Executing the strategy on the day (always happens to me) 09/11/2020.
    It gives me the following error in the bar 681 (the anteultimate one that brings the Strategy Analyzer) CurrentBars[1] == -1 ALWAYS in all the bars since it begins the strategy, that I know it because at the beginning of the OnBarUpdate() I ask: if (CurrentBars[1] == -1) return, there it doesn't fail but it doesn't execute anything of the code that follows it.
    Also it gives me an error in OnOrderUpdate in that same line.
    I generate prints in the following way in OnOrderUpdate:

    Code:
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
      string nameMethod = "OnOrderUpdate";
      if (CurrentBars[0] == 681)
      myPrint(string.Format("{0,-40} - 0.000 - Primary BarNbr = {1,7} - Secondary BarNbr = {2,7} - starting process", nameMethod, this.CurrentBars[0], this.CurrentBars[1]));
      if (CurrentBars[0] == 681)
      myPrint(string.Format("{0,-40} - 0.010 - order received = {1}", nameMethod, order));
    ...
    at the end
    
     if ((CurrentBars[0] == 681))
     {
       myPrint(string.Format("{0,-40} - 8.000 - post allTrades.OnOrderUpdate(true, ...) - Primary BarNbr = {2,7} - Secondary BarNbr = {3,7}", nameMethod, order, CurrentBars[0], CurrentBars[1] ));
       myPrint(string.Format("{0,-40} - 8.100 - order = {1} ", nameMethod, order, CurrentBars[0], CurrentBars[1] ));
       return;
      }
     if (sParms.levelToDebug.IndexOf(nameMethod) != -1)
     {
       myPrint(string.Format("{0,-40} - 9.000 - order orderstate is valid = [{1}]", nameMethod, order, CurrentBars[0] ));
     }
    }
    return // OnOrderUpdate
    The output:

    OnOrderUpdate - 0.000 - Primary BarNbr = 681 - Secondary BarNbr = -1 - starting process
    OnOrderUpdate - 0.010 - order received = orderId='NT-00008-358' account='Backtest' name='CTT_2' orderState=Cancelled instrument='MES 12-20' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=3668.75 quantity=1 tif=Gtc oco='CTT_2-OCO-' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-09 11:00:00' gtd='2099-12-01' statementDate='2021-01-15'
    OnOrderUpdate - 1.000 - myTime = 18:58
    OnOrderUpdate - 8.000 - post allTrades.OnOrderUpdate(true, ...) - Primary BarNbr = 681 - Secondary BarNbr = -1
    OnOrderUpdate - 8.100 - order = orderId='NT-00008-358' account='Backtest' name='CTT_2' orderState=Cancelled instrument='MES 12-20' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=3668.75 quantity=1 tif=Gtc oco='CTT_2-OCO-' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-09 11:00:00' gtd='2099-12-01' statementDate='2021-01-15'
    OnOrderUpdate - 8.000 - post allTrades.OnOrderUpdate(true, ...) - Primary BarNbr = 681 - Secondary BarNbr = -1
    OnOrderUpdate - 8.100 - order = orderId='NT-00007-358' account='Backtest' name='CTT_2' orderState=Cancelled instrument='MES 12-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2814.5 quantity=1 tif=Gtc oco='CTT_2-OCO-' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-09 11:00:00' gtd='2099-12-01' statementDate='2021-01-15'

    Strategy 'CTT/-1': Error on calling 'OnOrderUpdate' method on bar 681: Object reference not set to an instance of an object.
    The strange thing is that the last order skips the initial steps 0.000 and 0.010 (I use them only because of this error)

    ATTENTION:
    With Market Replay I don't have any error.


    Apparently it happens in an Exit on session close, but I am not sure because it is in the anteultimate bar that the analyzer delivers ...
    ​​​​​​​
    Translated with www.DeepL.com/Translator (free version)

    #2
    Hello mbcito,

    Thank you for the post.

    The error you are getting means an object you used was null :

    Strategy 'CTT/-1': Error on calling 'OnOrderUpdate' method on bar 681: Object reference not set to an instance of an object.

    When using order objects or the order events you need error handling to make sure the object you are using are not null. This is shown in the samples that we provide: https://ninjatrader.com/support/help...ghtsub=onorder

    Take a look at the "Properly assigning order object values" sample, that includes a null check for the order object. This error can also be generated for other objects that are used which are null so you may need to debug the script some to find what line causes the error.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Jesse!!

      I understand, that's why at the beginning I make a printed output at the beginning of OnOrderUpdate, but it does not seem to cancel at the invocation of the method, I still do not understand what happens:
      In the bar 681 I have several events, and you can see that it passes through that sector of the same, but the last event that is the cancellation of a Stop Market order, does not pass through that sector of the method (first print named 0.000), that's what I do not understand, please look more closely at the code.
      It must go through 0.000, 0.010, 8.000 and 8.100, for the previous order MIT works, with the Stop order it does not go through 0.000, 0.010 but through 8.000 and 8.100 steps,THAT'S NOT LOGICAL. The crazy thing is that it works for Market Reply ...

      Code:
      protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
      {
      string nameMethod = "OnOrderUpdate";
      if (CurrentBars[0] == 681)
      myPrint(string.Format("{0,-40} - 0.000 - Primary BarNbr = {1,7} - Secondary BarNbr = {2,7} - starting process", nameMethod, this.CurrentBars[0], this.CurrentBars[1]));

      Comment


        #4
        Hello mbcito,

        I can't tell why the error happened by looking at this type of sample, if you are seeing an error that's a situation you need to explore on your end in the situation where you see the error. You would need to use prints to find what line is having that error to better understand why.

        From the prints you have the error happens after 8.100 so we know that it happened likely on the next call to OnOrderUpdate because you have a return statement in 8.100. To find whats null you would need to check each object that can be null, you can print if something is null like the following:

        Print("order is null: " + (order == null));




        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you Jesse, it seems to be a licensing issue.
          I have my lifetime license running the strategy and another unlicenced where I do the development and test.
          When I run this version of the strategy on the production machine and don't get this error.
          I would like to know if this is contemplated. Because the truth is that buying a license for development at $1100 seems excessive at this time for me.

          Regards!

          Comment


            #6
            Hello mbcito,

            You could try running the same license on both systems to test that, just use one machine at a time for the testing or use the @Sim license for both. I am not aware of a reason that the license would affect OnOrderUpdate or cause a null object.

            The error you are getting is still just a C# error stating that an object was null and you don't have the appropriate handling for whatever object that was. The steps to find that problem would still be the same, to use prints to find the line causing the error so we know more about what relates to the problem.


            I look forward to being of further assistance.



            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ntbone, Today, 02:30 PM
            0 responses
            5 views
            0 likes
            Last Post ntbone
            by ntbone
             
            Started by tuliomgui, Yesterday, 10:07 PM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by Learner Trader, Today, 08:36 AM
            1 response
            24 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by GeorgeW, Today, 03:15 AM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by timko, Today, 11:55 AM
            4 responses
            11 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Working...
            X