I am trying to create a Breakeven order when the Initial Risk is earned. However, the Initial StopLoss varies from entry to entry, because the entry is a Bearish Engulfing patern:
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
if (Close[1] > Open[1] && Close[0] < Open[0] && Open[0] >= Close[1] && Close[0] <= Open [1])
{
EnterShort(DefaultQuantity, "BearishEngulfing");
double difference = High[0] - Close[0];
SetStopLoss(CalculationMode.Price, High[0]);
SetProfitTarget(CalculationMode.Ticks, TickSize*(8*difference));
}
if (Low[0] < Position.AveragePrice + (difference*4*TickSize))
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice);
}
}
I tried to find a way to store the value of the variable "difference" somehow, but did not find a way to do so. As seen in the bold part the if statement requires the difference value, but the value is not reachable from the if statement above.
Do you have an idea how to make it reachable or to store the value of difference so the second if statement can be executed?
Thanks in advance!
Comment