I am facing some difficulties on how to set a rolling stop loss using Swing Indicator.
My idea is to set the Stop Loss at the second last swing low (for Long entry) only when the swing low is higher than the previous swing low.
On the attachment chart you could see where the SL levels the should be (A,B,C and D) and the position should Stop Out at E point. To explain this further the SL need to change like the following :
At time 1 the SL is at A
At time 2 the SL is at B
At time 3 the SL is at C
At time 4 the SL is at D
Stop Out at E
In addition, I have a part of my code below where I am setting the stop loss(SL). My position is closing at using the the SL level D instead of C. Could you please give me an idea how to code this rolling SL idea.
Code:
else if (Position.MarketPosition == MarketPosition.Long)
{
if (Close[0]<stopLongPrice
&& Close[0]<SMA(MAFast)[0]
&& Close[1]<SMA(MAFast)[1])
{
Print("Exit Long trade at " + Close[0] + " at " + Time[0] );
}
else if (Swing(SWG).SwingLow[2]>stopLongPrice)
{
Print("Actual Low Swing=" +Swing(SWG).SwingLow[0] + " Previous SL="+stopLongPrice);
stopLongPrice = Swing(SWG).SwingLow[2];
Print("New Stop loss price : " + stopLongPrice + " at " + Time[0] );
}
Thanks in advance

Comment