
この戦略は,主に高低指標,平均線指標と超トレンド指標を組み合わせて,市場の傾向を判断してポジションを立てる.
高低指標によって,最近一定の周期で価格が新高または新低を創ったかどうかを判断し,スコアを累積する.スコアが上がると,多頭力の強化を代表する.スコアが下がると,空頭力の強化を代表する.
平均線指標を使用して,価格が上下階段型の上昇傾向にあるかどうかを判断するか,上下階段型の下降傾向にあるかを判断する.平均線が階段型の上昇を示したとき,多頭力の強化を代表する.平均線が階段型の下降を示したとき,空頭力の強化を代表する.
高低指数と平均線指数の判断結果を組み合わせて,市場トレンドを決定する.さらに,超トレンド指数の方向を組み合わせて,ポジション構築の機会を探す.具体的には,高低指数と平均線指数が多頭力の増加を示し,超トレンド指数が下向きであるとき,長ポジション構築を行う.高低指数と平均線指数が空頭力の増加を示し,超トレンド指数が上向きであるとき,空ポジション構築を行う.
高低指標は価格の動向と力の変化を効果的に判断し,均線指標は価格の動向を効果的に判断し,両者は組み合わせて市場の方向をより正確に判断できる.
超トレンド指標と組み合わせて倉庫を建設することは,倉庫を早すぎたり遅すぎたりするのを防ぐことができます.超トレンド指標は価格の逆転点を効果的に識別できます.
複数の指標が相互検証することで,偽信号を減らすことができます.
高低指数と平均線指数が誤った信号を発した場合は,負債の形成が起こりうる.
参加率が低い場合,超トレンド指標のパラメータが正しく設定されていない場合,誤ったシグナルが出る可能性があります.
トレンドの逆転が速すぎると,ストップ・ロスの設定が不適切で,大きな損失を招く可能性があります.
指数パラメータの最適化,ストップポイントの調整などによってリスクを軽減することができる.
異なるタイプの平均線指標をテストし,最適なパラメータの組み合わせを探します.
高低指標と平均線指標のパラメータを最適化して,信号をより安定して信頼できるようにする.
MACD,KDなど,偽信号を減らすために,他の指標と組み合わせて検証できます.
機械学習アルゴリズムを組み合わせてパラメータと信号重量を自動的に最適化します.
感情分析などと組み合わせて市場の熱度を判断し,低熱度の品種を取引することを避ける.
この戦略は,高低指標と均線指標によって市場の傾向と力を判断し,その後超トレンド指標のフィルター信号と組み合わせて,多空力対決と超トレンド指標の逆転時にポジションを構築し,低リスク取引を実現する.戦略の優位性は,多指標検証とタイムリーポジションを構築し,リスクを効果的に制御できる.存在している問題は,偽信号とトレンド判断の誤りである.パラメータ最適化,ストップ損失設定,シグナルフィルターなど,複数の方法で改善でき,戦略をより安定して信頼性がある.
/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
//@version=4
strategy("AlignedMA and Cumulative HighLow Strategy", overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01, calc_on_order_fills = true)
MAType = input(title="Moving Average Type", defval="sma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
includePartiallyAligned = input(true)
HighLowPeriod = input(50, minval=1,step=1)
LookbackPeriod = input(10, minval=1,step=1)
supertrendMult = input(2, minval=1, maxval=10, step=0.5)
supertrendLength = input(10, minval=1)
tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
backtestYears = input(10, minval=1, step=1)
f_getMovingAverage(source, MAType, length)=>
ma = sma(source, length)
if(MAType == "ema")
ma := ema(source,length)
if(MAType == "hma")
ma := hma(source,length)
if(MAType == "rma")
ma := rma(source,length)
if(MAType == "vwma")
ma := vwma(source,length)
if(MAType == "wma")
ma := wma(source,length)
ma
f_getMaAlignment(MAType, includePartiallyAligned)=>
ma5 = f_getMovingAverage(close,MAType,5)
ma10 = f_getMovingAverage(close,MAType,10)
ma20 = f_getMovingAverage(close,MAType,20)
ma30 = f_getMovingAverage(close,MAType,30)
ma50 = f_getMovingAverage(close,MAType,50)
ma100 = f_getMovingAverage(close,MAType,100)
ma200 = f_getMovingAverage(close,MAType,200)
upwardScore = 0
upwardScore := close > ma5? upwardScore+1:upwardScore
upwardScore := ma5 > ma10? upwardScore+1:upwardScore
upwardScore := ma10 > ma20? upwardScore+1:upwardScore
upwardScore := ma20 > ma30? upwardScore+1:upwardScore
upwardScore := ma30 > ma50? upwardScore+1:upwardScore
upwardScore := ma50 > ma100? upwardScore+1:upwardScore
upwardScore := ma100 > ma200? upwardScore+1:upwardScore
upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 5? 0.5: upwardScore < 2?-0.5:upwardScore>3?0.25:-0.25) : 0
f_getHighLowValue(HighLowPeriod)=>
currentHigh = highest(high,HighLowPeriod) == high
currentLow = lowest(low,HighLowPeriod) == low
currentHigh?1:currentLow?-1:0
inDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)
maAlignment = f_getMaAlignment(MAType,includePartiallyAligned)
alignedMaIndex = sum(maAlignment,LookbackPeriod)
maAlignmentDirection = alignedMaIndex > alignedMaIndex[1] ? 1 : alignedMaIndex < alignedMaIndex[1] ? -1 : 0
maAlignmentDirection := maAlignmentDirection == 0? nz(maAlignmentDirection[1],0):maAlignmentDirection
highLowIndex = f_getHighLowValue(HighLowPeriod)
cumulativeHighLowIndex = sum(highLowIndex,LookbackPeriod)
hlDirection = cumulativeHighLowIndex > cumulativeHighLowIndex[1] ? 1 : cumulativeHighLowIndex < cumulativeHighLowIndex[1] ? -1 : 0
hlDirection := hlDirection == 0? nz(hlDirection[1],0):hlDirection
[superTrend, dir] = supertrend(supertrendMult, supertrendLength)
buyEntry = (dir == -1 and maAlignmentDirection == 1 and hlDirection == 1)
sellEntry = (dir == 1 and maAlignmentDirection == -1 and hlDirection == -1)
barColor = buyEntry?color.lime:sellEntry?color.orange:color.gray
barcolor(barColor)
// strategy.risk.allow_entry_in(tradeDirection)
strategy.entry("Buy", strategy.long, when=barColor == color.lime and inDateRange, oca_name="oca_buy")
strategy.close("Buy", when=dir == 1)
strategy.entry("Sell", strategy.short, when=barColor == color.orange and inDateRange, oca_name="oca_sell")
strategy.close("Sell", when=dir == -1)