Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongLimit() and Null

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

    #16
    No, I cannot do that because the strategy a) exits the position if condition#1 b) reverse/enter opposite direction if condition#2. Therefore, if condition#2 is false then I do not want to enter a position.

    Comment


      #17
      Originally posted by alex.nt View Post
      No, I cannot do that because the strategy a) exits the position if condition#1 b) reverse/enter opposite direction if condition#2. Therefore, if condition#2 is false then I do not want to enter a position.
      Now that was dumb of me! I know I read that, then I made a silly reply. Dang.

      Comment


        #18
        Hi ,

        I'm a Ninjatrader Partner and develop lots of indicators and strategies since 3 years.
        I have client asking me for a special strategy that run on 1 tick timeframe (very fast)
        I never tried a strategy aat that speed but why not...

        The strategy is simple , it trades only Long or only Short (using a parameter)
        So it cannot reverse.

        It puts a EnterLongLimit at a certain amount of ticks of the current price...
        And it wait to be touch.. Or if conditions change it moves the EnterLongLimit.

        There is also a condition when the order is cancelled (if too close to Day High or Low)

        And guess what !!!

        I have exactly the same problem with IOrder become null

        The strategy can run one hours , taking lot of trades without problems... And at a moment, the entryOrder variable is null...

        I forgot to say that when the entry is filled , a stop loss and a targets are created...

        Here , the entryOrder become null ; but the order is still working.

        So when it fills , it enter OnExecution , but as entryOrder is null , it doesn't enter in my tests and it doesn't create the stop and target. So a little later I have an exception object not reference when I try to move the target.

        There is a real problem in the managed approach when orders are trigering events quicly !!!

        Just to explain a little more with examples :

        Code:
                                            // Cas ou on est dans les limites tradables
                                            if (entryOrder == null) 
                                            {
                                                entryOrder = EnterLongLimit(0, true, contractLots, limitPriceLong, "Entry");                    
                                                PrintDebug("INITIALISATION EnterLongLimit , at limit : " + limitPriceLong);
                                            }
                                            else if (entryOrder.LimitPrice != limitPriceLong){
                                                entryOrder = EnterLongLimit(0, true, contractLots, limitPriceLong, "Entry");                    
                                                PrintDebug("DEPLACEMENT EnterLongLimit , at limit : " + limitPriceLong);
                                            }
        The printDebug method use the Print and write on the output window.

        In the beginning of OnOrderUpdate , I have this :

        Code:
                /// <summary>
                /// OnOrderUpdate(IOrder order)
                /// </summary>
                /// <param name="order"></param>
                protected override void OnOrderUpdate(IOrder order)
                {
                    PrintDebug("Enter OnOrderUpdate :" + order.Name + " , " + order.OrderState.ToString() );
                    if (order.Name == "Entry") 
                    {
                        if (entryOrder != null) PrintDebug("EntryOrder != null");
                    }
        And in the beginning of OnExecution :

        Code:
                /// <summary>
                /// OnExecution(IExecution execution)
                /// </summary>
                protected override void OnExecution(IExecution execution)
                {
                    PrintDebug("Enter OnExecution" + execution.Name + " , " + execution.Order.Name);
                    if (entryOrder != null) PrintDebug("EntryOrder != null");
                        
                    // Gestion du Entry
                    //=================
                    if (entryOrder != null && entryOrder == execution.Order) 
                    {
                        PrintDebug("... Passage dans OnExecution : gestion Entry Order");
        This is what I have in the ouput for an order initialisation when it runs well


        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | DEPLACEMENT EnterLongLimit , at limit : 6738
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | DEPLACEMENT EnterLongLimit , at limit : 6738,5
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | DEPLACEMENT EnterLongLimit , at limit : 6739
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | DEPLACEMENT EnterLongLimit , at limit : 6739,5
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | Enter OnOrderUpdate :Entry , PendingChange
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | EntryOrder != null
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | Enter OnOrderUpdate :Entry , Accepted
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | EntryOrder != null
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | Enter OnOrderUpdate :Entry , Working
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | EntryOrder != null
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | Enter OnOrderUpdate :Entry , PendingChange
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | EntryOrder != null
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | => [Flat: 0] Pnl : 0,00 , maxGain : 0,00 , maxLoss : 0,00
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | Enter OnOrderUpdate :Entry , Accepted
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | EntryOrder != null
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | Enter OnOrderUpdate :Entry , Working
        ***[AccelerationCounterStrategy] - FD: 19/04/2012 13:25:00 | EntryOrder != null

        The lines with [Flat:0] are written by a method called on each onBarUpdate to calculate the Day Pnl...

        So as you see there were 4 calls to EnterLongLimit (see DEPLACEMENT print) with each time a new value. and only 1 time , it entered onOrderUpdate.

        Sometimes , after a DEPLACEMENT print...
        it print a INITALISATION print. That proof the lost of the entryOrder as already show in this code :

        Code:
                                            // Cas ou on est dans les limites tradables
                                            if (entryOrder == null) 
                                            {
                                                entryOrder = EnterLongLimit(0,  true, contractLots, limitPriceLong, "Entry");                    
                                                PrintDebug("INITIALISATION EnterLongLimit , at limit : " + limitPriceLong);
                                            }
                                            else if (entryOrder.LimitPrice != limitPriceLong){
                                                entryOrder = EnterLongLimit(0,  true, contractLots, limitPriceLong, "Entry");                    
                                                PrintDebug("DEPLACEMENT EnterLongLimit , at limit : " + limitPriceLong);
                                            }
        And of course , the strategy get an exception on object reference not fount later...

        As I'm not alone to show you that problem , I hope you will check it quicly.

        Regards

        Comment


          #19
          Hello,

          Thanks for the post.

          Basically the iOrder object should not be nullified unless the user has nullified it. If this is the case I would want to get it into development.

          However before we do that I wanted to take a look at your code you are using to null the iOrder object. Possible issue is in the code segment you are using to nullify it.

          Please send code snippits for any code that sets this iOrder object to null.

          -Brett

          Comment


            #20
            Furthermore, OnBarUpdate() and OnOrderUpdate() are Asynchronous. Which means they can run in any order.

            With the fact that you are using very small time series likely you are running into some sort of race condition here also between the two methods.

            -Brett

            Comment


              #21
              Hi Bret and thank you for your answer...

              However before we do that I wanted to take a look at your code you are using to null the iOrder object. Possible issue is in the code segment you are using to nullify it.
              Please , 4 persons explained the same problem , and you continue to return the error to us.

              the EnterLongLimit gives sometime NULL as return and that is the problem...
              It is very easy to proove it.
              And you could realize a very short strategy with the function EnterLongLimit and move the order on a simple condition. Run it on a 1 tick timeframe.

              To show you , I just add an exception to my code :

              Code:
              entryOrder = EnterLongLimit(0, true, contractLots, limitPriceLong, "Entry");                  
              if (entryOrder == null) 
              {
                PrintDebug("ERROR ON CALL EnterLongLimit , entryOrder is Null after call");
                throw new Exception("ERROR ON CALL EnterLongLimit , entryOrder is Null after call");
              }
              As Ninjatrader Support already answered , my entryOrder should always have a value...
              So I just check Null on next line (the closer possible).
              If it is null , I write in the Output and throw an exception to stop the strategy

              As you already know , I have Prit at the begining od OnOrderUpdate , OnExecution

              and this is the output :

              Code:
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:51 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:52 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:52 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:52 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:52 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 |  => [Flat: 0] Pnl : 15,20 , maxGain : 15,20 , maxLoss : 0,00
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 | ERROR ON CALL EnterLongLimit , entryOrder is Null after call
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 | EXCEPTION AFTER LINE : 11
              ***[AccelerationCounterStrategy] - FD: 19/04/2012 16:41:53 | ERROR ON CALL EnterLongLimit , entryOrder is Null after call
              **NT** Error on calling 'OnBarUpdate' method for strategy 'AccelerationCounterStrategy/b5d9c69342da405e9698fc78f110c0b8': ERROR ON CALL EnterLongLimit , entryOrder is Null after call
              As you can see there were no enter on any even (onOrderUpdate , onExecution) because there is no print...

              So the entryOrder was returned null from EnterLongLimit !

              Please do the same little test and you will see

              For information , I'm using a Mirus account with ZenFire...

              Regards

              Comment


                #22
                Hello,

                Thanks for posting that.

                This test is actually an invalid test.

                I would expect your code output on the first call to EnterLongLimit to create the order.

                Here is why in a very simplified scenario,. Remember these action are taking less then milliseconds to occur however it still can occur.

                ->Script Running in Thread B the ninjascript thread makes call to enter an order. This order is submitted by the NinjaTrader CORE which is running on thread A in this example.

                ->Thread B makes call to thread A to create the order.

                ->Thread B moves to the next line of code and executes the null check in your example.

                ->Null check comes back as null correctly. As Thread A isn't done processing the order yet and hasn't assigned any order information to the created object. Object is still is null at the time of the check.

                ->Thread A Initializes the order, fills order object with order state and calls OnOrderUpdate() and sets state to Initialized or Pending Submit. This is the reason why OnOrderUpdate() exists, as OrderUpdates occur in the NinjaTrader Core and this is how the CORE notifies the running script that the order has been updated.


                This is the sequence of events you can run into. I would suggest that you only do any null checking inside of OnOrderUpdate() or OnExecutionUpdate(). If you see any iOrder checking in any of our sample code outside of OnOrderUpdate() to null please let me know and I will look into the code sample and make a correction however the rule of thumb is to only check order states in OnOrderUpdate(). Use this to set any flags needed for your OnBarUpdate().

                -Brett
                Last edited by NinjaTrader_Brett; 02-21-2017, 08:27 AM.

                Comment


                  #23
                  I also wanted to make sure you are aware of this sample:

                  The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()

                  Comment


                    #24
                    Bret ,

                    Yes I know those examples...

                    And I repeat , I'm a NinjaTrader Partner , and also a .NET Architect Developer since the begining.

                    I wrote lot of strategies and sold a lot using always the same Order structure (as explained in your example).

                    I never had this problem... Even with multo Target , trailing stop , logics to add more contracts to an open trade...

                    So , I think the spead of 1 tick is certainly one cause... But you must admit that the system have to run correctly in all cases.

                    I just added the little test with the exception to show you that the entryOrder object inside onBarUpdate can be null after the call... But in the real strategy , I'm not using it at that moment.. I assign the value to use it in OnExecution...

                    So the process are :

                    in the OnBarUpdate :

                    Code:
                    double limitPriceLong = Instrument.MasterInstrument.Round2TickSize(Close[0] - ((accelerationSize - ACC.Acceleration[0]) * TickSize)) ;
                    if (CheckDayOHLOk(limitPriceLong)) 
                    {
                        // Cas ou on est dans les limites tradables
                        if (entryOrder == null) 
                        {
                            entryOrder = EnterLongLimit(0, true, contractLots, limitPriceLong, "Entry");                PrintDebug("INITIALISATION EnterLongLimit , at limit : " + limitPriceLong);
                        }
                        else if (entryOrder.LimitPrice != limitPriceLong){
                            PrintDebug("DEPLACEMENT EnterLongLimit , at limit : " + limitPriceLong);
                        }
                    }
                    else
                    {        
                        // Cas ou on est hors des limites Day OHL => on cancel
                        if (entryOrder != null) 
                        {
                            CancelOrder(entryOrder);                    
                            PrintDebug("CANCEL ORDER Cause Limit Day OHL : " + limitPriceLong);
                        }
                    }
                    the OnOrderUpdate is only use to reset iOrder object if cancel...

                    Code:
                            /// <summary>
                            /// OnOrderUpdate(IOrder order)
                            /// </summary>
                            /// <param name="order"></param>
                            protected override void OnOrderUpdate(IOrder order)
                            {
                                PrintDebug("Enter OnOrderUpdate :" + order.Name + " , " + order.OrderState.ToString() );
                                if (order.Name == "Entry") 
                                {
                                    if (entryOrder != null) PrintDebug("EntryOrder != null");
                                }
                    
                                if (entryOrder != null && entryOrder == order)
                                {    
                                    // Reset the entryOrder object to null if order was cancelled without any fill
                                    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                                    {
                                        PrintDebug("... Passage dans OnOrderUpdate : On clear Entry Order");
                                        entryOrder = null;
                                    }
                                    return;
                                }
                    
                                if (targetOrder != null && targetOrder == order)
                                {    
                                    // Reset the targetOrder object to null if order was cancelled without any fill
                                    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                                    {
                                        PrintDebug("... Passage dans OnOrderUpdate : On clear Target 1 Order");
                                        targetOrder = null;
                                    }
                                    return;
                                }
                    
                                if (stopOrder != null && stopOrder == order)
                                {    
                                    // Reset the stopOrder object to null if order was cancelled without any fill
                                    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                                    {
                                        PrintDebug("... Passage dans OnOrderUpdate : On clear stopAfterT1 Order");
                                        stopOrder = null;
                                    }
                                    return;
                                }
                                
                                if (haltStratOrder != null && haltStratOrder == order)
                                {    
                                    // Reset the haltStratOrder object to null if order was cancelled without any fill
                                    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                                    {
                                        PrintDebug("... Passage dans OnOrderUpdate : On clear haltStratOrder Order");
                                        haltStratOrder = null;
                                    }
                                    return;
                                }
                            }
                    and the onExecution is use to manage Stops , Targets...

                    Code:
                            /// <summary>
                            /// OnExecution(IExecution execution)
                            /// </summary>
                            protected override void OnExecution(IExecution execution)
                            {
                                PrintDebug("Enter OnExecution" + execution.Name + " , " + execution.Order.Name);
                                if (entryOrder != null) PrintDebug("EntryOrder != null");
                                    
                                // Gestion du Entry
                                //=================
                                if (entryOrder != null && entryOrder == execution.Order) 
                                {
                                    PrintDebug("... Passage dans OnExecution : gestion Entry Order");
                                    if (execution.Order.OrderState == OrderState.Filled || 
                                        execution.Order.OrderState == OrderState.PartFilled || 
                                        (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                                    {
                                        // On memorise le prix d'entree pour le calcul du gain Max
                                        entryPrice = Position.AvgPrice;
                    
                                        if (execution.MarketPosition == MarketPosition.Long)
                                        {
                                            // On place les target sur le COG
                                            PrintDebug("....... targetOrder = ExitLongLimit(0, true, 1, entryPrice + (Instrument.MasterInstrument.TickSize * target1Ticks),'T1','');");
                                            targetOrder = ExitLongLimit(0, true, contractLots, entryPrice + (Instrument.MasterInstrument.TickSize * target1Ticks),"T1","");
                    
                                            // On place le Stop sur le COG ou AvgPrice
                                            PrintDebug("....... stopOrder = ExitLongStop(0,true,Position.Quantity, entryPrice,'STOP','')");
                                            stopOrder = ExitLongStop(0,true,Position.Quantity, entryPrice - (Instrument.MasterInstrument.TickSize * stopInitTicks),"STOP","");
                                        }
                                        else if (execution.MarketPosition == MarketPosition.Short)
                                        {
                                            // On place les target sur le COG
                                            PrintDebug("....... targetOrder = ExitShortLimit(0, true, 1, entryPrice - (Instrument.MasterInstrument.TickSize * target1Ticks),'T1','');");
                                            targetOrder = ExitShortLimit(0, true, contractLots, entryPrice - (Instrument.MasterInstrument.TickSize * target1Ticks),"T1","");
                    
                                            // On place le Stop sur le COG ou AvgPrice
                                            PrintDebug("....... stopOrder = ExitShortStop(0,true,Position.Quantity, entryPrice,'STOP','')");
                                            stopOrder = ExitShortStop(0,true,Position.Quantity, entryPrice + (Instrument.MasterInstrument.TickSize * stopInitTicks),"STOP","");
                                        }
                    
                                        // Resets the entryOrder object to null after the order has been filled
                                        if (execution.Order.OrderState != OrderState.PartFilled)
                                        {
                                            PrintDebug("....... entryOrder    = null;");
                                            entryOrder     = null;
                                        }
                                    }
                                    return;
                                }
                    So the problem is :

                    At a moment , as explained the 'entryOrder' become null

                    when it enter in onExecution (some milisecond or even seconds... later)

                    the code :

                    // Gestion du Entry
                    //=================
                    if (entryOrder != null && entryOrder == execution.Order)

                    return false

                    So , no Stop and no Target are created !
                    And my clients are upset because they have an open position withtout protection

                    The structure of my code is not very far from your example

                    There is absolutely no logical reason to enter onExecution with an executionName = "Entry" and have the entryorder = null.

                    As already explain , the code can run more than one hour , taking near 10 to 20 trades , managing perfectly the Limit order and after the Stop and Targets without problem.
                    And at a moment... entryOrder become null after EnterLongLimit...

                    So if there is no problem (as you try to explain) , please explain us how to process.

                    Does an unmanaged solution could resolve it ?

                    Regards

                    Comment


                      #25
                      Just to add an information.

                      That can be important...

                      The problem NEVER comes on Market Replay...

                      Regards

                      Comment


                        #26
                        Thanks for posting the snippet that I needed to look into and originally requested. The sample code provided was an invalid test and unrelated for the reasons I previously stated.

                        Now on this new code snippets you submitted everything looks good thus far and I cannot see any race conditions issues with your code right now. However i may need to run a sample on my side and try to reproduce the issue in the debugger to confirm.

                        You said the following:

                        Code:
                        // Gestion du Entry
                                    //=================
                                    if (entryOrder != null && entryOrder == execution.Order) 
                        
                        return false
                        That is returning false. To me this could be the null check returning false or the entryOrder == execution.Order returning false.

                        I isolated an issue that was related to this that was resolved in .8. Are you on .8 or above when you are getting this result?

                        Here is the fix in the Releases notes for .8:

                        Fixed
                        4587
                        NinjaScript Strategies
                        Checking for order identity did not always work for auto stop/target orders


                        Could be there is something going on with this as well.

                        So if I take your exact OnBarUpdate/OnOrderUpdate()/OnOrderExecution() code and run it on some 1 tick chart series I should see it on the Sim101 account or what I need a live account to see this in my tests?

                        -Brett

                        Comment


                          #27
                          Brett ,

                          On the previous message I isolated the if condition just to show you...

                          But if you see the code I sent for the onExecution more completely :

                          Code:
                                  /// <summary>
                                  /// OnExecution(IExecution execution)
                                  /// </summary>
                                  protected override void OnExecution(IExecution execution)
                                  {
                                      PrintDebug("Enter OnExecution" + execution.Name + " , " + execution.Order.Name);
                                      if (entryOrder != null) PrintDebug("EntryOrder != null");
                                          
                                      // Gestion du Entry
                                      //=================
                                      if (entryOrder != null && entryOrder == execution.Order)
                          You see there is already an if (entryorder != null) just above to print a message in the output.
                          I added that code only to try to understand what is happening.

                          And when I have the problem , it prints nothing , so entryOrder is really null at that moment...

                          I'm using Ninjatrader 7.0.1000.9

                          I made the test on FDAX , connected to zenfire and using the Sim101 account.
                          (but my clients had the problem with other contracts. They are also using Zenfire)

                          Thanks for your help...

                          Regards

                          (and sorry for my english , I speak french usualy)

                          Comment


                            #28
                            Do you have the Output handy for when this occurs.

                            As it could be OnExecution never gets called also as I looked at the output you originally posted and I dont see this:

                            PrintDebug("Enter OnExecution" + execution.Name + " , " + execution.Order.Name);

                            Comment


                              #29
                              I made a new test to give you an output...

                              I removed the PrintDebug on each onBarUpdate that print the Day Pnl , Max Gain ,Max Loss

                              because it create a lot of lines and it is not important for our subject.

                              This is the full Output from the start of the strategy :

                              Code:
                              ***[Acc] - FD: 19/04/2012 21:33:15 | INITIALISATION EnterLongLimit , at limit : 6661,5
                              ***[Acc] - FD: 19/04/2012 21:33:15 | Enter OnOrderUpdate :Entry , PendingSubmit
                              ***[Acc] - FD: 19/04/2012 21:33:15 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:15 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:33:15 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:15 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:33:15 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:22 | DEPLACEMENT EnterLongLimit , at limit : 6660,5
                              ***[Acc] - FD: 19/04/2012 21:33:25 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:33:25 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:25 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:33:25 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:25 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:33:25 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:32 | DEPLACEMENT EnterLongLimit , at limit : 6661
                              ***[Acc] - FD: 19/04/2012 21:33:32 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:33:32 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:32 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:33:32 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:33:32 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:33:32 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:15 | DEPLACEMENT EnterLongLimit , at limit : 6661,5
                              ***[Acc] - FD: 19/04/2012 21:34:17 | DEPLACEMENT EnterLongLimit , at limit : 6662
                              ***[Acc] - FD: 19/04/2012 21:34:17 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:17 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:17 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:17 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:17 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:17 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:17 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:17 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:17 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:17 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:17 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:17 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:17 | DEPLACEMENT EnterLongLimit , at limit : 6662,5
                              ***[Acc] - FD: 19/04/2012 21:34:18 | DEPLACEMENT EnterLongLimit , at limit : 6663
                              ***[Acc] - FD: 19/04/2012 21:34:18 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:18 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:18 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:18 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:18 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:18 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:18 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:18 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:18 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:18 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:18 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:18 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:31 | DEPLACEMENT EnterLongLimit , at limit : 6663,5
                              ***[Acc] - FD: 19/04/2012 21:34:31 | DEPLACEMENT EnterLongLimit , at limit : 6664
                              ***[Acc] - FD: 19/04/2012 21:34:31 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:31 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:31 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:31 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:31 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:31 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:31 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:31 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:31 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:31 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:31 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:31 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:49 | DEPLACEMENT EnterLongLimit , at limit : 6662,5
                              ***[Acc] - FD: 19/04/2012 21:34:49 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:49 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:49 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:49 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:49 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:49 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:52 | DEPLACEMENT EnterLongLimit , at limit : 6663
                              ***[Acc] - FD: 19/04/2012 21:34:52 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:34:52 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:52 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:34:52 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:34:52 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:34:52 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:36 | DEPLACEMENT EnterLongLimit , at limit : 6663,5
                              ***[Acc] - FD: 19/04/2012 21:35:36 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:35:36 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:36 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:35:36 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:36 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:35:36 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:44 | DEPLACEMENT EnterLongLimit , at limit : 6664
                              ***[Acc] - FD: 19/04/2012 21:35:44 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:35:44 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:44 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:35:44 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:44 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:35:44 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:46 | DEPLACEMENT EnterLongLimit , at limit : 6664,5
                              ***[Acc] - FD: 19/04/2012 21:35:46 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:35:46 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:46 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:35:46 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:46 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:35:46 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:47 | DEPLACEMENT EnterLongLimit , at limit : 6665
                              ***[Acc] - FD: 19/04/2012 21:35:47 | Enter OnOrderUpdate :Entry , PendingChange
                              ***[Acc] - FD: 19/04/2012 21:35:47 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:47 | Enter OnOrderUpdate :Entry , Accepted
                              ***[Acc] - FD: 19/04/2012 21:35:47 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:35:47 | Enter OnOrderUpdate :Entry , Working
                              ***[Acc] - FD: 19/04/2012 21:35:47 | EntryOrder != null
                              ***[Acc] - FD: 19/04/2012 21:37:00 | DEPLACEMENT EnterLongLimit , at limit : 6662,5
                              ***[Acc] - FD: 19/04/2012 21:37:00 | Enter OnOrderUpdate :Entry , Filled
                              ***[Acc] - FD: 19/04/2012 21:37:00 | Enter OnExecutionEntry , Entry
                              ***[Acc] - FD: 19/04/2012 21:37:00 | CalculateTargetValue(): Check Position on Long :  6666,5
                              ***[Acc] - FD: 19/04/2012 21:37:00 | EXCEPTION AFTER LINE : 14
                              ***[Acc] - FD: 19/04/2012 21:37:00 | Object reference not set to an instance of an object.
                              **NT** Error on calling 'OnBarUpdate' method for strategy 'Acc/b5d9c69342da405e9698fc78f110c0b8': Object reference not set to an instance of an object.
                              **NT** Disabling NinjaScript strategy 'Acc/b5d9c69342da405e9698fc78f110c0b8'

                              At 21:37:00 it moves the enterLongLimit

                              21:37:00 | DEPLACEMENT EnterLongLimit , at limit : 6662,5

                              Then it entered in onOrderUpdate where I have the code :
                              Code:
                                      protected override void OnOrderUpdate(IOrder order)
                                      {
                                          PrintDebug("Enter OnOrderUpdate :" + order.Name + " , " + order.OrderState.ToString() );
                                          if (order.Name == "Entry") 
                                          {
                                              if (entryOrder != null) PrintDebug("EntryOrder != null");
                                          }
                              As you can see , the next line on the output is :
                              21:37:00 | Enter OnOrderUpdate :Entry , Filled

                              but after that line it doesn't print "EntryOrder != null" as expected by the second IF.

                              The output line after is :

                              21:37:00 | Enter OnExecutionEntry , Entry

                              As it was filled , it enter in onExecution ,
                              the line :
                              Code:
                                          PrintDebug("Enter OnExecution" + execution.Name + " , " + execution.Order.Name);
                              shows that the order.Name is "Entry"
                              but has entryOrder is null , it doesn't enter in the next if...

                              So after in the output is only the consequence...

                              As the Position object is positionned to Position.Long ,
                              on next onBarUpdate it goes thru different code to manage the Target Position :
                              21:37:00 | CalculateTargetValue(): Check Position on Long : 6666,5

                              But as we didn't created a TargetOrder on the OnExecution , it falls normaly in exception... close the strategy , and let an open position on the market...

                              Comment


                                #30
                                Thanks for that output.

                                Ok so right now I'm thinking it has to do with the order being changed so often see here:

                                You issue and pending change and then 1 second later issue another pending change.

                                19/04/2012 21:35:46 | Enter OnOrderUpdate :Entry , PendingChange

                                19/04/2012 21:35:47 | Enter OnOrderUpdate :Entry , PendingChange

                                This happens several times, what could be going on here is that you submit a pending change at that same time the order is being filled or some sequence of events related around this.

                                However what I dont understand is from your code snippet how you doing the PendingChange? From the code I see this order should never change once submitted since you dont call EnterLongLimit again unless entryOrder is null in which case it should never be null unless the order was cancelled.

                                Is your code really cancelling any resubmitting orders every second? If so I do not see the output showing that the order was cancelled.

                                What am I missing? Thanks.


                                Code:
                                double limitPriceLong = Instrument.MasterInstrument.Round2TickSize(Close[0] - ((accelerationSize - ACC.Acceleration[0]) * TickSize)) ;
                                if (CheckDayOHLOk(limitPriceLong)) 
                                {
                                    // Cas ou on est dans les limites tradables
                                    if (entryOrder == null) 
                                    {
                                        entryOrder = EnterLongLimit(0, true, contractLots, limitPriceLong, "Entry");                PrintDebug("INITIALISATION EnterLongLimit , at limit : " + limitPriceLong);
                                    }
                                    else if (entryOrder.LimitPrice != limitPriceLong){
                                        PrintDebug("DEPLACEMENT EnterLongLimit , at limit : " + limitPriceLong);
                                    }
                                }
                                else
                                {        
                                    // Cas ou on est hors des limites Day OHL => on cancel
                                    if (entryOrder != null) 
                                    {
                                        CancelOrder(entryOrder);                    
                                        PrintDebug("CANCEL ORDER Cause Limit Day OHL : " + limitPriceLong);
                                    }
                                }

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by PhillT, 04-19-2024, 02:16 PM
                                4 responses
                                31 views
                                0 likes
                                Last Post PhillT
                                by PhillT
                                 
                                Started by ageeholdings, 05-01-2024, 05:22 AM
                                5 responses
                                36 views
                                0 likes
                                Last Post ageeholdings  
                                Started by reynoldsn, Today, 02:34 PM
                                0 responses
                                10 views
                                0 likes
                                Last Post reynoldsn  
                                Started by nightstalker, Today, 02:05 PM
                                0 responses
                                17 views
                                0 likes
                                Last Post nightstalker  
                                Started by llanqui, Yesterday, 09:59 AM
                                8 responses
                                30 views
                                0 likes
                                Last Post llanqui
                                by llanqui
                                 
                                Working...
                                X