在长期趋势显示为上涨时,可以在较低时间框架上购买和卖出标记。为了实现这个策略,我们可以使用以下代码:
//@version=4 strategy("Buy and Sell Markers on Lower Time Frames when Longer Time Frame Shows Uptrend", overlay=true, margin_long=100, margin_short=100)
//长期时间框架 resLong = input("D", title="Long-Term Timeframe") lenLong = input(20, title="Long-Term Moving Average Length") srcLong = input(close, title="Long-Term Moving Average Source") maLong = sma(srcLong, lenLong)
//判断趋势是否上涨 longCondition = close > maLong
//单独的窗口显示较长时间框架上的结果 plot(series=maLong, title="Long-Term MA", color=color.green, linewidth=2, transp=0)
//短期时间框架 resShort = input("60", title="Short-Term Timeframe") lenShort = input(5, title="Short-Term Moving Average Length") srcShort = input(close, title="Short-Term Moving Average Source") maShort = sma(srcShort, lenShort)
//判断趋势是否上涨 shortCondition = close > maShort
//单独的窗口,显示较短时间框架上的结果 plot(series=maShort, title="Short-Term MA", color=color.blue, linewidth=2, transp=0)
//确定买入和卖出信号 buySignal = crossover(maShort, maLong) and longCondition and shortCondition sellSignal = crossunder(maShort, maLong) and longCondition and shortCondition
//下单代码 if (buySignal) strategy.entry("Long", strategy.long) if (sellSignal) strategy.entry("Short", strategy.short)
//标记指示
下一篇:不严格相邻的递增子数组