当满足以下标准时,此策略将产生买入或卖出信号:
9个均线交叉21个均线 最近关闭的K线BAR的平均体积比之前的5支蜡烛高出15% 反转 价格超过9均线
您可以随意使用和修改。交易愉快!
回测测试
/*backtest
start: 2021-12-01 09:00:00
end: 2022-04-19 15:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","rb888",360008]]
*/
//@version=5
//Author: Andrew Shubitowski
strategy("Buy/Sell Strat", overlay = true)
//Define EMAs & Crossovers (Feature 2)
a = ta.ema(close, 9)
b = ta.ema(close, 21)
crossUp = ta.crossover(a, b)
crossDown = ta.crossunder(a, b)
//Define & calc volume averages (Feature 1)
float volAvg = 0
for i = 1 to 5
volAvg := volAvg + volume[i]
volAvg := volAvg / 5
//Define candlestick pattern recongition (Feature 4)
bool reversalPatternUp = false
bool reversalPatternDown = false
if (close > close[1] and close[1] > close [2] and close[3] > close[2] and close > close[3])
reversalPatternUp := true
if (close < close[1] and close[1] < close [2] and close[3] < close[2] and close < close[3])
reversalPatternDown := true
//Execute trade (Feature 3 + 5)
if (crossUp)
strategy.entry("long", strategy.long, when = ((volume * 0.85) > volAvg and close > a and reversalPatternUp == true))
if (crossDown)
strategy.entry("short", strategy.short, when = ((volume * 0.85) > volAvg and close < a and reversalPatternDown == true))
//Exit strategy (New Feature)
//close_condition_long = close < a
//close_condition_short = close > a
//if (close_condition_long)
// strategy.close("long")
//
//if (close_condition_short)
// strategy.close("short")
//plot the EMAs
plot(a, title = "Fast EMA", color = color.green)
plot(b, title = "Slow EMA", color = color.blue)
//Some visual validation parameters
//plotchar(volAvg, "Volume", "", location.top, color.aqua) //*TEST* volume calc check
//plotshape(reversalPatternUp, style = shape.arrowup, color = color.aqua) //*TEST* reversal check
//plotshape(reversalPatternDown, style = shape.arrowup, location = location.belowbar, color = color.red) //*TEST* reversal check