この戦略は,双MACD指数とランダムな指数StochRSIを組み合わせて取引信号判断を行う.双MACDは,異なるパラメータ設定を使用して,快慢効果を実現し,StochRSIは,強さの背面検証に使用される.戦略はまた,トレンド判断とストップ条件の制御リスクを追加する.
この戦略の取引シグナル判断は以下の指標に基づいています.
二重MACD:高速MACDは短周期パラメータを採用し,遅いMACDは長周期パラメータを採用し,異なる滑り効果を実現する.
StochRSI: RSIが超買い超売り状態にあるかどうかを判断するために,一定の周期内のRSIの最高低値を計算します.
取引信号の判断のルール:
オーバー: 速いMACDでゼロ軸を横切る 遅いMACDでゼロ軸を横切る ストックRSIは超売り状態で,K線でD線を横切る,上昇傾向にある.
空白: 急速MACDはゼロ軸下を通過し,遅いMACDはゼロ軸下を通過し,StochRSIは超買い状態で,K線下を通過し,D線下を通過し,下降傾向にある.
ダブルMACD検証は偽突破を回避し,信号品質を向上させる.
ストックRSIは超買いと超売れを判断し,落下を回避した.
逆の取引の損失を減らすために,大トレンドの方向を考慮してください.
信号の有効性を向上させるため,指標の多時間枠検証を実現する.
ストップ・ロスの条件を設定し,リスクを制御する.
MACDは偽信号を発生しやすいため,さらにフィルタリングの検証が必要である.
StochRSIのパラメータを誤って設定すると,取引機会が逃れることがあります.
ストップポイントの設定は不合理で,保守的または過激すぎる可能性があります.
持仓管理戦略がなく,動的停止ができない.
改善の方法は以下の通りです.
フィルター条件は,取引量または均線角の増加などです.
StochRSIパラメータを最適化するか,他のランダムな指標を導入する.
動的にストップポイントを調整し,ストップを追跡する.
ポジション管理モジュールを追加し,戦略のパフォーマンスに応じてポジションを動的に調整します.
この戦略の主な最適化方向は
指標のパラメータを最適化し,指標の効果を向上させる.
フィルタリング条件を追加し,偽信号をフィルターします.
ストップ・ローズ戦略を最適化し,ダイナミック・ストップ・ローズを実現する.
ポジション管理を導入し,戦略効果に応じてポジションを調整する.
機械学習モジュールを追加し,ビッグデータを活用して自動最適化を行う.
この戦略は,多種多様な指標を総合的に考慮して,より強い取引信号を形成する.しかし,依然として,パラメータ設定を最適化し,不要な取引を減らすために,利得の確率を高めるために,信号や動的停止などの側面をさらにフィルタリングする必要がある.全体的に戦略の考え方は合理的で,優れた最適化スペースがある.
/*backtest
start: 2023-09-14 00:00:00
end: 2023-09-21 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//This strategy is an ongoing work in progress. Last updated 8/6/16.
//Feel free to modify it as you see fit, if you do borrow code then send me a link so I
//can see and maybe borrow some of your code to improve this.
//Thanks to ChrisMoody who I stole the code for setting custom resolution from.
//
//more info in comments at end of script
strategy("MACDouble & StochRSI w/ safeties v0.3", overlay=true)
source = close
useCurrentRes = input(true, title="Uncheck to use custom res./intrv. for 2nd MACD indicator")
resCustom = input(title="Resolution/interval to use for 2nd MACD:", defval="45")
res = useCurrentRes ? timeframe.period : resCustom
useCurrentRes2 = input(true, title="Uncheck to use custom res/intrv for StochRSI")
resCustom2 = input(title="Resolution to use for StochRSI indicator:", defval="45")
res2 = useCurrentRes2 ? timeframe.period : resCustom2
//MACD1
fastLength = input(10, title="MACD fast length")
slowlength = input(21, title="MACD slow length")
sigLength = input(9, title="MACD signal length")
MACD = ema(source, fastLength) - ema(source, slowlength)
signal = sma(MACD, sigLength)
delta = MACD - signal
//MACD2
fastLength2 = input(31, title= "2nd MACD fast length")
slowlength2 = input(63, title= "2nd MACD slow length")
sigLength2 = input(30, title= "2nd MACD signal length")
MACD2 = ema(source, fastLength2) - ema(source, slowlength2)
signal2 = sma(MACD2, sigLength2)
delta2 = MACD2 - signal2
MACDRes = security(syminfo.tickerid, res, MACD2)
signalRes = security(syminfo.tickerid,res, signal2)
deltaRes = security(syminfo.tickerid, res, delta2)
uptrend = (close + high)/(close[1] + high[2])
downtrend = (close + low)/(close[1] + low[2])
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(11, minval=1)
lengthStoch = input(11, minval=1)
src = close
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
RSI_buyTrig = input(90)
RSI_sellTrig = input(20)
kRes = security(syminfo.tickerid, res2, k)
dRes = security(syminfo.tickerid, res2, d)
if (delta > 0) and (year>2012) and (deltaRes > 0) and (uptrend > 1) and ( kRes and dRes < RSI_buyTrig) and (kRes > dRes)
strategy.entry("buy", strategy.long, comment="buy")
if (delta < 0) and (year>2012) and (deltaRes < 0) and (downtrend < 1) and ( kRes and dRes > RSI_sellTrig) and (kRes < dRes)
strategy.entry("sell", strategy.short, comment="sell")
strategy.exit("sell", loss = 9000)
// RELEASE NOTES, ETC
//
// The core starting idea for this backtesting script came from the desire to have two traditional
//MACD indicators: one 'fast' and one 'slow'. The slow one is to pretty much smooth out noisy signals
//so that short term changes in price are ignored (ideally).
// A brief version history
// v0.1 - Basic two MACD indicators script
// v0.2 - Added StochRSI indicator
// v0.21- Added primitive uptrend/downtrend safety condition
// v0.22- Added changable time resolution for MACDslow
// v0.23- Added exit safeties conditional on loss threshold
// v0.3 - Added changeable resolution for StochRSI
// Future changes planned for next release:
// -Fine tuning exit safeties
// -Major overhaul of trade logic/triggers (may be forked as a different script)
//
//I am more than happy to discuss any difficulties you are having, questions about the script, or improvement suggestions.
//I am not a coder and my background is actually in economics, so feel free to debug ;)
//Feel free to tip me on the indcluded bitcoin address on TV as well
// tradingview.com/u/RyanMartin
// [email protected]