一旦价格收于 ema100(卖出)或高于 ema100(买入),我想确定第一个 ema7/13 交叉..
你能帮忙吗?
实际上,我可以找到 ema 100 以下的柱数,但无法识别第一个 ema 7/13 交叉..
根据您的条件:
//@version=5
indicator(title='EMA 7, 13, 100', overlay=true)
//EMA
ema_1 = ta.ema(close, 7)
ema_2 = ta.ema(close, 13)
ema_3 = ta.ema(close, 100)
plot(series=ema_1, title='EMA 1', color=color.green, linewidth=1)
plot(series=ema_2, title='EMA 2', color=color.red, linewidth=1)
plot(series=ema_3, title='EMA 3', color=color.blue, linewidth=1)
// Conditions
long_condition = barstate.isconfirmed and
ema_1 > ema_3 and
ema_2 > ema_3 and
ta.crossover(ema_1, ema_2)
short_condition = barstate.isconfirmed and
ema_1 < ema_3 and
ema_2 < ema_3 and
ta.crossunder(ema_1, ema_2)
// Function to Remove Excessive Signals
exrem(condition_1, condition_2) =>
var entry_signal = 0
entry_signal := condition_1 ? 1 : condition_2 ? -1 : entry_signal[1]
entry = entry_signal != entry_signal[1]
buy = entry and entry_signal == 1
sell = entry and entry_signal == -1
[buy, sell]
// Signals
[long_signal, short_signal] = exrem(long_condition, short_condition)
// Plot
plotshape(long_signal, style=shape.triangleup, color=color.green, text='BUY', textcolor=#FFFFFF, editable=false, location=location.belowbar, size=size.small)
plotshape(short_signal, style=shape.triangledown, color=color.red, text='SELL', textcolor=#FFFFFF, editable=false, location=location.abovebar, size=size.small)
图片: