I am trying to code a stopplacement depending on the position of the close to the EMA20, ema50 and ema 100.
The idea is simple. If the close is above the ema 20 and the distance to the ema20 is greater then 6 the stop is placed at the ema20.
If the distance is smaller then 6 or the close is smaller then the ema20 and the the distance to the ema50 is greater then 6 the stop is placed at the ema50. and so on…
I wrote the following code, but clearly i have made a mistake, cause it doen not influence the outcome.
In line 1 you use EMA20 in the expression, while in line 2 you use EMA20[2], which is the value retained two bars prior to the current one.
I think this is the culprit.
Try removing [2].