この戦略は,3つの平らな移動平均線,相対的に強い指数 ((RSI)) とウィリアムズ指数を組み合わせて,株価のトレンド方向を識別し,トレンドが逆転するときに入場機会を探します. 3つの移動平均線が上下 (上下) に並び,RSIが50より高く (下下) で,上下 (上下) のウィリアムズ指数信号が表示されたときに,多めに (空) します. 止損点は入場価格の一定パーセントに設定され,止まり点は入場価格の有利な方向への移動の一定パーセントに設定されています.
この戦略は,快線,中線,慢線を含む3つの異なる周期の平滑移動平均を使用しています. 快線が中線を横切るときは,株価が上昇傾向に入ることを示す. 快線が中線を横切るときは,株価が下降傾向に入ることを示す. 株価が上昇傾向または下降傾向にあることを確認した後,戦略は,最初の取引機会の出現を待っています.
具体的には,株価が上昇傾向に入ると,戦略は以下の5つの条件が同時に満たされるのを待って,ポジションを開きます.
株価が下落する傾向に入ると,戦略は以下の5つの条件が同時に満たされるのを待って空白ポジションを開きます.
余分な空白を行った後,戦略は,リスクを管理するためにストップ・ロースポイントとストップ・ストップポイントを設定する.具体的には,ストップ・ロースポイントは入場価格の一定パーセントであり,ストップ・ストップポイントは入場価格が有利な方向に移動した後の一定パーセントである.
複数の指標を組み合わせて入場確認を行うことで,偽突破を効果的に防ぐことができる。3つの均線がトレンドの方向を決定し,ウィリアム指標は反転信号を捕捉し,RSIフィルタは振動状況をフィルタリングし,共同で入場の正確性を向上させる。
ストップ・ストップ・ストップ・ポイントを設定することで,各株のリスク・リターン比率がよく制御され,利益のある取引が損失のある取引より大きいことを保証できます.
戦略の論理は明確で分かりやすく,パラメータの設定は合理的で,様々なレベルのトレーダーに適しています.
振動的な状況では,指標は誤った信号を発し,不必要な入場を引き起こす可能性があります. RSIのパラメータを最適化することによって,部分的な振動的な状況をフィルターすることができます.
快線中線交差は偽突破が発生する可能性があるため,他の指標と併用して使用するべきである. 交差量指標の追加を検討することができる.
入場価格からあまりにも近いストップ・ロズポイントは,出場をストップする恐れがあり,ストップ・ロズポイントの設定を適切な位置に調整する必要があります.
入場価格から遠すぎるストップポイントは,出場を止められない可能性があり,ストップポイントも適切な位置に調整する必要がある.
異なる周期のパラメータの組み合わせをテストし,3つの平均線とRSIのパラメータを最適化できます.
取引量指数などの他の指標を追加して,突破前に取引量が突出しているかどうかを判断できます.
この戦略のパラメータ設定は,異なる品種ごとにテストできます.
回測結果に基づいて収益曲線を描画し,ストップダストストップパラメータの設定をテストできます.
起動前に模擬取引を試み,パラメータ設定を最適化できます.
この戦略は全体的に論理的に明確であり,指標の組み合わせを用いて入場と出場を行うことで,リスクを効果的に制御することができる.戦略のパラメータ最適化の余地はまだ広大であり,異なるパラメータ設定をテストすることによって,この戦略は安定した収益の定量取引戦略になることができる.しかし,いかなる戦略も完全に損失を回避することはできません.トレーダーは取引の規律を維持し,利益が止まれば止まる,損失が止まれば止まる必要があります.
/*backtest
start: 2023-08-28 00:00:00
end: 2023-09-27 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//This script is a combination of 3 smoothed moving averages, and RSI. When moving averages are aligned upward (downward) and RSI is above (below) 50 and a down (up) William fractal appears, it enters long (short) position. Exiting from long and short entries are defined by StopLoss and TargetProfit.
//@version=5
strategy(title="3SmmaCrossUp + Fractal + RSI", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.03)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// inputs
// Global
src = input(close, title="Source")
stopLoss = input.float(defval = 0.1, title = "Stop Loss %", minval = 0, maxval=100, step = 0.1)
targetProfit = input.float(defval = 0.4, title = "Target Profit %", minval = 0, maxval=100, step = 0.1)
// Smooth Moving Average
fastSmmaLen = input.int(21, minval=1, title="Fast Length", group = "Smooth Moving Average")
midSmmaLen = input.int(50, minval=1, title="Mid Length",group = "Smooth Moving Average")
slowSmmaLen = input.int(200, minval=1, title="Slow Length",group = "Smooth Moving Average")
// RSI
rsiLen = input.int(defval=14, title="length", minval=1, maxval=1000, step=1, group="RSI")
// Fractals
n = input.int(title="Periods", defval=2, minval=2, group = "Fractals")
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// initialization
var waitingFirstTradeInUpwardTrend = false
var waitingFirstTradeInDownwardTrend = false
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// functions
smma(ma, src, len) =>
smma = 0.0
smma := na(smma[1]) ? ma : (smma[1] * (len - 1) + src) / len
smma
fractals(n, highs, lows) =>
// UpFractal
bool upflagDownFrontier = true
bool upflagUpFrontier0 = true
bool upflagUpFrontier1 = true
bool upflagUpFrontier2 = true
bool upflagUpFrontier3 = true
bool upflagUpFrontier4 = true
for i = 1 to n
upflagDownFrontier := upflagDownFrontier and (highs[n-i] < highs[n])
upflagUpFrontier0 := upflagUpFrontier0 and (highs[n+i] < highs[n])
upflagUpFrontier1 := upflagUpFrontier1 and (highs[n+1] <= highs[n] and highs[n+i + 1] < highs[n])
upflagUpFrontier2 := upflagUpFrontier2 and (highs[n+1] <= highs[n] and highs[n+2] <= highs[n] and highs[n+i + 2] < highs[n])
upflagUpFrontier3 := upflagUpFrontier3 and (highs[n+1] <= highs[n] and highs[n+2] <= highs[n] and highs[n+3] <= highs[n] and highs[n+i + 3] < highs[n])
upflagUpFrontier4 := upflagUpFrontier4 and (highs[n+1] <= highs[n] and highs[n+2] <= highs[n] and highs[n+3] <= highs[n] and highs[n+4] <= highs[n] and highs[n+i + 4] < highs[n])
flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4
upFractal = (upflagDownFrontier and flagUpFrontier)
// downFractal
bool downflagDownFrontier = true
bool downflagUpFrontier0 = true
bool downflagUpFrontier1 = true
bool downflagUpFrontier2 = true
bool downflagUpFrontier3 = true
bool downflagUpFrontier4 = true
for i = 1 to n
downflagDownFrontier := downflagDownFrontier and (lows[n-i] > lows[n])
downflagUpFrontier0 := downflagUpFrontier0 and (lows[n+i] > lows[n])
downflagUpFrontier1 := downflagUpFrontier1 and (lows[n+1] >= lows[n] and lows[n+i + 1] > lows[n])
downflagUpFrontier2 := downflagUpFrontier2 and (lows[n+1] >= lows[n] and lows[n+2] >= lows[n] and lows[n+i + 2] > lows[n])
downflagUpFrontier3 := downflagUpFrontier3 and (lows[n+1] >= lows[n] and lows[n+2] >= lows[n] and lows[n+3] >= lows[n] and lows[n+i + 3] > lows[n])
downflagUpFrontier4 := downflagUpFrontier4 and (lows[n+1] >= lows[n] and lows[n+2] >= lows[n] and lows[n+3] >= lows[n] and lows[n+4] >= lows[n] and lows[n+i + 4] > lows[n])
flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4
downFractal = (downflagDownFrontier and flagDownFrontier)
[upFractal, downFractal]
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// calcs
[upFractal, downFractal] = fractals(n, high, low)
rsiIsHigh = ta.rsi(src, rsiLen) >= 50
slowMa = ta.sma(src, slowSmmaLen)
midMa = ta.sma(src, midSmmaLen)
fastMa = ta.sma(src, fastSmmaLen)
slowSmma = smma(slowMa ,src, slowSmmaLen)
midSmma = smma(midMa, src, midSmmaLen)
fastSmma = smma(fastMa, src, fastSmmaLen)
isFastSmmaUpward = ta.rising(fastSmma, 1)
isMidSmmaUpward = ta.rising(midSmma, 1)
isSlowSmmaUpward = ta.rising(slowSmma, 1)
isFastSmmaDownward = ta.falling(fastSmma, 1)
isMidSmmaDownward = ta.falling(midSmma, 1)
isSlowSmmaDownward = ta.falling(slowSmma, 1)
slowMovingAveragesAreUpward = isMidSmmaUpward and isSlowSmmaUpward
slowMovingAveragesAreDownward = isMidSmmaDownward and isSlowSmmaDownward
justEnteredUpwardTrend = ta.crossover(fastSmma, midSmma) ? true : false
justEnteredDownwardTrend = ta.crossunder(fastSmma, midSmma) ? true : false
waitingFirstTradeInUpwardTrend := justEnteredUpwardTrend == true ? true : (isFastSmmaDownward or isMidSmmaDownward or isSlowSmmaDownward ? false : waitingFirstTradeInUpwardTrend)
waitingFirstTradeInDownwardTrend := justEnteredDownwardTrend == true ? true : (isFastSmmaUpward or isMidSmmaUpward or isSlowSmmaUpward ? false : waitingFirstTradeInDownwardTrend)
priceCrossedOverSlowMa = ta.crossover(close, slowSmma)
priceCrossedUnderSlowMa = ta.crossunder(close, slowSmma)
enterLongCondition = barstate.isconfirmed and low > fastSmma and rsiIsHigh and (downFractal or priceCrossedOverSlowMa) and waitingFirstTradeInUpwardTrend and strategy.position_size == 0
enterShortCondition = barstate.isconfirmed and high < fastSmma and (not rsiIsHigh) and (upFractal or priceCrossedUnderSlowMa) and waitingFirstTradeInDownwardTrend and strategy.position_size == 0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// strategy
if(enterLongCondition)
strategy.entry(id="L", direction=strategy.long)
waitingFirstTradeInUpwardTrend := false
if(enterShortCondition)
strategy.entry(id="S", direction=strategy.short)
waitingFirstTradeInDownwardTrend := false
if(strategy.position_size > 0)
strategy.exit(id="EL", stop=strategy.position_avg_price * (1 - stopLoss/100), limit=strategy.position_avg_price * (1+targetProfit/100))
if(strategy.position_size < 0)
strategy.exit(id="ES", stop=strategy.position_avg_price * (1 + stopLoss/100), limit=strategy.position_avg_price * (1-targetProfit/100))
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// plots
plot(series = slowSmma, title="Slow SMMA", linewidth=3)
plot(series = midSmma, title="Mid SMMA", linewidth=2)
plot(series = fastSmma, title="Fast SMMA", linewidth=1)
plotchar(series=rsiIsHigh, title='rsiIsHigh', char='')
plotchar(series=justEnteredUpwardTrend, title='justEnteredUpwardTrend', char='')
plotchar(series=justEnteredDownwardTrend, title='justEnteredDownwardTrend', char='')
plotchar(series=waitingFirstTradeInUpwardTrend, title='waitingFirstTradeInUpwardTrend', char='')
plotchar(series=waitingFirstTradeInDownwardTrend, title='waitingFirstTradeInDownwardTrend', char='')
plotchar(series=enterLongCondition, title='enterLongCondition' , char='')
plotchar(series=enterShortCondition, title='enterShortCondition' , char='')
plotshape(series=upFractal, title='upFractal', style=shape.triangleup, location=location.abovebar, color=#009688, size = size.tiny)
plotshape(series=downFractal, title='downFractal', style=shape.triangledown, location=location.belowbar, color=color.red, size = size.tiny)