我想在 TradingView 上的 Pine Editor 中结合 2 个指标来触发“买入”或“卖出”信号。
目前我有 Demark9 指标的代码,但我想在相同的“IF”语句下与二级指标结合。
例如:
买入:如果 Demark9 location.belowbar 为TRUE
ANDMACD 指标为TRUE
,则在图表上绘制“买入”信号。
卖出:如果 Demark9 location.abovebar 是TRUE
ANDMACD 指标是TRUE
那么 '卖出' 信号。
是目前工作的代码,但我想添加一个额外的指标到相同的买入或卖出信号:
//DeMark_9_Indicator_1
study("Nathan's Bot Indicator",overlay=true)
TD = close > close[4] ?nz(TD[1])+1:0
TS = close < close[4] ?nz(TS[1])+1:0
TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
plotshape(TDUp==7?true:na,style=shape.down,text="7",color=green,location=location.abovebar)
plotshape(TDUp==8?true:na,style=shape.down,text="8",color=green,location=location.abovebar)
plotshape(TDUp==9?true:na,style=shape.down,text="⚠️",color=green,location=location.abovebar)
plotshape(TDDn==7?true:na,style=shape.up,text="7",color=red,location=location.belowbar)
plotshape(TDDn==8?true:na,style=shape.up,text="8",color=red,location=location.belowbar)
plotshape(TDDn==9?true:na,style=shape.up,text="✅",color=red,location=location.belowbar)
任何帮助是超级赞赏。
谢谢你,宇宙
您只需要使用and
运算符并导入 MACD 指标。您可以通过单击 MACD 上的代码图标来查看 MACD 的源代码。复制将 macd 粘贴到您的脚本中。
//macd
macd_fast = 12, macd_slow = 26
macd_fastMA = ema(close, macd_fast)
macd_slowMA = ema(close, macd_slow)
macd = macd_fastMA - macd_slowMA
macd_signal = sma(macd, 9)
macd_hist = macd - macd_signal
然后为 macd 示例添加您的条件:
macd_buy = macd_hist > 0
macd_sell = macd_hist < 0
然后你可以使用and
运算符来组合这两个条件。
//DeMark_9_Indicator_1
study("Nathan's Bot Indicator",overlay=true)
TD = close > close[4] ?nz(TD[1])+1:0
TS = close < close[4] ?nz(TS[1])+1:0
TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
//macd
macd_fast = 12, macd_slow = 26
macd_fastMA = ema(close, macd_fast)
macd_slowMA = ema(close, macd_slow)
macd = macd_fastMA - macd_slowMA
macd_signal = sma(macd, 9)
macd_hist = macd - macd_signal
macd_buy = macd_hist > 0
macd_sell = macd_hist < 0
plotshape(TDUp==7 and macd_sell ?true:na,style=shape.down,text="7",color=green,location=location.abovebar)
plotshape(TDUp==8 and macd_sell ?true:na,style=shape.down,text="8",color=green,location=location.abovebar)
plotshape(TDUp==9 and macd_sell ?true:na,style=shape.down,text="⚠️",color=green,location=location.abovebar)
plotshape(TDDn==7 and macd_buy ?true:na,style=shape.up,text="7",color=red,location=location.belowbar)
plotshape(TDDn==8 and macd_buy ?true:na,style=shape.up,text="8",color=red,location=location.belowbar)
plotshape(TDDn==9 and macd_buy ?true:na,style=shape.up,text="✅",color=red,location=location.belowbar)
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(85条)