3つの指数関数移動平均値とストカスティック相対強度指標の取引戦略

作者: リン・ハーンチャオチャン, 日付: 2024-01-30 16:52:48
タグ:

img

概要

この戦略は,トレードシグナルを生成するために,トリプル指数関数移動平均値 (EMA) とストコスタス相対強度指数 (Stoch RSI) を組み合わせるトレンドフォロー戦略である. 急速なEMAが中間EMAを横切り,中間EMAが緩やかなEMAを横切ったときに長くなって,逆が起きたとき短くなってしまいます. この戦略は,ストコスタス相対強度指数 (Stoch RSI) を補助指標として使用します.

原則

  1. 8日間のEMA > 14日間のEMA > 50日間のEMAでロングに行く.逆の場合はショートに行く.

  2. ストーカスティックRSIを補助指標として使用する.まず14日間のRSIを計算し,その後RSI上のストーカスティックを計算し,最後に3日間のSMAをK線として計算し,K線上の3日間のSMAをD線として計算する.KがDを横切ると長い信号が得られる.

  3. ロング・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ショート・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ショート・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる時 ロング・シグナルで8日間の EMAを閉じる.

  4. ストップ・ロスはエントリー価格を下/上1ATR距離で設定され,利益はエントリー価格を下/上4ATR距離で設定される.

優位性

  1. 基本指標としてのEMAは,トレンドを効果的に追跡することができます.トリプルEMAは,複数の期間をみ,短期的および長期的トレンドの両方を把握します.

  2. 誤った信号をフィルタリングして 入力精度を高めます

  3. ATRベースのストップ・ロストとテイク・プロフィートは,不適切な投資を回避し,市場の変動を動的に追跡することができます.

  4. この戦略は,パラメータをよく調整し,トレンド期間に優れたパフォーマンスを発揮します. 引き上げは小さく,長期取引では利益は一貫しています.

リスク

  1. 複数の指標の組み合わせにより,ウィップソーリスクが増加する. EMAとストックRSIの間の矛盾する信号は,悪いレベルに入ることを引き起こします. このような場合,価格傾向自体は監視する必要があります.

  2. 保守的なストップ・ロストとテイク・プロフィートの設定は,巨大な市場の変動によって違反し,さらなるトレンドを欠く早期出口を引き起こす可能性があります. ATRパラメータを調整したり,SL/TP倍数を増加させることも役立ちます.

  3. トリプル EMA の設定は,高速線と中間線が逆転するときに一定の遅れがあります.価格のトレンド自体も,エントリを決定するために監視する必要があります.

  4. この戦略は,トレンド市場を好む.横向市場はうまく機能しない.MA期間を調整したり,他の補助指標を追加したりすることが役立ちます.

改良

  1. MACDのような指標を追加して より良いエントリをします.

  2. ATRの長/短テストパラメータを最適化します.例えば,ストップ損失を1ATRから1.5ATRに調整し,より良い結果のために4ATRから3ATRに利益を取ります.

  3. ストックRSIを削除し 騒音をフィルターし 安定した利益を得るため MAだけを維持します

  4. 取引量などの傾向を判断する基準を追加し 重要な水準を下回る

結論

この戦略は,トレンドを決定するために三重EMAとストックRSIを組み合わせます.厳格なエントリーシグナルが不必要な取引を減らす.ATRに基づくダイナミックSLとTPはパラメータを適応させます.バックテストは,トレンド期間に小さな引き下げと一貫した利益で優れた結果を示します.さらなる最適化はさらに良い結果をもたらす可能性があります.


/*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"}]
*/

//              3ESRA
//              v0.2a

// Coded by Vaida Bogdan

// 3ESRA consists of a 3 EMA cross + a close above (for longs) the quickest EMA
// or below (for shorts). Note that I've deactivated the RSI Cross Over/Under
// (you can modify the code and activate it). The strategy also uses a stop loss
// that's at 1 ATR distance from the entry price and a take profit that's at
// 4 times the ATR distance from the entry price.

// Feedback:
// Tested BTCUSDT Daily
// 1. Stoch-RSI makes you miss opportunities.
// 2. Changing RR to 4:1 times ATR works better.

//@version=4
strategy(title="3 EMA + Stochastic RSI + ATR", shorttitle="3ESRA", overlay=true, pyramiding=1,
     process_orders_on_close=true, calc_on_every_tick=true,
     initial_capital=1000, currency = currency.USD, default_qty_value=10, 
     default_qty_type=strategy.percent_of_equity,
     commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)

startDate = input(title="Start Date", type=input.integer,
     defval=1, minval=1, maxval=31, group="Backtesting range")
