SPARK ダイナミック・ポジション・サイジングとダブル・インディケーター・トレーディング・戦略

作者: リン・ハーンチャオチャン,日付: 2024-04-12 17時22分47秒
タグ:スーパートレンドRSIATR

img

概要

SPARK戦略は,ダイナミックなポジションサイジングとデュアルインジケーター確認を組み合わせた定量的な取引戦略である.この戦略は,潜在的なエントリーとアウトプットポイントを特定するためにスーパートレンド指標と相対強度指数 (RSI) を利用し,資本配分を最適化するためにダイナミックなポジションサイジングメカニズムを使用している.この戦略は柔軟な利益とストップ損失設定,最低取引頻度や方向性偏好などのカスタマイズ可能なパラメータも提供している.

戦略の原則

SPARK戦略の核心は,スーパートレンド指標とRSI指標の組み合わせによる応用にあります.スーパートレンド指標は,閉値と動的サポートとレジスタンスレベルを比較することによってトレンド方向を決定し,RSI指標は,過剰購入と過剰販売の市場状況を特定するために使用されます.スーパートレンド指標とRSI指標の両方が同時に特定の基準を満たしたとき,戦略はエントリー信号を生成します.

この戦略は,各取引の資本配分を最適化するために動的なポジションサイズメカニズムを使用している.ポートフォリオの割合とレバレッジ比率を設定することにより,戦略は現在の市場状況と口座残高に基づいて最適なポジションサイズを自動的に計算する.また,この戦略は柔軟な利益とストップ損失設定を提供し,ユーザーは固定パーセントまたは動的に計算されたレベルの中から選択することができます.

戦略 の 利点

  1. 2つの指標の確認:スーパートレンドとRSIの指標を組み合わせることで,SPARK戦略は潜在的なエントリーとアウトプット点をより正確に特定し,誤った信号の確率を減らすことができます.
  2. ダイナミック・ポジション・サイジング: この戦略は,ポートフォリオの割合とレバレッジ比に基づいて,各取引に対して資本配分を自動的に最適化するダイナミック・ポジション・サイジングメカニズムを使用し,資本効率を向上させる.
  3. 柔軟なリスクマネジメント: 戦略は柔軟な利益とストップロスの設定を提供し,ユーザーはリスクの優先順位に基づいて固定パーセントまたは動的に計算されたレベルから選択することができ,正確なリスク管理が可能になります.
  4. カスタマイズ可能なパラメータ:この戦略は,ユーザーが異なる市場状況と取引好みに適応するために,ATR長,倍数,RSIの値などの複数の入力パラメータを調整できるようにします.

戦略リスク

  1. 市場リスク:SPARK戦略の2つの指標の確認と動的ポジションサイズメカニズムにもかかわらず,極端な市場状況下では損失のリスクに直面することがあります.
  2. パラメータ最適化リスク: 戦略のパフォーマンスは,インプットパラメータの選択に大きく依存する.不適切なパラメータ設定は,戦略のパフォーマンスが不最適になる可能性があります.
  3. 過剰に適したリスク:戦略パラメータが過剰に最適化されれば,将来の市場条件下では不良な業績をもたらす可能性があります.

戦略の最適化方向

  1. 追加指標の導入:信号確認の精度をさらに高めるため,MACD,ボリンジャー帯など他の技術指標の導入を検討する.
  2. 利得とストップ損失のメカニズムの最適化: より高度な利得とストップ損失の戦略,例えばトライリングストップ,ダイナミック・テイク・プロフィートレベルなどを探索し,利益をより良く保護し損失を制限する.
  3. 適応性パラメータ調整: 絶えず変化する市場環境に適応するために,市場状況に基づいて戦略パラメータを動的に調整する適応性メカニズムを開発する.

概要

SPARK戦略は,スーパートレンドとRSI指標を組み合わせ,ダイナミックなポジションサイズメカニズムを採用し,柔軟なリスク管理ツールを提供することで,トレーダーに包括的な定量的な取引ソリューションを提供します. 戦略は一定のリスクに直面する可能性がありますが,継続的な最適化と精製により,SPARK戦略は,さまざまな市場条件で一貫したパフォーマンスを提供する可能性があります.


