-1
//@version=4
study(title="MA Cross", overlay=true, resolution="")
fastMA = sma(close, 55)
medMA= sma(close, 89)
slowMA =  sma(close,233)
plot(fastMA, color = color.red)
plot(medMA, color = color.green)
plot(slowMA,color= color.black)
plot(cross(fastMA,medMA,slowMA) ? short : na, style = plot.style_cross, linewidth = 4)

I want to plot a crossover of three different moving averages but i'm not sure what function to use in order to cross all three of them according to the value. As function only lets me crossover two moving averages MA.. Ex:50 day moving average should be greater than 80 (i.e. displayed on top) and 80 be greater than 200(i.e. above 200 but lower than 80 on display) and have them corssover at once point

Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42

1 Answers1

0

The cross of three different moving averages in one place is a unique event. Below is a script that checks the cross of the first two moving averages and the relative position of the other two moving averages. I hope the idea is clear, comparing the values of the moving averages on two bars, you can independently check any condition. Good luck.

//@version=4
study(title="MA Cross", overlay=true, resolution="")
fastMA = sma(close, 55)
medMA= sma(close, 89)
slowMA =  sma(close,233)
plot(fastMA, color = color.red)
plot(medMA, color = color.green)
plot(slowMA,color= color.black)

Cond_Cross_Dn = false
if (fastMA[1] >= medMA[1] and fastMA[0] < medMA[0]) and (medMA[0] < slowMA[0])
    Cond_Cross_Dn := true

plot(Cond_Cross_Dn ? fastMA : na, style = plot.style_cross, linewidth = 4)
AnyDozer
  • 2,236
  • 2
  • 5
  • 22
  • If the answer is complete for you, use the recommendations of the article https://stackoverflow.com/help/someone-answers – AnyDozer Jan 17 '21 at 02:51