资源加载中... loading...

TUE ADX/MACD汇集策略

Author: 雨幕(youquant), Date: 2022-06-15 10:13:17
Tags: ADXMACD

MACD/ADX

回测测试

img

img

img


/*backtest
start: 2021-06-08 09:00:00
end: 2022-06-14 15:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","rb888",360008]]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Written by TradersUltimateEdge
// Code provided open source, feel free to use it for any purpose except resale

//@version=5
indicator("TUE ADX/MACD Confluence V1.0", overlay=true)

showsignals = input(true, title="显示 买入/卖出 信号")
showcandlecolors = input(true, title="显示 K线 颜色")
length = input(14, title="ADX 周期")
smoothing = input(10, title="ADX 平滑")
macdsource = input(close, title="MACD 数据源")
macdfast = input(12, title="MACD 快线 周期")
macdslow = input(26, title="MACD 慢线 周期")
macdsignal = input(9, title="MACD 信号 周期")
colorup = input(color.green, title="向上 BAR 颜色")
colordown = input(color.red, title="向下 BAR 颜色")


/////////////////////////////////////////////////////////////////////////////////////////////// ADX AND MACD CALC
[diplus, diminus, adx] = ta.dmi(length, smoothing)

[macdline, signalline, histline] = ta.macd(macdsource, macdfast, macdslow, macdsignal)

//////////////////////////////////////////////////////////////////////////////////////////////TRADE CALC

longcheck = diplus > diminus and macdline > signalline
shortcheck = diminus > diplus and signalline > macdline

int trade = 0

//Open from nothing

if trade == 0 and longcheck
    trade := 1

else if trade == 0 and shortcheck
    trade := -1
    
//Reversal

else if trade == 1 and shortcheck
    trade := -1
    
else if trade == -1 and longcheck
    trade := 1
    
//Keep status quo until crossover

else
    trade := trade[1]

//////////////////////////////////////////////////////////////////////////////////////////////PLOT 

colors = longcheck ? colorup : shortcheck ? colordown : color.white

plotcandle(open, high, low, close, color = showcandlecolors ? colors : na)

plotshape(trade[1] != 1 and trade == 1 and showsignals, style=shape.labelup, text='BUY', textcolor=color.white, color=color.green, size=size.small, location=location.belowbar)
plotshape(trade[1] != -1 and trade == -1 and showsignals, style=shape.labeldown, text='SELL', textcolor=color.white, color=color.red, size=size.small, location=location.abovebar)

///////////////////////////////////////////////////////////////////////////////////////////// ALERTS

alertcondition(trade[1] != 1 and trade == 1, "LONG")
alertcondition(trade[1] != -1 and trade == -1, "SHORT")
if trade[1] != 1 and trade == 1
   strategy.entry("buy", strategy.long)
else if trade[1] != -1 and trade == -1
    strategy.entry("sell", strategy.short)



相关内容

更多内容