CCIの平均逆転チャネル戦略

作者: リン・ハーンチャオチャン開催日:2023年11月1日 16時20分45秒
タグ:

img

概要

この戦略は,CCI指標に基づいた柔軟なトレンドフォロー・トレーディングシステムとして設計されています.CCIゼロラインクロスオーバーまたはカスタム上/下帯クロスオーバーに基づいてトレーディング・シグナルを生成できます.この戦略は,固定ストップ・ロストとテイク・プロフィート比率を設定し,特定のタイムフレームで取引し,さらに多くのことを可能にします.

戦略の論理

  1. CCIのゼロラインクロスオーバーを使用して市場動向を決定する.CCIのゼロを超えることは上昇信号であり,以下を超えることは下落信号である.

  2. CCI上位および下位帯をカスタムに設定する.上位帯の上部のCCI横断は上昇し,下位帯下部のCCI横断は下落する.バンドクロスオーバーはストップとして動作する.

  3. 特定のタイムフレームでの取引のみと,それらの期間外のすべてのポジションを閉鎖するオプション.また,固定日々のタイムフレームで取引することができます.

  4. 固定ストップ・ロスを設定し 利益率を設定します

  5. 入口と出口信号の警告メッセージがカスタマイズできます

  6. 調整可能なCCIパラメータ,帯域,ストップなどで高度にカスタマイズ可能な戦略

利点分析

  1. CCIは価格変動に敏感で,トレンド逆転を把握するのに良い.

  2. カスタム帯は,異なる市場のために調整できます.帯のクロスストップはリスクを制御するのに役立ちます.

  3. 特徴に基づいて最適化されたパラメータで異なる時間枠で取引をサポートする.

  4. 固定ストップ損失/取上げ利益 既定リスク/リターン比と制限リスク

  5. 完全にカスタマイズ可能なパラメータは,異なる製品と市場条件のための戦略を最適化します.

リスク分析

  1. CCIは誤った信号に敏感で,より長い時間枠を示す信号を検証すべきです.

  2. 固定ストップ/テイクパーセントは 変化する市場状況に適応できない.

  3. 固定時間枠での取引は,範囲期間中に機会を逃すリスクがあります.

  4. パラメータを頻繁に最適化すると,取引が過剰に取引されるか,取引が欠けている可能性があります.

  5. マクロ要因は考慮されるべきで,最適化だけではリスクを除去するには不十分です.

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

  1. CCI信号の検証のために,より長い時間枠の指標を追加します.

  2. ATR のような動的停止/取出を組み込む.

  3. 異なる時間枠でパラメータをテストし 高効率の期間を見つけます

  4. 市場の変化に合わせてCCIパラメータと帯域を最適化する.

  5. 波動性やボリュームなどの他の要因を考慮してください

  6. 取引される製品に適した時間枠を選択する.

  7. 戦略の最適化を自動化するために 機械学習を考慮してください

概要

一般的には,これは非常に柔軟でカスタマイズ可能なトレンドフォローシステムである.主な利点は,トレンド,リスクを制限するためのカスタムバンド,固定ストップ/テイク,およびタイムフレーム選択のためのCCIを使用することである.誤ったCCI信号や柔軟性のないストップを監視する必要がある.将来の改善は,パラメータを最適化し,シグナルをフィルタリングし,効率的なタイムフレームを選択し,より一貫した過剰収益を達成するために,市場の変化に自動適応するための機械学習を組み込むことから生じる可能性がある.


/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-31 00:00:00
period: 1h
basePeriod: 15m
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/
// © REV0LUTI0N

//@version=4

strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)


//CCI Code

length = input(20, minval=1, title="CCI Length")
src = input(close, title="Source")
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))


// Strategy Backtesting
startDate  = input(timestamp("2099-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true


//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = true
timetoclose = true


//Strategy Settings

//Strategy Settings - Enable Check Boxes
enableentry = input(true, title="Enter First Trade ASAP")
enableconfirmation = input(false, title="Wait For Cross To Enter First Trade")
enablezero =input(true, title="Use CCI Simple Cross Line For Entries & Exits")
enablebands = input(false, title="Use Upper & Lower Bands For Entries & Exits")

//Strategy Settings - Band Sources
ccisource = input(0, title="CCI Simple Cross")
upperbandsource =input(100, title="CCI Enter Long Band")
upperbandexitsource =input(100, title="CCI Exit Long Band")
lowerbandsource =input(-100, title="CCI Enter Short Band")
lowerbandexitsource =input(-100, title="CCI Exit Short Band")

//Strategy Settings - Crosses
simplecrossup = crossover(cci, ccisource)
simplecrossdown = crossunder(cci, ccisource)
uppercrossup = crossover(cci, upperbandsource)
lowercrossdown = crossunder(cci, lowerbandsource)
uppercrossdown = crossunder(cci, upperbandexitsource)
lowercrossup = crossover(cci, lowerbandexitsource)
upperstop = crossunder(cci, upperbandsource)
lowerstop = crossover(cci, lowerbandsource)


// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100

longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)

plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")


// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
    

//Strategy Execution

//Strategy Execution - Simple Line Cross
if (cci > ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (cci < ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

if (simplecrossup and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (simplecrossdown and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Entry
if (uppercrossup and enablebands and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (lowercrossdown and enablebands and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Exit
if strategy.position_size > 0 and uppercrossdown and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowercrossup and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Upper and Lower Band Stops
if strategy.position_size > 0 and upperstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowerstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Close Trade At End Of Time Frame    
if strategy.position_size > 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Stop Loss and Take Profit
if strategy.position_size > 0 and enablesl and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
    
if strategy.position_size > 0 and enabletp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)



もっと