NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-01-2011, 08:06 AM   #1
AAATradingSolutions
Junior Member
 
Join Date: Jan 2010
Location: Belgium
Posts: 25
Thanks: 0
Thanked 4 times in 2 posts
Default 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
AAATradingSolutions is offline  
Reply With Quote
Old 04-01-2011, 08:25 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Trumumflu,

Thank you for the report. Can you let us know which version of NinjaTrader you are running?
NinjaTrader_RyanM is offline  
Reply With Quote
Old 04-01-2011, 08:56 AM   #3
AAATradingSolutions
Junior Member
 
Join Date: Jan 2010
Location: Belgium
Posts: 25
Thanks: 0
Thanked 4 times in 2 posts
Default

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...
AAATradingSolutions is offline  
Reply With Quote
Old 04-01-2011, 09:10 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 04-01-2011, 09:41 AM   #5
AAATradingSolutions
Junior Member
 
Join Date: Jan 2010
Location: Belgium
Posts: 25
Thanks: 0
Thanked 4 times in 2 posts
Default

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...)
AAATradingSolutions is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing tools for Median Lines - Action Reaction Lines mahlonhersh Charting 3 09-24-2010 01:09 PM
Action Reaction lines Hannes.S Charting 9 05-29-2009 02:30 PM
ExitLongLimit is ignored. istavnit Automated Trading 5 04-01-2009 02:50 PM
ExitLongLimit issue. strategy1 General Programming 35 01-22-2009 11:18 AM
ExitLongLimit from different strategy MindSabre Strategy Development 3 07-11-2007 08:16 AM


All times are GMT -6. The time now is 03:17 AM.