Adding a MA Slope to Crossover

Hello,

I am trying to create a basic ma cross-over system with a third ma that acts as a filter, the ma cross should only fire a trade if the 3rd MA is sloping incorrect angle.

So two questions:

Is this [Ref(Moving3 > moving3,-5);] an effective way to ensure the 3rdma is sloping up or down?

With the code below, will it only enter a trade only occur if the cross happens whilst the ma3 is sloping the correct way? How would I modify to say that if all these conditions are met, buy: ma1 > ma2 and ma3 is sloping upward?

SetOption("Maxopenpositions", 20);
SetPositionSize(5, spsPercentOfEquity);

Moving1 = Wilders(C, 6);
Moving2 = HMA(C, 60);
Moving3 = HMA(C,70);

ApplyStop(0, stopModePercent, 10, 2, 0, 0,0,0,0);

Buy = Cross(Moving1, Moving2) AND Ref(Moving3 > moving3,-5);
Sell = Cross(Moving2, Moving1) AND Ref(Moving3 < moving3,-5);
Short = Sell; Cover = Buy;

Big thanks

This will never be true as you are comparing two equal values on the same bar.

If you're looking to detect whether Moving3 is higher than it was 5 bars ago, you can use:

MA3Rising = Moving3 > Ref(Moving3, -5);

or a simpler form...

MA3Rising = ROC(Moving3, 5) > 0;
1 Like

Okay I am coming stuck again, I am trying to set the either buy/sell condition as constant, so whever both conditions are true, a buy signal is initiated. Reading up I think it is about state condition ? I tried adding the () but says somehign about not a function.

Anyone able to help out with mutliple consistent buy conditions ?

MA3Rising = ROC(Ma3, 5) > 0;
MA3Decline = ROC(ma3, 5) < 0;
EntryCross = (m > n);
ExitCross = (m < n);

Buy = MA3Rising AND EntryCross;
Sell = ExitCross;
Short = MA3Decline AND ExitCross;
Cover = EntryCross;

Okay, the code is working, well it appears to be anyway :slight_smile: However, I have located another issue. How do you only initaive a cover, when there is an existing short? Right now the code fires a cover, right before a buy if teh mas's line up?

typeMA3Rising = ROC(Ma3, 5) > 0;
MA3Decline = ROC(ma3, 5) < 0;
EntryCross = (m > n);
ExitCross = (m < n);
 
Buy  = ExRem(MA3Rising, EntryCross);
Sell = ExitCross;
Short = ExRem(MA3Decline, ExitCross);
Cover = EntryCross;

Buy   = ExRem(Buy, Sell);
Sell  = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short); or paste code here

Not sure why you went with

Buy  = ExRem(MA3Rising, EntryCross);

With this statement, Buy will = 1 (True) when MA3Rising is true the first time, and then will remain 0 until EntryCross is True. So you could get entries simply by MA3Rising.

Exrem() isn't required for buy/sell in backtestregular() as it already handles the redundant signals so you can eliminate that.

And not sure what your last post is asking. Your buy signal and cover signal are identical so it's going to cover and then buy.

Your second post is confusing as your buy and sell should never be true at same time as one is m > n and one is m < n. No idea what "m" and "n" are but perhaps start there.