startMonth = input(title="Start Month", type=input.integer,
     defval=1, minval=1, maxval=12, group="Backtesting range")
startYear = input(title="Start Year", type=input.integer,
     defval=1900, minval=1800, maxval=2100, group="Backtesting range")
endDate = input(title="End Date", type=input.integer,
     defval=1, minval=1, maxval=31, group="Backtesting range")
endMonth = input(title="End Month", type=input.integer,
     defval=1, minval=1, maxval=12, group="Backtesting range")
endYear = input(title="End Year", type=input.integer,
     defval=2040, minval=1800, maxval=2100, group="Backtesting range")

// Date range filtering
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and
     (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 23, 59))
     
fast = input(8, minval=8, title="Fast EMA", group="EMAs")
medium = input(14, minval=8, title="Medium EMA", group="EMAs")
slow = input(50, minval=8, title="Slow EMA", group="EMAs")
src = input(close, title="Source")

smoothK = input(3, "K", minval=1, group="Stoch-RSI", inline="K&D")
smoothD = input(3, "D", minval=1, group="Stoch-RSI", inline="K&D")
lengthRSI = input(14, "RSI Length", minval=1, group="Stoch-RSI", inline="length")
lengthStoch = input(14, "Stochastic Length", minval=1, group="Stoch-RSI", inline="length")
rsiSrc = input(close, title="RSI Source", group="Stoch-RSI")

length = input(title="Length", defval=14, minval=1, group="ATR")
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"], group="ATR")

// EMAs
fastema = ema(src, fast)
mediumema = ema(src, medium)
slowema = ema(src, slow)

// S-RSI
rsi1 = rsi(rsiSrc, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
sRsiCrossOver = k[1] < d[1] and k > d
sRsiCrossUnder = k[1] > d[1] and k < d

// ATR
ma_function(source, length) =>
	if smoothing == "RMA"
		rma(source, length)
	else
		if smoothing == "SMA"
			sma(source, length)
		else
			if smoothing == "EMA"
				ema(source, length)
			else
				wma(source, length)
atr = ma_function(tr(true), length)

// Trading Logic
longCond1 = (fastema > mediumema) and (mediumema > slowema)
longCond2 = true
// longCond2 = sRsiCrossOver
longCond3 = close > fastema
longCond4 = strategy.position_size <= 0
longCond = longCond1 and longCond2 and longCond3 and longCond4 and inDateRange

shortCond1 = (fastema < mediumema) and (mediumema < slowema)
shortCond2 = true 
// shortCond2 = sRsiCrossUnder
shortCond3 = close < fastema
shortCond4 = strategy.position_size >= 0
shortCond = shortCond1 and shortCond2 and shortCond3 and shortCond4 and inDateRange

var takeProfit = float(na), var stopLoss = float(na)
if longCond and strategy.position_size <= 0
    takeProfit := close + 4*atr
    stopLoss := close - 1*atr
    // takeProfit := close + 2*atr
    // stopLoss := close - 3*atr

else if shortCond and strategy.position_size >= 0
    takeProfit := close - 4*atr
    stopLoss := close + 1*atr
    // takeProfit := close - 2*atr
    // stopLoss := close + 3*atr
    
// Strategy calls
strategy.entry("3ESRA", strategy.long, comment="Long", when=longCond and strategy.position_size <= 0)
strategy.entry("3ESRA", strategy.short, comment="Short", when=shortCond and strategy.position_size >= 0)
strategy.exit(id="TP-SL", from_entry="3ESRA", limit=takeProfit, stop=stopLoss)
if (not inDateRange)
    strategy.close_all()
    
// Plot EMAs
plot(fastema, color=color.purple, linewidth=2, title="Fast EMA")
plot(mediumema, color=color.teal, linewidth=2, title="Medium EMA")
plot(slowema, color=color.yellow, linewidth=2, title="Slow EMA")
// Plot S-RSI
// plotshape((strategy.position_size > 0) ? na : sRsiCrossOver, title="StochRSI Cross Over", style=shape.triangleup, location=location.belowbar, color=color.teal, text="SRSI", size=size.small)
// Plot trade
bgcolor(strategy.position_size > 0 ? color.new(color.green, 75) : strategy.position_size < 0 ? color.new(color.red,75) : color(na))
// Plot Strategy
plot((strategy.position_size != 0) ? takeProfit : na, style=plot.style_linebr, color=color.green, title="TP")
plot((strategy.position_size != 0) ? stopLoss : na, style=plot.style_linebr, color=color.red, title="SL")



もっと