本策略基于Kevin Davey的免费原油期货交易策略改编。该策略利用ADX指标判断原油市场的趋势,结合价格突破原则,实现了一个简单实用的原油自动交易策略。
该策略主要依赖ADX指标判断趋势,并在趋势情况下根据固定周期的价格突破产生交易信号。整个策略逻辑非常简单清晰。
本策略总的来说是一个非常实用的原油交易策略。它利用ADX指标判断趋势非常合理,价格突破原则简单有效,回测效果良好。同时作为Kevin Davey的公开免费策略,它具有很强的实战可靠性。虽然策略也存在一定改进空间,但对于初学者和小资金交易者来说,本策略是一个非常适合入门和实践的选择。
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// Strategy idea coded from EasyLanguage to Pinescript
//@version=5
strategy("Kevin Davey Crude free crude oil strategy", shorttitle="CO Fut", format=format.price, precision=2, overlay = true, calc_on_every_tick = true)
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
plot(sig, color=color.red, title="ADX")
buy = sig > 10 and (close - close[65]) > 0 and (close - close[65])[1] < 0
sell = sig > 10 and (close - close[65]) < 0 and (close - close[65])[1] > 0
plotshape(buy, style = shape.arrowup, location = location.belowbar,size = size.huge)
plotshape(sell, style = shape.arrowdown, location = location.abovebar,size = size.huge)
if buy
strategy.entry("long", strategy.long)
if sell
strategy.entry("short", strategy.short)
if strategy.position_size != 0
strategy.exit("long", profit = 450, loss = 300)
strategy.exit("short", profit = 450, loss = 300)
// GetTickValue() returns the currency value of the instrument's
// smallest possible price movement.
GetTickValue() =>
syminfo.mintick * syminfo.pointvalue
// On the last historical bar, make a label to display the
// instrument's tick value
if barstate.islastconfirmedhistory
label.new(x=bar_index + 1, y=close, style=label.style_label_left,
color=color.black, textcolor=color.white, size=size.large,
text=syminfo.ticker + " has a tick value of:\n" +
syminfo.currency + " " + str.tostring(GetTickValue()))