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 :
// 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;
}
******* ()-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

Comment