I am trying to code Moving Average strategy without conventional crossover with 2 filters:
Filter 1 : prices to stay above 10 day MA for straight 2 days.
In an uptrend, prices must move up through the moving average and post 2 lows above the average.
In a downtrend, prices must move down through the moving average and post 2 highs below the average.
Filter 2 : break of the highest bar of the two bars that have moved through the moving average.
So, in an uptrend we need prices to move up through the moving average and then post two lows above the average (filter 1). We then need the highest high of those two days to be breached by 10 cents (filter 2) before entering the trade.
Here is the code snippet:
MA10 = MA(C, 10);
// Filter
priceBeAboveMA10 = C > Ref(MA10,-2); // Price above 10 MA
priceIsUp = (C > Ref(Highest(C),-2));
LongEntry = priceBeAboveMA10 AND priceIsUp
I am not sure if I am heading to the right direction