我试图建立一种策略,该策略按照以下条件添加多头头寸:
该策略基于34 ema波策略,该策略根据条形图在高,低和关闭时与34 ema的距离来绘制条形的颜色。
我已经使用barsince函数来尝试实现此功能,但是在获取数据和交易时遇到了麻烦。
任何帮助将不胜感激。
// === STRATEGY === //
TP = (200)
SL = (100)
EMA_len = input(34, title="EMA wave length")
EMA_src = input(close, title="EMA wave length")
EMA_lim = input(4, title="No of green bars")
EMA_High = ema(high, PACLen)
EMA_High_Over = crossover(close, EMA_High)
since_EMA_High_Over = barssince(EMA_High_Over)
plot(since_EMA_High_Over)
longCondition = EMA_High_Over and since_EMA_High_Over <= EMA_lim
if (longCondition)
strategy.entry("Buy", strategy.long)
strategy.exit("Close", profit = TP, loss = SL)