Hello everybody,
Hope someone can help me.
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.
If close[0] > EMA20 AND (close[0] - EMA20) > 6 then
mystoplong = ema20[2]
ELSIF close[0] > ema20 and (close[0] - ema20) =< 6 then
mystoplong = EMA50[2]
ELSIF close[0] > ema50 AND close[0] < EMA20 and (close[0] - ema50) > 6 then
mystoplong =EMA50[2]
ELSIF close[0] > ema50 AND close[0] < EMA20 and (close[0] - ema50) =< 6 then
mystoplong = EMA100[2]
endif
Hope someone can tell me what i did wrong 🙂
Kind regards,
Jaldidee
Hi Jalidee,
Put this on top of the code you just showed (thus after the EMA20 is known) :
Graph (close[0] - EMA20)
and you will see what’s the culprit …
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].