/*backtest
start: 2024-03-12 00:00:00
end: 2024-04-11 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("SPARK", shorttitle="SPARK", overlay=true)

// Choose whether to activate the minimal bars in trade feature
minBarsEnabled = input(true, title="Activate Minimal Bars in Trade")
portfolioPercentage = input(10, title="Portfolio Percentage", minval=1, maxval=100)
// Leverage Input
leverage = input(1, title="Leverage", minval=1)

// Calculate position size according to portfolio percentage and leverage
positionSizePercent = portfolioPercentage / 100 * leverage
positionSize = (strategy.initial_capital / close) * positionSizePercent

// Take Profit and Stop Loss settings
useFixedTPSL = input(1, title="Use Fixed TP/SL", options=[1, 0])
tp_sl_step = 0.1
fixedTP = input(2.0, title="Fixed Take Profit (%)", step=tp_sl_step)
fixedSL = input(1.0, title="Fixed Stop Loss (%)", step=tp_sl_step)

// Calculate Take Profit and Stop Loss Levels
takeProfitLong = close * (1 + fixedTP / 100)
takeProfitShort = close * (1 - fixedTP / 100)
stopLossLong = close * (1 - fixedSL / 100)
stopLossShort = close * (1 + fixedSL / 100)

// Plot TP and SL levels on the chart
plotshape(series=takeProfitLong, title="Take Profit Long", color=color.green, style=shape.triangleup, location=location.abovebar)
plotshape(series=takeProfitShort, title="Take Profit Short", color=color.red, style=shape.triangledown, location=location.belowbar)
plotshape(series=stopLossLong, title="Stop Loss Long", color=color.red, style=shape.triangleup, location=location.abovebar)
plotshape(series=stopLossShort, title="Stop Loss Short", color=color.green, style=shape.triangledown, location=location.belowbar)

// Minimum Bars Between Trades Input
minBarsBetweenTrades = input(5, title="Minimum Bars Between Trades")

// Inputs for selecting trading direction
tradingDirection = input("Both", "Choose Trading Direction", options=["Long", "Short", "Both"])

// SuperTrend Function
trendFlow(src, atrLength, multiplier) =>
    atr = atr(atrLength)
    up = hl2 - (multiplier * atr)
    dn = hl2 + (multiplier * atr)
    trend = 1
    trend := nz(trend[1], 1)
    up := src > nz(up[1], 0) and src[1] > nz(up[1], 0) ? max(up, nz(up[1], 0)) : up
    dn := src < nz(dn[1], 0) and src[1] < nz(dn[1], 0) ? min(dn, nz(dn[1], 0)) : dn
    trend := src > nz(dn[1], 0) ? 1 : src < nz(up[1], 0)? -1 : nz(trend[1], 1)
    [up, dn, trend]

// Inputs for SuperTrend settings
atrLength1 = input(7, title="ATR Length for Trend 1")
multiplier1 = input(4.0, title="Multiplier for Trend 1")
atrLength2 = input(14, title="ATR Length for Trend 2")
multiplier2 = input(3.618, title="Multiplier for Trend 2")
atrLength3 = input(21, title="ATR Length for Trend 3")
multiplier3 = input(3.5, title="Multiplier for Trend 3")
atrLength4 = input(28, title="ATR Length for Trend 4")
multiplier4 = input(3.382, title="Multiplier for Trend 4")

// Calculate SuperTrend
[up1, dn1, trend1] = trendFlow(close, atrLength1, multiplier1)
[up2, dn2, trend2] = trendFlow(close, atrLength2, multiplier2)
[up3, dn3, trend3] = trendFlow(close, atrLength3, multiplier3)
[up4, dn4, trend4] = trendFlow(close, atrLength4, multiplier4)

// Entry Conditions based on SuperTrend and Elliott Wave-like patterns
longCondition = trend1 == 1 and trend2 == 1 and trend3 == 1 and trend4 == 1
shortCondition = trend1 == -1 and trend2 == -1 and trend3 == -1 and trend4 == -1

// Calculate bars since last trade
barsSinceLastTrade = barssince(tradingDirection == "Long" ? longCondition : shortCondition)

// Strategy Entry logic based on selected trading direction and minimum bars between trades
if tradingDirection == "Long" or tradingDirection == "Both"
    if longCondition and (not minBarsEnabled or barsSinceLastTrade >= minBarsBetweenTrades)
        strategy.entry("Long", strategy.long, qty=positionSize)
        strategy.exit("TP/SL Long", from_entry="Long", stop=stopLossLong, limit=takeProfitLong)

if tradingDirection == "Short" or tradingDirection == "Both"
    if shortCondition and (not minBarsEnabled or barsSinceLastTrade >= minBarsBetweenTrades)
        strategy.entry("Short", strategy.short, qty=positionSize)
        strategy.exit("TP/SL Short", from_entry="Short", stop=stopLossShort, limit=takeProfitShort)

// Color bars based on position
var color barColor = na
barColor := strategy.position_size > 0 ? color.green : strategy.position_size < 0 ? color.red : na

// Plot colored bars
plotcandle(open, high, low, close, color=barColor)

// Plot moving averages
plot(sma(close, 50), color=color.blue)
plot(sma(close, 200), color=color.orange)

// More customizable trading bot - adding a new indicator
// This indicator is the RSI (Relative Strength Index)

// RSI Inputs
rsi_length = input(14, title="RSI Length")
rsi_oversold = input(30, title="RSI Oversold")
rsi_overbought = input(70, title="RSI Overbought")

// Calculate RSI
rsi = rsi(close, rsi_length)

// Plot RSI
plot(rsi, color=color.purple, title="RSI")

// Entry Conditions based on RSI
rsi_long_condition = rsi < rsi_oversold
rsi_short_condition = rsi > rsi_overbought

// Strategy Entry logic based on RSI
if tradingDirection == "Long" or tradingDirection == "Both"
    if rsi_long_condition and (not minBarsEnabled or barsSinceLastTrade >= minBarsBetweenTrades)
        strategy.entry("Long_RSI", strategy.long, qty=positionSize)
        strategy.exit("TP/SL Long_RSI", from_entry="Long_RSI", stop=stopLossLong, limit=takeProfitLong)

if tradingDirection == "Short" or tradingDirection == "Both"
    if rsi_short_condition and (not minBarsEnabled or barsSinceLastTrade >= minBarsBetweenTrades)
        strategy.entry("Short_RSI", strategy.short, qty=positionSize)
        strategy.exit("TP/SL Short_RSI", from_entry="Short_RSI", stop=stopLossShort, limit=takeProfitShort)


関連性

もっと