ダイナミックなCCI支援と抵抗戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-22 16時37分46秒
タグ:

img

概要

この戦略は,CCI指標のピボットポイントを使用して動的サポートとレジスタンスレベルを計算し,トレンド判断を組み合わせて買いと売却のシグナルを見つけます.この戦略は,CCIの逆転特性とトレンド追跡能力を統合し,中期トレンドの利益の逆転点を把握します.

戦略原則

CCIインジケーターは,市場が弱すぎるか強すぎるかを示すことができる.80と -80の2つの極端は,市場が過剰購入または過剰販売状態に入っているかどうかを判断するために使用することができる.この戦略はCCIのこの特徴を利用する.左および右50バーのピボットポイントを計算することによって,上下ピボットポイントが得られる.その後,ピボットポイントに基づいてバッファを追加または減算することによって,サポートとレジスタンスラインが動的に構築される.

買い信号は,閉じる値がオープン値よりも高く,上位サポート値よりも低いときに生成される.閉じる値がオープン値よりも低く,低レジスタンス値よりも高くなったとき,売り信号は生成される.主要トレンド方向に対する取引信号をフィルタリングするために,戦略は,現在の主要なトレンド方向を決定するためにEMAと傾斜指標も組み合わせます.トレンドが上昇傾向であると決定された場合にのみロングエントリートレードが行われます.トレンドが下落傾向であると決定された場合にのみショートエントリートレードが行われます.

ストップ・ロースとテイク・プロフィートはATR指標に基づいて動的に計算され,この戦略のリスク管理がより合理的です.

利点分析

  1. CCIの逆転特性を利用し,潜在的な逆転点近くでエントリが行われ,利益の確率が増加します.
  2. トレンド判断と組み合わせることで トレンドに反する取引を避け 損失を減らすことができます
  3. ダイナミックなストップ・ロストと 収益設定により リスク管理がより合理的です
  4. CCI長さ,バッファサイズなど,カスタマイズ可能なパラメータは,より多くの市場環境に適応します.

リスク分析

  1. CCIインジケーターは誤った信号を生成し,傾向判断からフィルターを必要とする.
  2. 逆転は必ずしも成功しないし 損失のリスクもある
  3. パラメータの設定が正しくない場合,過剰な取引や機会の逃れにつながる可能性があります.

パラメータ最適化,ストップ損失範囲の調整などの方法がリスクを軽減するのに役立ちます.また,この戦略は,他の指標のための補助ツールとして使用され,その信号に完全に依存する必要はありません.

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

  1. バッファーのサイズを最適化し,変動が異なる市場に対応する.
  2. ATR 期間パラメータを最適化し,より正確なダイナミックストップ・ロストと利益を取ります.
  3. 異なるCCIパラメータ設定をテストする.
  4. 他のタイプの傾向判断指標の効果をテストする.

結論

この戦略は,CCIからのロング/ショートスクリーニング能力とトレンド判断からのフィルター確認を統合し,一定の実用的な価値を有している.ダイナミックストップ・ロストとテイク・プロフィートは,実際の取引で戦略を適用する際にリスクを制御できるようにする.パラメータ最適化と改善により,より良い結果が期待できる.


/*backtest
start: 2023-12-22 00:00:00
end: 2024-01-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AliSignals


//@version=5
strategy("CCI based support and resistance strategy", overlay=true  )


cci_length = input.int(50, "cci length")
right_pivot = input.int(50, "right pivot")
left_pivot = input.int(50, "left pivot")
buffer = input.float(10.0, "buffer")
trend_matter = input.bool(true, "trend matter?")
showmid = input.bool ( false , "show mid?")
trend_type = input.string("cross","trend type" ,options = ["cross","slope"])
slowma_l = input.int(100, "slow ma length")
fastma_l = input.int(50, "fast ma length")
slope_l = input.int(5,  "slope's length for trend detection")
ksl = input.float(1.1)
ktp = input.float(2.2)
restf = input.timeframe(title="Time Frame of Last Period for Calculating max" , defval="D")



// Calculating Upper and Lower CCI
cci = ta.cci(hlc3,cci_length)

uppercci = 0.0
lowercci = 0.0

uppercci := fixnan(ta.pivothigh(cci, left_pivot, right_pivot)) - buffer
lowercci := fixnan(ta.pivotlow (cci, left_pivot, right_pivot)) + buffer
midccci  = math.avg(uppercci,lowercci)


// Support and Resistance based on CCI
res = uppercci*(0.015*ta.dev(hlc3,cci_length))+ ta.sma(hlc3,cci_length)
sup = lowercci*(0.015*ta.dev(hlc3,cci_length))+ ta.sma(hlc3,cci_length)
mid =  midccci*(0.015*ta.dev(hlc3,cci_length))+ ta.sma(hlc3,cci_length)



// Calculating trend
t_cross  = 0
t_cross := ta.ema(close,fastma_l) > ta.ema(close,slowma_l) ? 1 : ta.ema(close,fastma_l) < ta.ema(close,slowma_l) ? -1 : t_cross[1] 

t_slope  = 0
t_slope := ta.ema(close,slowma_l) > ta.ema(close,slowma_l)[slope_l] ? 1 : ta.ema(close,slowma_l) < ta.ema(close,slowma_l)[slope_l]  ? -1 : t_slope[1] 

t  = 0
t := trend_type == "cross" ? t_cross : trend_type == "slope" ? t_slope : na

colort =  trend_matter == false ? color.rgb(201, 251, 0) : t == 1 ? color.rgb(14, 243, 132) :  t == -1 ? color.rgb(255, 34, 34) : na
bull_t = trend_matter == false or t ==  1
bear_t = trend_matter == false or t == -1

plot(res, color = colort)
plot(sup, color = colort)
plot(showmid == true ? mid : na)


// Long and Short enter condition
buy  = bull_t == 1 and ta.lowest (2) < sup and close > open and close > sup
sell = bear_t == 1 and ta.highest(2) > res and close < open and close < res

plotshape( buy , color=color.rgb(6, 255, 23) , location = location.belowbar, style = shape.triangleup  , size = size.normal)
plotshape( sell, color=color.rgb(234, 4, 4) ,  location = location.abovebar, style = shape.triangledown, size = size.normal)





atr = ta.atr(100)



CLOSE=request.security(syminfo.tickerid, restf, close)
max = 0.0
max := CLOSE == CLOSE[1] ? math.max(max[1], atr) : atr
act_atr = 0.0
act_atr := CLOSE == CLOSE[1] ? act_atr[1] : max[1]

atr1 =  math.max(act_atr, atr) 

dis_sl = atr1 * ksl
dis_tp = atr1 * ktp


var float longsl  = open[1] - dis_sl
var float shortsl = open[1] + dis_sl
var float longtp =   open[1] + dis_tp
var float shorttp =  open[1] - dis_tp


longCondition = buy
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = sell
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)


longsl  := strategy.position_size > 0  ? longsl[1]  : close - dis_sl
shortsl := strategy.position_size < 0 ? shortsl[1] : close + dis_sl
longtp  := strategy.position_size > 0  ? longtp[1]  : close + dis_tp
shorttp := strategy.position_size < 0 ? shorttp[1] : close - dis_tp




if strategy.position_size > 0 
    strategy.exit(id="My Long close Id", from_entry ="My Long Entry Id" , stop=longsl, limit=longtp)
if strategy.position_size < 0 
    strategy.exit(id="My Short close Id", from_entry ="My Short Entry Id" , stop=shortsl, limit=shorttp)



もっと