PSAR,MACDおよびRSIをベースとした多時間枠量的な取引戦略

作者: リン・ハーンチャオチャン開催日:2023年12月27日 16:12:57
タグ:

img

概要

この戦略は,パラボリックSAR,MACDおよびRSI指標を組み合わせて,複数のタイムフレームにわたって自動化されたロングおよびショート取引を実施します. 主に株式および商品の日中取引に適しています.

戦略原則

  1. PSAR インディケーターは,価格の方向性とトレンド逆転点を決定するために使用されます. 落ちる点は上昇する点が下落する信号で,上昇する点は下落する信号です.

  2. MACD指標は価格の勢いを判断します.SIGNAL線を上向きに横切るMACD線は上昇信号で,下向きに横切るのは下向きです.

  3. RSIインジケーターは過買い・過売状態を判断します. 限界以上のRSIは上昇傾向で,その下のRSIは下落傾向です.

  4. 上記3つの指標からの信号を組み合わせて最終的な長/短の決定をします.

  5. 適応的に Chop インデックス インディケーターを使用して 統合市場をフィルタリングします

  6. 逆ピラミッド型ポジションサイズを使用して,リスクと利益の目標を動的に管理する.

利点

  1. トレンド,モメント,オシレーターを判断する複数の指標の組み合わせにより 精度は向上します

  2. 市場条件に適応して 市場を統合するフィルタをフィルタリングすることで 罠に引っかかることを防ぐのです

  3. ダイナミックなリスクと利益管理 逆ピラミッド型ポジションサイズ化 適応型ストップとリーミット

  4. 異なる製品や市場環境に合わせて 調整可能なパラメータを備えた高度なカスタマイズ可能性

  5. 複数のタイムフレームをサポートし,短期的な日中取引や中期・長期のポジション取引に柔軟性があります.

リスク分析

  1. 長/短の決定はパラメータ設定に依存し,不適切な場合はエラーを引き起こす可能性があります.

  2. 傾向に反する決定につながる誤った信号の可能性

  3. 不適切なストップ・ロースと得益設定は,損失を増やしたり,利益を下げたりする可能性があります.

  4. 頻繁なモニタリングとパラメータ調整が必要で 人工介入コストが高くなります

オプティマイゼーションの方向性

  1. パラメータ設定と信号の有効性を評価するためのモデル検証モジュールを追加する.

  2. 自動パラメータとモデル最適化のための機械学習モジュールを増やす

  3. 機能空間を豊かにし 意思決定を改善するために より多くのデータ源を摂取します

  4. 人工介入を減らすための自動的な監視と保守システムを開発する.

  5. バックテストとシミュレーションの評価を追加して 戦略のパフォーマンスを検証します

結論

この戦略は,複数の技術指標のルールベースのシステムを組み合わせて自動化された定量取引を実現する.大きな最適化スペースと柔軟性により,パラメータチューニング,機能拡張,機械学習の強化に適しています.


/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vikris

//@version=4
strategy("[VJ]Phoenix Force of PSAR +MACD +RSI", overlay=true, calc_on_every_tick = false,pyramiding=0)

// ********** Strategy inputs - Start **********

// Used for intraday handling
// Session value should be from market start to the time you want to square-off 
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session, 
     defval="0915-1455", confirm=true)

// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01

shortProfitPerc = input(title="Short Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01
     
// Set stop loss level with input options (optional)
longLossPerc = input(title="Long Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01

shortLossPerc = input(title="Short Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01    


// ********** Strategy inputs - End **********


// ********** Supporting functions - Start **********

// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0



// Figure out take profit price
longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)

// Determine stop loss price
longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)


// ********** Supporting functions - End **********


// ********** Strategy - Start **********
// See if intraday session is active
bool intradaySession = barInSession(i_marketSession)

// Trade only if intraday session is active

//=================Strategy logic goes in here===========================
 
psar = sar(0.02,0.02,0.2)
c1a = close > psar
c1v = close < psar

malen = input(50, title="MA Length")
mm200 = sma(close, malen)
c2a = close > mm200
c2v = close < mm200

fast = input(12, title="MACD Fast EMA Length")
slow = input(26, title="MACD Slow EMA Length")
[macd,signal,hist] = macd(close, fast,slow, 9)
c3a = macd >= 0
c3v = macd <= 0

rsilen = input(7, title="RSI Length")
th = input(50, title="RSI Threshold")
rsi14 = rsi(close, rsilen)
c4a = rsi14 >= th
c4v = rsi14 <= th

chopi = input(7, title="Chop Index lenght")
ci = 100 * log10(sum(atr(1), chopi) / (highest(chopi) - lowest(chopi))) / log10(chopi)

buy = c1a and c2a and c3a and c4a ? 1 : 0
sell = c1v and c2v and c3v and c4v ? -1 : 0


//Final Long/Short Condition
longCondition = buy==1 and ci <50
shortCondition = sell==-1 and ci <50 
 
//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
    stop_level = longStopPrice
    profit_level = longExitPrice
    strategy.entry("My Long Entry Id", strategy.long)
    strategy.exit("TP/SL", "My Long Entry Id", stop=stop_level, limit=profit_level)


//Short Strategy - sell condition and exits with Take profit and SL
if (shortCondition and intradaySession)
    stop_level = shortStopPrice
    profit_level = shortExitPrice
    strategy.entry("My Short Entry Id", strategy.short)
    strategy.exit("TP/SL", "My Short Entry Id", stop=stop_level, limit=profit_level)
 
 
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")

// ********** Strategy - End **********

もっと