Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

stock - Three moving average cross over in trading view using pine script version @4

//@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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...