Pine 脚本用于多个时间范围内的一些 EMA
Pine Script for a few EMAs on multiple timeframes
我正在尝试构建一个脚本,该脚本多次显示相同的 EMA 长度但在不同的时间范围内运行。我无法弄清楚时间表部分。无论我做什么,它都只能让我将所有 ema 调整为 1 个时间范围,我真的希望在许多不同的时间线上拥有相同的 ema。
例如,我想让 AAPL 在 1 分钟图表上显示 6 个不同的 20 个 EMA,但每个 6 个 EMA 都在不同的时间范围内。即1分钟、10分钟、60分钟、240分钟等。
使用secutiry()
函数。
//@version=4
study("My Script")
plot(ema(close, 10))
plot( security("AAPL", "1", ema(close,10)))
其他时间段依此类推。
https://www.tradingview.com/pine-script-reference/v4/#fun_security
需要在每个时间段的安全调用上下文中调用 ema()
函数
ema20_1 = security("AAPL", 1, ema(close, 20))
ema20_5 = security("AAPL", 5, ema(close, 20))
ema20_10 = security("AAPL", 10, ema(close,20))
plot(ema20_1)
plot(ema20_5)
plot(ema20_10)
此外,在这种情况下,图表的时间范围必须为 1 分钟(或更短),以便安全调用参考的时间范围不会低于图表的时间范围。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SafetyHammer
//@version=4
study("My Script", overlay=true)
ShowMA = input(title="Show Moving Average", type=input.bool, defval=true)
MA_Period1 = input(title="MA 1 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period2 = input(title="MA 2 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period3 = input(title="MA 3 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period4 = input(title="MA 4 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period5 = input(title="MA 5 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period6 = input(title="MA 6 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Source = input(title="Source for all", type=input.source, defval=close, group="Moving Average")
MA_Res1 = input(title="MA 1 Resolution", type=input.resolution, defval="1", group="Moving Average")
MA_Res2 = input(title="MA 2 Resolution", type=input.resolution, defval="5", group="Moving Average")
MA_Res3 = input(title="MA 3 Resolution", type=input.resolution, defval="10", group="Moving Average")
MA_Res4 = input(title="MA 4 Resolution", type=input.resolution, defval="30", group="Moving Average")
MA_Res5 = input(title="MA 5 Resolution", type=input.resolution, defval="60", group="Moving Average")
MA_Res6 = input(title="MA 6 Resolution", type=input.resolution, defval="240", group="Moving Average")
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1],barmerge.gaps_on, lookahead = barmerge.lookahead_on) // orignal code line
MA_Function1 = f_secureSecurity(syminfo.tickerid, MA_Res1, ema(MA_Source, MA_Period1))
MA_Function2 = f_secureSecurity(syminfo.tickerid, MA_Res2, ema(MA_Source, MA_Period2))
MA_Function3 = f_secureSecurity(syminfo.tickerid, MA_Res3, ema(MA_Source, MA_Period3))
MA_Function4 = f_secureSecurity(syminfo.tickerid, MA_Res4, ema(MA_Source, MA_Period4))
MA_Function5 = f_secureSecurity(syminfo.tickerid, MA_Res5, ema(MA_Source, MA_Period5))
MA_Function6 = f_secureSecurity(syminfo.tickerid, MA_Res6, ema(MA_Source, MA_Period6))
ma1_plot = plot(series=MA_Function1, title="Moving Average 1", color=iff(ShowMA, color.aqua, na), style=plot.style_line, linewidth=1)
ma2_plot = plot(series=MA_Function2, title="Moving Average 2", color=iff(ShowMA, color.blue, na), style=plot.style_line, linewidth=1)
ma3_plot = plot(series=MA_Function3, title="Moving Average 3", color=iff(ShowMA, color.lime, na), style=plot.style_line, linewidth=1)
ma4_plot = plot(series=MA_Function4, title="Moving Average 4", color=iff(ShowMA, color.green, na), style=plot.style_line, linewidth=1)
ma5_plot = plot(series=MA_Function5, title="Moving Average 5", color=iff(ShowMA, color.olive, na), style=plot.style_line, linewidth=1)
ma6_plot = plot(series=MA_Function6, title="Moving Average 6", color=iff(ShowMA, color.red, na), style=plot.style_line, linewidth=1)
我正在尝试构建一个脚本,该脚本多次显示相同的 EMA 长度但在不同的时间范围内运行。我无法弄清楚时间表部分。无论我做什么,它都只能让我将所有 ema 调整为 1 个时间范围,我真的希望在许多不同的时间线上拥有相同的 ema。
例如,我想让 AAPL 在 1 分钟图表上显示 6 个不同的 20 个 EMA,但每个 6 个 EMA 都在不同的时间范围内。即1分钟、10分钟、60分钟、240分钟等。
使用secutiry()
函数。
//@version=4
study("My Script")
plot(ema(close, 10))
plot( security("AAPL", "1", ema(close,10)))
其他时间段依此类推。
https://www.tradingview.com/pine-script-reference/v4/#fun_security
需要在每个时间段的安全调用上下文中调用 ema()
函数
ema20_1 = security("AAPL", 1, ema(close, 20))
ema20_5 = security("AAPL", 5, ema(close, 20))
ema20_10 = security("AAPL", 10, ema(close,20))
plot(ema20_1)
plot(ema20_5)
plot(ema20_10)
此外,在这种情况下,图表的时间范围必须为 1 分钟(或更短),以便安全调用参考的时间范围不会低于图表的时间范围。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SafetyHammer
//@version=4
study("My Script", overlay=true)
ShowMA = input(title="Show Moving Average", type=input.bool, defval=true)
MA_Period1 = input(title="MA 1 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period2 = input(title="MA 2 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period3 = input(title="MA 3 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period4 = input(title="MA 4 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period5 = input(title="MA 5 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Period6 = input(title="MA 6 Length", type=input.integer, defval=20, minval=1, group="Moving Average")
MA_Source = input(title="Source for all", type=input.source, defval=close, group="Moving Average")
MA_Res1 = input(title="MA 1 Resolution", type=input.resolution, defval="1", group="Moving Average")
MA_Res2 = input(title="MA 2 Resolution", type=input.resolution, defval="5", group="Moving Average")
MA_Res3 = input(title="MA 3 Resolution", type=input.resolution, defval="10", group="Moving Average")
MA_Res4 = input(title="MA 4 Resolution", type=input.resolution, defval="30", group="Moving Average")
MA_Res5 = input(title="MA 5 Resolution", type=input.resolution, defval="60", group="Moving Average")
MA_Res6 = input(title="MA 6 Resolution", type=input.resolution, defval="240", group="Moving Average")
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1],barmerge.gaps_on, lookahead = barmerge.lookahead_on) // orignal code line
MA_Function1 = f_secureSecurity(syminfo.tickerid, MA_Res1, ema(MA_Source, MA_Period1))
MA_Function2 = f_secureSecurity(syminfo.tickerid, MA_Res2, ema(MA_Source, MA_Period2))
MA_Function3 = f_secureSecurity(syminfo.tickerid, MA_Res3, ema(MA_Source, MA_Period3))
MA_Function4 = f_secureSecurity(syminfo.tickerid, MA_Res4, ema(MA_Source, MA_Period4))
MA_Function5 = f_secureSecurity(syminfo.tickerid, MA_Res5, ema(MA_Source, MA_Period5))
MA_Function6 = f_secureSecurity(syminfo.tickerid, MA_Res6, ema(MA_Source, MA_Period6))
ma1_plot = plot(series=MA_Function1, title="Moving Average 1", color=iff(ShowMA, color.aqua, na), style=plot.style_line, linewidth=1)
ma2_plot = plot(series=MA_Function2, title="Moving Average 2", color=iff(ShowMA, color.blue, na), style=plot.style_line, linewidth=1)
ma3_plot = plot(series=MA_Function3, title="Moving Average 3", color=iff(ShowMA, color.lime, na), style=plot.style_line, linewidth=1)
ma4_plot = plot(series=MA_Function4, title="Moving Average 4", color=iff(ShowMA, color.green, na), style=plot.style_line, linewidth=1)
ma5_plot = plot(series=MA_Function5, title="Moving Average 5", color=iff(ShowMA, color.olive, na), style=plot.style_line, linewidth=1)
ma6_plot = plot(series=MA_Function6, title="Moving Average 6", color=iff(ShowMA, color.red, na), style=plot.style_line, linewidth=1)