Hi,
I create an indicator and want to check if a bar is crosses under the MA10, MA20 and MA30 at the same day. If it is, then the output is minus. But it seems it doesn’t work always. See my attached screenshot.
My code looks as follow:
...
// MA
MA1 = ExponentialAverage[10](close)
MA2 = ExponentialAverage[20](close)
MA3 = ExponentialAverage[30](close)
...
...
cExit = (close crosses under MA1) and (close crosses under MA2) and (close crosses under MA3)
...
...
if cExit then
output = -1
else
output = 0
...
RETURN output
This works fine:
MA1 = ExponentialAverage[10](close)
MA2 = ExponentialAverage[20](close)
MA3 = ExponentialAverage[30](close)
cExit = (close crosses under MA1) and (close crosses under MA2) and (close crosses under MA3)
if cExit then
output = -1
else
output = 0
endif
RETURN output
Thanks first!
I simply copy your code and have a try by me. But it looks it doesn’t work 100%. See attached screenshots. Really strange. :-/
Check that periods and average type on your chart are the same as in your code and that you are using a numer of unit large enough (1K should do).
Because sometimes Close from the previous candlestick was already below one of the MA, so the Close is not crossing the MA on the current period (it has crosses the period before!).