
この策略は,トレンド追跡策略であり,トリプルインデックス移動平均指標とランダムインデックス平移平均指標を組み合わせて取引信号を生成する. 急速移動平均線上を通過すると,中速移動平均線上を通過すると,中速移動平均線上を通過すると,中速移動平均線下を通過すると,中速移動平均線下を通過すると,空を見ます. この策略は,ランダムインデックス平移平均指標を判断補助指標として導入する.
8日,14日,50日三重指数移動平均を使用する。 8日指数移動平均の上に14日指数移動平均を穿越すると,14日指数移動平均の上に50日指数移動平均を穿越すると多見信号が生じ,逆に,空見信号。
ランダム指数平滑移動平均指数 ((Stochastic RSI) を使用して補助判断指数とする.具体的には,まず14日RSIを計算し,次にRSIの基礎でストキャスティック指数を再計算し,最後にストキャスティック指数に3日単行移動平均を計算してK線と3日単行移動平均をD線を得る.K線にD線を通るとき,多くの補助信号として参照する.
取引シグナルを生成する際,価格が8日指数移動平均より高い場合は,入場を多めにする.価格が8日指数移動平均より低い場合は,入場を空っぽにする.
止損は入場価格の1倍ATRの距離より下/上にある. 止損は入場価格の4倍ATRの距離より上/下にある.
移動平均は基礎指標として,市場動向を効果的に追跡することができる.三重指数移動平均は,複数の周期を組み合わせて使用することで,短期および中長期の傾向に対して同時に敏感性を保証することができる.
ストキャスティックRSIを追加して,偽信号をフィルターして,入場の正確性を向上させる.
ATRに基づいてストップ・ストップの位置を設定することで,市場の変動の程度を動的に追跡でき,ストップ・ストップの大きすぎたり小さすぎたりを避ける.
この戦略のパラメータ設定は合理的で,大トレンド下では優れたパフォーマンスを発揮する. 引き下がりは小さい,収益は平坦で,長線操作に適している.
多指数組み合わせ戦略は反転のリスクを高めます. 移動平均とストキャスティックRSIが反対の信号を発信すると,取引信号の誤りが発生する可能性があります. この場合は,価格自体の傾向性に注意する必要があります.
ストップとストップの設定は比較的保守的で,市場情勢が激しく波動する時に突破され,トレンドの機会を逃してストップされる可能性がある.このとき,ATRパラメータを適切に調整したり,ストップストップの倍数を大きくしたりすることができる.
三重移動平均を使用しているため,高速線と中高速線が反転するときは,一定の遅延が発生する.このとき,入場かどうかを決定するために価格自体が反転しているかどうかを注目する必要がある.
この策略は,主にトレンド性情勢に適しており,整合情勢ではうまく機能しない.この場合,移動平均の周期パラメータを最適化するか,他の判定指標を使用することを考慮することができる.
MACDなどの他の指標を追加することで,入場時間をさらに最適化することも考えられます.また,異なるパラメータの移動平均の組み合わせをテストすることもできます.
ATR多空検査のパラメータを最適化することができる.例えば,ストップを1ATRから1.5ATRに,ストップを4ATRから3ATRに調整して,よりよい収益が得られるかどうかを見る.
移動平均だけを使ってテストし,ストキャスティックRSIを削除して,より多くのノイズをフィルターして,より安定した利益を得ることができるかどうか確認できます.
トレンドを判断するための条件をさらに追加することも考えられます.例えば,取引量指数を増やして,大レベルのトレンドで操作することを保証します.
この戦略は,トリプルインデックス移動平均とストキャスティックRSIの指標を総合的に使用してトレンドの方向性を判断する.入場信号はより厳格で,無意味な取引を効果的に減らすことができる.ストップ・ストップ・ロスの設定は,動的にATRを追跡し,戦略のパラメータを自律的に適応させる.裏返し結果からすると,この戦略は,トレンドの状況で優れている,リタークは小さい,収益は平らである.さらなる最適化により,よりよい効果が期待される.
/*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")