Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLongLimit strange reaction

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

    ExitLongLimit strange reaction

    Hi ,
    I'm using NT since a long time now and I'm very happy with it.

    I'm an Expert .NET Analyst Developer so I use NT exclusively to develop automate systeme...

    I wrote a lot of strategies without (too much ) technicals problems...

    But here , I have a strange effect and I cannot explain it

    I'm working on a strategy exclusively based on events.

    In two words , I have 4 types of order :

    1 ) an entry order (following some alogorithms and go long or short)
    2) an adding order that is use to add on position if it loose 4 ticks
    3) two targets order
    4) a stop loss order...

    The usual running is :
    1) Entry
    => Target1 is created
    => Adding is created...

    When Target 1 is hit :
    => Target 2 is created
    => Adding is cancelled
    => Stop loss is created...

    I come to the problem...
    The entry begin with 2 contracts (I forgot to say I'm trading only Future)
    So Target 1 is created with 1 contract

    The problem comes when Target 1 is hit and I create Target2 (on OnExecution event)
    I have an error message saying : Reason='There is no remaining quantity to exit'
    But I'm sure to have 1 contract left...
    And If I print "Position.Quantity" , it's equal to 1.

    The funny thing is that just after , I create the Stop Loss order , and there is no problem...

    This is the part of code in OnExecution event :

    Code:
                // Gestion du Target 1
                //====================
                // Si T1 est atteind , on arrete le Adding , et on met un Stop sur COG Ligne 1 de la quantité dans T2
                if (target1Order != null && target1Order.Token == execution.Order.Token) 
                {
                    PrintDebug("MendoITCOGwithAdding:... Passage dans OnExecution : gestion Target1 Order");
                    if (execution.Order.OrderState == OrderState.Filled)
                    {
    
                        // On cree un Target 2 et un StopLoss
                        switch (Position.MarketPosition)
                        {
                            case MarketPosition.Long:
                                // On place les target sur le COG
                                PrintDebug("MendoITCOGwithAdding:....... target2Order = ExitLongLimit(0, true, Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Top2[0],'COG_T2','');");
                                PrintDebug(" Quantite pour le target 2 : " +  Position.Quantity );
                                target2Order = ExitLongLimit(0, true, Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Top2[0],"COG_T2","");
    
                                PrintDebug("MendoITCOGwithAdding:....... stopAfterT1Order = ExitLongStop(0,true,Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Bottom1[0],'COG_STOP','')");
                                stopAfterT1Order = ExitLongStop(0,true,Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Bottom1[0],"COG_STOP","");
                                break;
                            
                            case MarketPosition.Short:
                                // On place les target sur le COG
                                PrintDebug("MendoITCOGwithAdding:....... target2Order = ExitShortLimit(0, true, Position.Quantityu, MendoITCenterOfGravity(cOGNbreBars).Bottom2[0],'COG_T2','');");
                                PrintDebug(" Quantite pour le target 2 : " +  Position.Quantity );
                                target2Order = ExitShortLimit(0, true, Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Bottom2[0],"COG_T2","");
                
                                // On place les target sur le COG
                                PrintDebug("MendoITCOGwithAdding:....... stopAfterT1Order = ExitShortStop(0,true,Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Bottom1[0],'COG_STOP','')");
                                stopAfterT1Order = ExitShortStop(0,true,Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Top1[0],"COG_STOP","");
                                break;
                        }
    
                        // On supprime les Addings
                        if (addingOrder != null) 
                        {
                            PrintDebug("MendoITCOGwithAdding:....... CancelOrder(addingOrder);");
                            CancelOrder(addingOrder);
                        }
    
                        // On clear le pointeur
                        PrintDebug("MendoITCOGwithAdding:....... target1 Order = null;");
                        target1Order = null;
                        
                    }
                    return;
                }
    And this is my output at that time :

    ******* ()-ES 06-11: 30/03/2011 16:35:00 | MendoITCOGwithAdding:... Passage dans OnExecution : gestion Target1 Order
    ******* ()-ES 06-11: 30/03/2011 16:35:00 | MendoITCOGwithAdding:....... CancelOrder(addingOrder);
    Cancelled custom managed order at 30/03/2011 16:32:12: Order='b7d9dc88fcb5436193d4046bf5b8e60a/Sim101' Name='COG_Adding' State=Working Instrument='ES 06-11' Action=Buy Limit price=1319 Stop price=0 Quantity=2 Strategy='MendoITCOGwithAdding' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='b7d9dc88fcb5436193d4046bf5b8e60a' Gtd='1/12/2099 0:00:00'
    ******* ()-ES 06-11: 30/03/2011 16:35:00 | MendoITCOGwithAdding:....... target2Order = ExitLongLimit(0, true, Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Top2[0],'COG_T2','');
    30/03/2011 16:32:12 Entered internal PlaceOrder() method at 30/03/2011 16:32:12: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=1322,50 StopPrice=0 SignalName='COG_T2' FromEntrySignal=''
    30/03/2011 16:32:12 Ignored PlaceOrder() method at 30/03/2011 16:32:12: Action=Sell OrderType=Limit Quantity=0 LimitPrice=1322,50 StopPrice=0 SignalName='COG_T2' FromEntrySignal='' Reason='There is no remaining quantity to exit'
    ******* ()-ES 06-11: 30/03/2011 16:35:00 | MendoITCOGwithAdding:....... stopAfterT1Order = ExitLongStop(0,true,Position.Quantity, MendoITCenterOfGravity(cOGNbreBars).Bottom1[0],'COG_STOP','')
    30/03/2011 16:32:12 Entered internal PlaceOrder() method at 30/03/2011 16:32:12: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1320,50 SignalName='COG_STOP' FromEntrySignal=''
    ******* ()-ES 06-11: 30/03/2011 16:35:00 | MendoITCOGwithAdding:....... target1 Order = null;


    I must add that if I have some adding during the first step of the strategy.
    Everything goes OK... Target2 is created with the lefting Position.Quantity.

    Hope I'm clear in my explanation , it's not easy

    Best Regards

    #2
    Hi Trumumflu,

    Thank you for the report. Can you let us know which version of NinjaTrader you are running?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Sorry I forgot...

      I'm on Ninjatrader 7 (7.0.1000.2) with Zen fire.
      I have a regular License

      Those trades are made in real time but on simulation account...

      Comment


        #4
        There is one important coding change to make for version 7. When you check for equality you need to compare order objects directly, rather than use .token.

        Change This:
        if (target1Order != null && target1Order.Token == execution.Order.Token)

        To This:
        if (target1Order != null && target1Order == execution.Order)

        Let us know if you are still seeing unexpected results after making this change.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I will change that and come back to you monday...

          But I'm sure it will change nothing , the problem is in the code inside that IF...
          So it enters without problems...

          (But you're right , it's better to change...)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          646 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          367 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X