Simple stratey that enters two (e.g. P1, P2) same direction orders with individual profit target and trail stop loss. Both the positions are entered correctly, I can see individual Profit target and Stop loss orders for both the P1 and P2 positions on the chart trader.
Issue: When either profit target or stop order for P1 is hit, both profit target and stop order for P2 entry disappear/cancelled.
I have spent quite a few days on looking for solution to no avail. I would really appreciate if your help in figuring out why Profit/Stop orders for P2 are cancelled when P1 profit/stop orders are hit.
OnStateChange
{
Calculate = Calculate.OnBarClose;
OrderFillResolution = OrderFillResolution.Standard;
StartBehavior = StartBehavior.WaitUntilFlat;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelCloseIgnoreRejects ;
//I have tried all the following combinations but same issue
//1.
EntriesPerDirection = 2;
EntryHandling = EntryHandling.AllEntries;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
//2. Tried this also
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
}
OnBarUpdate()
{
.....
//Pseudocode
double p1ProfitTicks = (currentAtr * 40);
double p1TailStopTicks =(currentAtr * 40);
double p2ProfitTicks = (currentAtr * 200);
double p2TailStopTicks =(currentAtr * 100);
SetTrailStop(@"P1",CalculationMode.Ticks, p1TailStopTicks, false);
SetTrailStop(@"P2", CalculationMode.Ticks, p2TailStopTicks, false);
SetProfitTarget(@"P1", CalculationMode.Ticks, p1ProfitTicks);
SetProfitTarget(@"P2", CalculationMode.Ticks, p2ProfitTicks);
if (long condition && Position.MarketPosition == MarketPosition.Flat)
{
EnterLong(1, @"P1");
EnterLong(1, @"P2");
}
if (short condition && Position.MarketPosition == MarketPosition.Flat)
{
EnterShort(1, @"P1");
EnterShort(1, @"P2");
}
.....
}
TIA for your attention and help!
Comment