I've been working on my algo for some weeks now, and I'm struggling to get trailing stop loss working.
I already tried a lot of different things, but always encounter issues or not the expected behavior.
The idea is to have a fixed SL of 20 points from my entry until price is reaching 20 points in profits. From this moment, I take one contract off and I would like my stop loss to trail price only if it's doing higher highs (15 points trail stop) / or higher price since my trade has been opened.
Here what my current code is looking like regarding this specific part. It currently sets my SL at Breakeven when 20 points in profit is reached and then take the 2nd contract off at 40 points.
if (Position.MarketPosition == MarketPosition.Long)
{
//Keep Stop order where it is until TP1 is reached
if (Position.Quantity == Contracts && !halfPositionClosed)
{
stopLossOrder = ExitLongStopMarket(Contracts, Position.AveragePrice - SL);
double limitPrice1 = Position.AveragePrice + TP1;
ExitLongLimit(Convert.ToInt32(Contracts)/2, limitPrice1, "ExitHalfLong", "Long");
}
// Another part of the code set halfPositionClosed to true
if (halfPositionClosed)
{
[COLOR=#e74c3c]double breakevenPrice = Position.AveragePrice + (1); // Add one tick to cover commissions[/COLOR]
stopLossOrder = ExitLongStopMarket(Position.Quantity, breakevenPrice);
Print("current SL long: " + stopLossOrder);
// TP2
double limitPrice2 = Position.AveragePrice + TP2;
ExitLongLimit(Convert.ToInt32(Contracts)/2, limitPrice2, "ExitFullLong", "Long");
}
}
My Stop Loss is following price, whatever it does (even if it's going down or if not doing higher highs).
Could someone help me on this topic?
Thanks in advance for the help.

Comment