
该策略是一个基于均线的追踪策略。它利用均线的方向和candle的影线来判断价格趋势和力度,以决定entries和exits。核心逻辑是当第二条均线颜色改变时做多/空,然后利用第三条均线的强势信号来加仓,最多加5单。
策略使用Heikin Ashi均线来判断趋势。具体来说,策略定义了3条均线:
AddEntry逻辑:
Exit逻辑:
该策略具有以下优势:
该策略也存在一些风险:
可通过止损,调整加仓次数,参数优化来控制风险。
该策略可从以下方面进行优化:
该策略整体来说是一个基于双均线方向性的追踪策略。它融合了趋势判断和突破判断的优点,通过加仓扩大获利。但也需要注意控制风险,适当调整参数。未来可从优化止损,参数调整等方面进行改进。
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("平均K腳本交易策略", overlay=true)
// 定義 Heikin Ashi 指標
ha_open = security(heikinashi(syminfo.tickerid), "60", open)
ha_high = security(heikinashi(syminfo.tickerid), "60", high)
ha_low = security(heikinashi(syminfo.tickerid), "60", low)
ha_close = security(heikinashi(syminfo.tickerid), "60", close)
// 確定 Heikin Ashi 指標的顏色
isGreen = ha_open < ha_close
// 定義加碼次數
var int add_on_buy = 10
var int add_on_sell = 10
// 定義進場和出場條件
long_condition = crossover(ha_close, ha_open) and isGreen and ha_low == ha_open
short_condition = crossunder(ha_close, ha_open) and not isGreen and ha_high == ha_open
exit_condition = crossover(ha_open, ha_close) or crossunder(ha_open, ha_close)
// 如果條件符合,進行進場和出場操作
if (long_condition)
strategy.entry("Buy", strategy.long)
if (short_condition)
strategy.entry("Sell", strategy.short)
if (exit_condition)
strategy.close("Buy")
strategy.close("Sell")
// 繪製 Heikin Ashi 蠟燭圖
plotcandle(iff(ha_open < ha_close, ha_open, na), ha_high, ha_low, ha_close, title='Green Candles', color=#53b987, wickcolor=#53b987, bordercolor=#53b987)
plotcandle(iff(ha_open >= ha_close, ha_open, na), ha_high, ha_low, ha_close, title='Red Candles', color=#eb4d5c, wickcolor=#eb4d5c, bordercolor=#eb4d5c)