Pine Script v5、EMA 云和警报
尝试在这里学习 Pine 脚本来优化我的交易策略。我有大约 1.5 年的交易经验。我使用的趋势系统是强大的 Ripster Clouds。它基于多个 EMA 的移动、形成云(如一目均衡表云)并发现趋势反转。我将链接粘贴下面的代码。
我正在努力解决的是添加警报和箭头,指出趋势反转的开始位置和结束位置。
牛市 = 当 EMA 云 2 穿过 EMA 云 3 时
熊市 = 当 EMA 云 3 穿过 EMA 云 3 时。
我还想要一个它所基于的时间范围的变量。我的建议是 3 分钟、10 分钟、1 小时、1 天和 1 周。
如果有人可以指出我寻求帮助的方向,或者在评论中帮助我,我将不胜感激。
该代码当然是免费的。
云层变化的屏幕截图。云 2 = 5-13 EMA 交叉,云 3 = 34-50 EMA 交叉
此处为 EMA 云的描述视频。 视频
干杯,
//@version=5
indicator("TwntySQ EMA Clouds - modified version of Ripster47 EMA clouds", shorttitle="TQ", overlay=true)
matype = input.string(title='MA Type', defval='EMA', options=['EMA', 'SMA'])
ma_len1 = input(title='Short EMA1 Length', defval=8)
ma_len2 = input(title='Long EMA1 Length', defval=9)
ma_len3 = input(title='Short EMA2 Length', defval=5)
ma_len4 = input(title='Long EMA2 Length', defval=13)
ma_len5 = input(title='Short EMA3 Length', defval=34)
ma_len6 = input(title='Long EMA3 Length', defval=50)
ma_len7 = input(title='Short EMA4 Length', defval=72)
ma_len8 = input(title='Long EMA4 Length', defval=89)
ma_len9 = input(title='Short EMA5 Length', defval=180)
ma_len10 = input(title='Long EMA5 Length', defval=200)
src = input(title='Source', defval=hl2)
ma_offset = input(title='Offset', defval=0)
//res = input(title="Resolution", type=resolution, defval="240")
f_ma(malen) =>
float result = 0
if matype == 'EMA'
result := ta.ema(src, malen)
result
if matype == 'SMA'
result := ta.sma(src, malen)
result
result
htf_ma1 = f_ma(ma_len1)
htf_ma2 = f_ma(ma_len2)
htf_ma3 = f_ma(ma_len3)
htf_ma4 = f_ma(ma_len4)
htf_ma5 = f_ma(ma_len5)
htf_ma6 = f_ma(ma_len6)
htf_ma7 = f_ma(ma_len7)
htf_ma8 = f_ma(ma_len8)
htf_ma9 = f_ma(ma_len9)
htf_ma10 = f_ma(ma_len10)
//plot(out1, color=green, offset=ma_offset)
//plot(out2, color=red, offset=ma_offset)
//lengthshort = input(8, minval = 1, title = "Short EMA Length")
//lengthlong = input(200, minval = 2, title = "Long EMA Length")
//emacloudleading = input(50, minval = 0, title = "Leading Period For EMA Cloud")
//src = input(hl2, title = "Source")
showlong = input(false, title='Show Long Alerts')
showshort = input(false, title='Show Short Alerts')
showLine = input(false, title='Display EMA Line')
ema1 = input(true, title='Show EMA Cloud-1')
ema2 = input(true, title='Show EMA Cloud-2')
ema3 = input(true, title='Show EMA Cloud-3')
ema4 = input(true, title='Show EMA Cloud-4')
ema5 = input(true, title='Show EMA Cloud-5')
emacloudleading = input.int(0, minval=0, title='Leading Period For EMA Cloud')
mashort1 = htf_ma1
malong1 = htf_ma2
mashort2 = htf_ma3
malong2 = htf_ma4
mashort3 = htf_ma5
malong3 = htf_ma6
mashort4 = htf_ma7
malong4 = htf_ma8
mashort5 = htf_ma9
malong5 = htf_ma10
cloudcolour1 = mashort1 >= malong1 ? #036103 : #880e4f
cloudcolour2 = mashort2 >= malong2 ? #4caf50 : #f44336
cloudcolour3 = mashort3 >= malong3 ? #2196f3 : #ffb74d
cloudcolour4 = mashort4 >= malong4 ? #009688 : #f06292
cloudcolour5 = mashort5 >= malong5 ? #05bed5 : #e65100
//03abc1
mashortcolor1 = mashort1 >= mashort1[1] ? color.olive : color.maroon
mashortcolor2 = mashort2 >= mashort2[1] ? color.olive : color.maroon
mashortcolor3 = mashort3 >= mashort3[1] ? color.olive : color.maroon
mashortcolor4 = mashort4 >= mashort4[1] ? color.olive : color.maroon
mashortcolor5 = mashort5 >= mashort5[1] ? color.olive : color.maroon
mashortline1 = plot(ema1 ? mashort1 : na, color=showLine ? mashortcolor1 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA1')
mashortline2 = plot(ema2 ? mashort2 : na, color=showLine ? mashortcolor2 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA2')
mashortline3 = plot(ema3 ? mashort3 : na, color=showLine ? mashortcolor3 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA3')
mashortline4 = plot(ema4 ? mashort4 : na, color=showLine ? mashortcolor4 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA4')
mashortline5 = plot(ema5 ? mashort5 : na, color=showLine ? mashortcolor5 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA5')
malongcolor1 = malong1 >= malong1[1] ? color.green : color.red
malongcolor2 = malong2 >= malong2[1] ? color.green : color.red
malongcolor3 = malong3 >= malong3[1] ? color.green : color.red
malongcolor4 = malong4 >= malong4[1] ? color.green : color.red
malongcolor5 = malong5 >= malong5[1] ? color.green : color.red
malongline1 = plot(ema1 ? malong1 : na, color=showLine ? malongcolor1 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA1')
malongline2 = plot(ema2 ? malong2 : na, color=showLine ? malongcolor2 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA2')
malongline3 = plot(ema3 ? malong3 : na, color=showLine ? malongcolor3 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA3')
malongline4 = plot(ema4 ? malong4 : na, color=showLine ? malongcolor4 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA4')
malongline5 = plot(ema5 ? malong5 : na, color=showLine ? malongcolor5 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA5')
fill(mashortline1, malongline1, color=cloudcolour1, title='MA Cloud1', transp=45)
fill(mashortline2, malongline2, color=cloudcolour2, title='MA Cloud2', transp=65)
fill(mashortline3, malongline3, color=cloudcolour3, title='MA Cloud3', transp=70)
fill(mashortline4, malongline4, color=cloudcolour4, title='MA Cloud4', transp=65)
fill(mashortline5, malongline5, color=cloudcolour5, title='MA Cloud5', transp=65)
Trying to learn Pine script here to optimize my trading strategy. I have around 1.5 year of experience trading. The trendsystem Im using is the all mighty Ripster Clouds. It is based on several EMAs moving, and making a cloud(like a ichimoku cloud) and spotting trend reversing. I'll link paste the code below.
What Im struggling with is adding alerts and arrows pointing where the trendreversing start, and where it ends.
Bull = When EMA cloud 2 crosses OVER EMA cloud 3
Bear = When EMA cloud 3 crosses UNDER EMA cloud 3.
I also want a variable of what timeframe it is based upon. My suggestions are 3min, 10min, 1hour, 1 day and 1 week.
If anyone can either point me in a direction to get help, or help me in the comments, it will be greatly appreciated.
The code will be free of course.
Screenshot where the clouds change. Cloud 2 = 5-13 EMA cross, Cloud 3 = 34-50 EMA cross
Video of descriptive video of EMA clouds here. Video here
Cheers,
//@version=5
indicator("TwntySQ EMA Clouds - modified version of Ripster47 EMA clouds", shorttitle="TQ", overlay=true)
matype = input.string(title='MA Type', defval='EMA', options=['EMA', 'SMA'])
ma_len1 = input(title='Short EMA1 Length', defval=8)
ma_len2 = input(title='Long EMA1 Length', defval=9)
ma_len3 = input(title='Short EMA2 Length', defval=5)
ma_len4 = input(title='Long EMA2 Length', defval=13)
ma_len5 = input(title='Short EMA3 Length', defval=34)
ma_len6 = input(title='Long EMA3 Length', defval=50)
ma_len7 = input(title='Short EMA4 Length', defval=72)
ma_len8 = input(title='Long EMA4 Length', defval=89)
ma_len9 = input(title='Short EMA5 Length', defval=180)
ma_len10 = input(title='Long EMA5 Length', defval=200)
src = input(title='Source', defval=hl2)
ma_offset = input(title='Offset', defval=0)
//res = input(title="Resolution", type=resolution, defval="240")
f_ma(malen) =>
float result = 0
if matype == 'EMA'
result := ta.ema(src, malen)
result
if matype == 'SMA'
result := ta.sma(src, malen)
result
result
htf_ma1 = f_ma(ma_len1)
htf_ma2 = f_ma(ma_len2)
htf_ma3 = f_ma(ma_len3)
htf_ma4 = f_ma(ma_len4)
htf_ma5 = f_ma(ma_len5)
htf_ma6 = f_ma(ma_len6)
htf_ma7 = f_ma(ma_len7)
htf_ma8 = f_ma(ma_len8)
htf_ma9 = f_ma(ma_len9)
htf_ma10 = f_ma(ma_len10)
//plot(out1, color=green, offset=ma_offset)
//plot(out2, color=red, offset=ma_offset)
//lengthshort = input(8, minval = 1, title = "Short EMA Length")
//lengthlong = input(200, minval = 2, title = "Long EMA Length")
//emacloudleading = input(50, minval = 0, title = "Leading Period For EMA Cloud")
//src = input(hl2, title = "Source")
showlong = input(false, title='Show Long Alerts')
showshort = input(false, title='Show Short Alerts')
showLine = input(false, title='Display EMA Line')
ema1 = input(true, title='Show EMA Cloud-1')
ema2 = input(true, title='Show EMA Cloud-2')
ema3 = input(true, title='Show EMA Cloud-3')
ema4 = input(true, title='Show EMA Cloud-4')
ema5 = input(true, title='Show EMA Cloud-5')
emacloudleading = input.int(0, minval=0, title='Leading Period For EMA Cloud')
mashort1 = htf_ma1
malong1 = htf_ma2
mashort2 = htf_ma3
malong2 = htf_ma4
mashort3 = htf_ma5
malong3 = htf_ma6
mashort4 = htf_ma7
malong4 = htf_ma8
mashort5 = htf_ma9
malong5 = htf_ma10
cloudcolour1 = mashort1 >= malong1 ? #036103 : #880e4f
cloudcolour2 = mashort2 >= malong2 ? #4caf50 : #f44336
cloudcolour3 = mashort3 >= malong3 ? #2196f3 : #ffb74d
cloudcolour4 = mashort4 >= malong4 ? #009688 : #f06292
cloudcolour5 = mashort5 >= malong5 ? #05bed5 : #e65100
//03abc1
mashortcolor1 = mashort1 >= mashort1[1] ? color.olive : color.maroon
mashortcolor2 = mashort2 >= mashort2[1] ? color.olive : color.maroon
mashortcolor3 = mashort3 >= mashort3[1] ? color.olive : color.maroon
mashortcolor4 = mashort4 >= mashort4[1] ? color.olive : color.maroon
mashortcolor5 = mashort5 >= mashort5[1] ? color.olive : color.maroon
mashortline1 = plot(ema1 ? mashort1 : na, color=showLine ? mashortcolor1 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA1')
mashortline2 = plot(ema2 ? mashort2 : na, color=showLine ? mashortcolor2 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA2')
mashortline3 = plot(ema3 ? mashort3 : na, color=showLine ? mashortcolor3 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA3')
mashortline4 = plot(ema4 ? mashort4 : na, color=showLine ? mashortcolor4 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA4')
mashortline5 = plot(ema5 ? mashort5 : na, color=showLine ? mashortcolor5 : na, linewidth=1, offset=emacloudleading, title='Short Leading EMA5')
malongcolor1 = malong1 >= malong1[1] ? color.green : color.red
malongcolor2 = malong2 >= malong2[1] ? color.green : color.red
malongcolor3 = malong3 >= malong3[1] ? color.green : color.red
malongcolor4 = malong4 >= malong4[1] ? color.green : color.red
malongcolor5 = malong5 >= malong5[1] ? color.green : color.red
malongline1 = plot(ema1 ? malong1 : na, color=showLine ? malongcolor1 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA1')
malongline2 = plot(ema2 ? malong2 : na, color=showLine ? malongcolor2 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA2')
malongline3 = plot(ema3 ? malong3 : na, color=showLine ? malongcolor3 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA3')
malongline4 = plot(ema4 ? malong4 : na, color=showLine ? malongcolor4 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA4')
malongline5 = plot(ema5 ? malong5 : na, color=showLine ? malongcolor5 : na, linewidth=3, offset=emacloudleading, title='Long Leading EMA5')
fill(mashortline1, malongline1, color=cloudcolour1, title='MA Cloud1', transp=45)
fill(mashortline2, malongline2, color=cloudcolour2, title='MA Cloud2', transp=65)
fill(mashortline3, malongline3, color=cloudcolour3, title='MA Cloud3', transp=70)
fill(mashortline4, malongline4, color=cloudcolour4, title='MA Cloud4', transp=65)
fill(mashortline5, malongline5, color=cloudcolour5, title='MA Cloud5', transp=65)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以从 TA 的角度计算这些云的交叉或交叉。
首先等待整个云2交叉到云3;这可以通过使用每个云中较慢 MA 的交叉来完成。
其次是在云层开始交叉或下方时立即获取交叉信号。在这种情况下,您将在每个云中使用更快的 MA。
另一种选择是获取每个云的平均点并将其用于交叉信号。
最后,要存储正在使用的时间范围,您可以使用内置的
timeframe.period
因此:
res = timeframe.period
There are a few ways you can calculate a crossover or crossunder of these clouds from a TA perspective.
First is waiting for the entire cloud 2 to crossover cloud 3; this can be done by using the crossover of the slower MAs in each cloud.
Second is getting the crossover signal as soon as the clouds begin to crossover or under. In this case you would use the faster MAs in each cloud.
Another option would be getting the average point of each cloud and using those for the crossover signals.
lastly, to store the timeframe being used you can use the built-in
timeframe.period
so:
res = timeframe.period