双重MACDストックRSI取引戦略

作者: リン・ハーンチャオチャン開催日:2023年9月22日16時55分55秒
タグ:

概要

この戦略は,二重MACD指標とStockRSIオシレーターを組み合わせて取引信号を提示する.二重MACDは,速い効果と遅い効果のために異なるパラメータを使用し,StockRSIはモメントディバージェンスを確認する.トレンドフィルターとストップロスはリスク管理にも追加される.

戦略の論理

取引シグナルは,以下の点に基づいています.

  • ダブルMACD:FastMACDは短回顧期間を使用し,SlowMACDはスムージング効果のために長い回顧期間を使用します.

  • StochRSI: RSIの高低範囲を計算し,過買い/過売りのRSI値を特定する.

入場規則:

  • ロング:速いMACDがゼロ線を超越し,遅いMACDがゼロ線を超越する.ストックRSIは過売れ,KはDを超越する.上昇傾向にある.

  • 短:速いMACDがゼロ線以下に突破し,遅いMACDがゼロ線以下に突破.ストックRSIは過買いで,KはD以下に突破する.ダウントレンド.

利点

  • 二重MACDは,より高い信号品質のために偽のブレイクを回避します.

  • StochRSIは,追いかけるのを避けるために,過剰購入/過剰販売レベルを特定します.

  • 逆動向損失を減らすため,全体的な動向方向を考慮する.

  • クロスタイムフレームの検証は信号の有効性を向上させる.

  • ストップ損失はリスクを制御します

リスク

  • MACDは誤った信号を受けやすいので 検証が必要です

  • ストックRSIのパラメータが悪ければ 取引が失敗する可能性があります

  • ストップ・ロスのレベルは,保守的すぎたり,攻撃的すぎたりする可能性があります.

  • ダイナミックストップの位置管理が欠けています

改善:

  1. ボリュームやMA傾きのようなフィルターを追加します

  2. オプティマイズしたり,他の振動器を追加したりする.

  3. ダイナミックストップ損失追跡

  4. 性能に基づいて位置サイズを追加します

最適化

最適化すべき主な分野:

  1. インディケーターのパラメータを最適化

  2. 偽信号を削除するフィルターを追加します.

  3. ダイナミックな追跡のために停止を最適化します.

  4. 戦略の業績に基づいて ポジションサイズを組み込む.

  5. 自動最適化のための機械学習を追加します

概要

この戦略は,より強い信号のために複数の指標を組み合わせているが,不要な取引を削減し収益性を向上させるためにパラメータ,フィルタリング,ダイナミックストップの最適化が必要である.全体的には,論理は良好で最適化可能性が高い.


/*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 
// rjmarti2@millersville.edu


もっと