I'm trying to code a startegy that scales into a position but only if the prior entry order is at break-even. This proves harder with my skill level than I anticipated...
The logic involves storing Entry prices in variables and bools to mark if a position is true or not. I'm adding the breakeven protective stops with ExitShortStopMarket method to be able to assign an exit signal name to each. I have several problems: I can't assign exit signal name to SetStopLoss method (initial entry) to check if it was triggered to gauge if a position is open. Also, the BarsinceExitExecution does not seem to work but I can't figure out why. Is there a way to check if a position from an entry signal is open in any other way? Third issue I have is that the ExitShortStopMarket method doesn't move stops to breakeven as per the code below.
// Breakeven Logic
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(@"SE1", CalculationMode.Ticks, Stop_Tick, false);
SetStopLoss(@"SE2", CalculationMode.Ticks, Stop_Tick, false);
Pos1= false;
Pos2= false;
}
else if ((Position.MarketPosition == MarketPosition.Short)
&& (Pos1= true)
&& (Close[0] < Pos1Price - BE_Trigger*TickSize))
{
ExitShortStopMarket(0,true, Convert.ToInt32(DefaultQuantity), Pos1Price-2*TickSize,@"SX1", @"SE1");
}
else if ((Position.MarketPosition == MarketPosition.Short)
&& (Pos2= true)
&& (Close[0] < Pos2Price - BE_Trigger*TickSize))
{
ExitShortStopMarket(0,true, Convert.ToInt32(DefaultQuantity), Pos2Price-2*TickSize,@"SX2", @"SE2");
}
else if ((Position.MarketPosition == MarketPosition.Short)
&& (Pos1= false))
{
SetStopLoss(@"SE1", CalculationMode.Ticks, Stop_Tick, false);
}
else if ((Position.MarketPosition == MarketPosition.Short)
&& (Pos2= false))
{
SetStopLoss(@"SE2", CalculationMode.Ticks, Stop_Tick, false);
}
// Pos Variable
if (BarsSinceExitExecution(0,@"SX1",0)==0)
{
Pos1 = false;
Print("Pos1=false"); //// no print
}
if (BarsSinceExitExecution(0, @"SX2", 0) == 0)
{
Pos2 = false;
Print("Pos2=false"); //// no print
}
Comment