I'm trying to create my own stop loss strategy where an initial take profit order and stop loss order are set upon entering the trade and triggered when either "ProfitTarget" or "StopLoss" are reached.
However, I want my stop loss to move to a pre-determined level ("StopLossAdj") once the price reaches a certain threshold ("RatchetAmt") above the EntryPrice.
The code below works fine for most trades but not for others and I don't understand why. I join two screenshots taken from the exact same 2000 tick chart. All trades have the same signals applies to them.
On the first screenshot, we see the code working as expecte: the stoploss on the left trade is moved to 1 below entry price after ratchetAmt 3 is reached. On the right side, the ratchetAmt is never reached so the price stops out at StopLoss 6 points below EntryPrice.
Yet, on the following trade (second screenshot), the price does reach ratchetAmt 3 but the stop is apparently not moved to the level 1 point below EntryPrice. It should have triggered there.
I'm relatively new to learning EasyLanguage. I've spent two days trying to work it out. Thank you for your help.
The following user says Thank You to samasthiti for this post:
you are using "SetStopLoss" twice in your code. The first one is valid on every bar and the second one would only be used on bars where "High >= (EntryPrice + RatchetAmt )", but not on later bars where High < (EntryPrice + RatchetAmt ), even if the condition was met on a prior bar. On those bars only the first stop would be used according to your code, which appears to be what you are seeing on the chart, too.
You could consider using the reserved word SetStopLoss once only at the end of the code and using a variable that holds the stop amount.
If you are flat you would reset the variable (let's call it myStopAmount for this example) to myStopAmount = StopLoss* BigPointValue and in case High >= (EntryPrice + RatchetAmt ) while you are in a position you would set it to myStopAmount = StopLossAdj * BigPointValue.
At the end of the code you would issue the stop using SetStopLoss( myStopAmount ).
Regards,
ABCTG
The following 3 users say Thank You to ABCTG for this post: