リアルタイムの金価格変動検出とリスク管理戦略のための複数のテクニカル指標

MA EMA ATR STC HEIKIN ASHI CHANDELIER EXIT supertrend RMA VWMA WMA HMA
作成日: 2025-03-05 10:35:15 最終変更日: 2025-03-05 10:35:15
コピー: 4 クリック数: 548
2
フォロー
319
フォロワー

リアルタイムの金価格変動検出とリスク管理戦略のための複数のテクニカル指標 リアルタイムの金価格変動検出とリスク管理戦略のための複数のテクニカル指標

戦略概要

複数の技術指標の黄金の即時変化検知とリスク管理戦略は,1分間のヘイキン・アシ・チャートに基づく金取引システムで,複数の技術指標を取引信号と確認ツールとして組み合わせている.この戦略は,主に台風出口 ((Chandelier Exit) を主導指標として使用し,選択的にEMAフィルター,スーパートレンド ((SuperTrend)) と砂のトレンド周期 ((Schaff Trend Cycle)) などの指標を確認ツールとして組み合わせている.この戦略は,柔軟なストップ・ストップ・ストーピングの仕組みを採用し,直観的な取引メーターボードを提供し,トレーダーが取引状態をリアルタイムで監視できるようにする.この多次元的な技術分析方法は,金価格の短期変動を迅速に捉え,偽信号のリスクを低減するために,指標システムによって確認することを目的としています.

戦略原則

この戦略は,多層の信号確認システムに基づいている. 核心的な論理は以下の通りである.

  1. 主導指標信号生成策略 台出口を主導する指標.台出口は,トレンド追跡指標で,ATR (平均リアルレンジ) の倍数を用いてストップポジションを決定し,多頭と空頭信号を生成する.

  2. フィルタリングを確認: 策略は,トレーダーに選択的に複数の確認指標を有効にします.

    • EMAフィルター:価格が指定されたEMAラインの上 ((多頭) または下 ((空頭) に位置する必要があります.
    • スーパートレンド (SuperTrend): 主導信号の方向と一致する
    • シェフトレンド周期 (STC):上限 (多頭) よりも高く,下限 (空頭) よりも低くする必要があります.
  3. 信号の切断メカニズム: 策略は,信号の有効数を設定して,古い信号で取引を防ぐために,信号の期限切れ機能を実装している.

  4. トランザクション実行論理: すべての選択条件が満たされたとき,戦略は入場信号を生成し,自動的に固定ポイントのストップストロスを設定する.

  5. データ処理の最適化: 策略 使用条件サンプリングEMAとSMA関数,および専用範囲フィルターにより,技術指標の計算効率が向上する.

  6. 視覚化システム: 各指数の状態を表示する取引表盤を提供し,取引信号とストップ・ロスの位置をグラフにマークします.

戦略的優位性

  1. 複数の認証メカニズム:複数の指標の確認により,偽信号を大幅に削減し,取引の正確性を向上させる.複数の指標が共同で1つの方向を確認するときに,取引の信号はより信頼性が高くなる.

  2. 柔軟な指標の組み合わせ: ユーザーは,さまざまな確認指標を有効または無効に選択し,異なる市場条件に応じて戦略のパフォーマンスをカスタマイズすることができます.

  3. リスクの管理: 戦略は,ユーザが特定のストップ・ストロップ・ポイントを設定することを許可し,各取引のリスク・リターン比率を精密に制御する.

  4. 信号の過時制御: 信号の有効期限を設定することで,期限切れの信号で取引を避ける戦略,遅滞のリスクを減らす.

  5. 高可視化取引インターフェース取引表は,すべての指標の状態を直視的に表示し,トレーダーが市場状況を迅速に評価するのを助けます.

  6. 黄金の市場を最適化する戦略: 黄金市場の特性を考慮してパラメータを最適化し,特にポイント換算 ((1ポイント=0.1ドル) を考慮した.

  7. 高周波取引の適応性1分間の周期は,短期的な価格変動を捕捉する戦略を可能にし,日中のトレーダーに適しています.

戦略リスク

  1. 過剰取引のリスク: 1分周期は,取引コストの増加と過剰取引につながる過剰取引信号を生成する可能性があります. 解決方法は,確認指標の数を調整するか,信号フィルタリング条件を増やすことです.

  2. 市場騒音の影響低時間周期は,市場騒音に干渉されやすく,偽信号を生じます. 高い変動期間の間に慎重に使用することをお勧めします. または,より長い周期との組み合わせでトレンドを確認してください.

  3. 累積された指標の遅れ複数の指標の確認は偽信号を減少させるが,システムの遅延を増加させ,収益の機会の一部を逃す可能性がある. 応答のスピードを向上させるために確認指標の数を減らすことを検討することができます.

  4. 固定ストップストップの限界: 固定ポイントのストップ・ストロップは市場の変動を考慮していない.高波動期にはストップが近すぎ,低波動期にはストップが遠すぎになる可能性がある.現在のATRの動向に応じてストップ・ストロップ値を調整することが推奨されている.

  5. 黄金市場における特殊なリスク金市場は,インフレデータ,中央銀行政策,地政学など,複数のマクロ経済要因の影響を受け,純粋な技術分析ではこれらの影響が無視されることがあります. 基本的分析と組み合わせて使用することが推奨されています.

  6. 主要指標依存性: 戦略は,台輸出を主導指標として過度に依存しており,この指標は区間市場では不良な結果をもたらす可能性がある.複数の主導指標を選択するオプションを追加することを提案する.

戦略最適化の方向性

  1. 主要な指標は多様化です:現在の戦略は,主導指標として台風輸出のみをサポートしており,異なる市場環境に対応するために,ブリン帯,MACD,または自主移動平均などの複数の主導指標オプションをサポートすることを拡張できます.

  2. ダイナミックストップストップ: 固定ポイント数ストップをATRベースのダイナミックストップに変更し,市場の変動の変化により適したストップを設定します.例えば,sl_value = atr(14) * 1.5固定ポイントの代わりに

  3. タイムフィルター統合取引時間フィルターを追加し,流動性の低い時間や重要な報道の時間帯を避けることで,スライドポイントや予期せぬ価格変動のリスクを軽減できます.

  4. ボリューム分析を追加統合された取引量指標は,価格の動きの強さを検証し,信号の質を向上させます.例えば,取引量が増加したときにのみ突破信号が確認されます.

  5. 機械学習の最適化: 機械学習アルゴリズムを導入し,指標の重みを動的に調整し,最近の市場パフォーマンスに応じて自己適応戦略のパラメータを設定する.

  6. 試合開始のメカニズム: 入場・出場の分期メカニズムを導入し,単一の入場・出場のタイミングのリスクを軽減する.例えば,三回分期で倉庫を建設し,三回分期で倉庫を平らにする.

  7. 複数のタイムサイクルを確認: より高い時間周期のトレンドを確認,高時間周期のトレンドの方向のみでポジションを開き,逆転取引のリスクを減らす.

  8. 指標関連性分析: 選択した指標間の関連性を分析し,偽物の複数の確認につながる可能性のある,高度に関連した指標を確認として使用することを避ける.

要約する

多技術指標金 即時変化検知とリスク管理戦略は,短期間のトレーダーを対象とした複合型取引システムであり,複数の技術指標を統合することにより,より信頼性の高い取引シグナルを提供します. この戦略の核心的な優点は,その柔軟な指標確認機構と直感的なビジュアルインタフェースで,市場状況に応じてトレーダーが戦略パラメータを調整することを可能にします.しかし,ユーザーは,過度な取引と市場騒音の影響を含む低周期取引の固有のリスクに注意する必要があります.

この戦略は,推奨された最適化措置,特にダイナミックストップローズ,多周期確認,主導指標の多様化を実施することにより,その適応性と安定性をさらに向上させることができます.この戦略は,日内トレーダーとショートラインの金取引の愛好家にとって,技術分析の枠組みを提供しますが,資金管理の原則と市場の基本を理解した組み合わせで使用する必要があります.

最終的に,取引の成功は,戦略そのものに依存するだけでなく,トレーダーが戦略を理解し,正しく実行することにも依存します.継続的な戦略のフィードバック,最適化,適応は,長期的に安定した取引結果を達成するための鍵です.

ストラテジーソースコード
/*backtest
start: 2024-03-05 00:00:00
end: 2025-03-03 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("1 Min Gold Heikin Ashi Strategy", overlay=true, max_bars_back=500)

// Adjustable TP & SL in Pips
tp_pips = input.int(50, title="Take Profit (Pips)")
sl_pips = input.int(30, title="Stop Loss (Pips)")

// Convert pips to price value for XAUUSD (1 pip = 0.1 in Gold)
tp_value = tp_pips * 0.1
sl_value = sl_pips * 0.1

// Fixed components
justcontinue = bool(true)

ma(_source, _length, _type) => 
    switch _type
        "SMA"  => ta.sma (_source, _length)
        "EMA"  => ta.ema (_source, _length)
        "RMA"  => ta.rma (_source, _length)
        "WMA"  => ta.wma (_source, _length)
        "VWMA" => ta.vwma(_source, _length)

alarm(_osc, _message) => 
    alert(syminfo.ticker + ' ' + _osc + ' : ' + _message + ', price (' + str.tostring(close, format.mintick) + ')')

// Conditional Sampling EMA Function 
Cond_EMA(x, cond, n) =>
    var val = array.new_float(0)
    var ema_val = array.new_float(1)
    if cond
        array.push(val, x)
        if array.size(val) > 1
            array.remove(val, 0)
        if na(array.get(ema_val, 0))
            array.fill(ema_val, array.get(val, 0))
        array.set(ema_val, 0, (array.get(val, 0) - array.get(ema_val, 0)) * (2 / (n + 1)) + array.get(ema_val, 0))
    EMA = array.get(ema_val, 0)
    EMA

// Conditional Sampling SMA Function
Cond_SMA(x, cond, n) =>
    var vals = array.new_float(0)
    if cond
        array.push(vals, x)
        if array.size(vals) > n
            array.remove(vals, 0)
    SMA = array.avg(vals)
    SMA

// Standard Deviation Function
Stdev(x, n) =>
    math.sqrt(Cond_SMA(math.pow(x, 2), 1, n) - math.pow(Cond_SMA(x, 1, n), 2))

// Range Size Function
rng_size(x, scale, qty, n) =>
    ATR = Cond_EMA(ta.tr(true), 1, n)
    AC = Cond_EMA(math.abs(x - x[1]), 1, n)
    SD = Stdev(x, n)
    rng_size = scale == 'Pips' ? qty * 0.0001 : scale == 'Points' ? qty * syminfo.pointvalue : scale == '% of Price' ? close * qty / 100 : scale == 'ATR' ? qty * ATR : scale == 'Average Change' ? qty * AC : scale == 'Standard Deviation' ? qty * SD : scale == 'Ticks' ? qty * syminfo.mintick : qty
    rng_size

// Two Type Range Filter Function
rng_filt(h, l, rng_, n, type, smooth, sn, av_rf, av_n) =>
    rng_smooth = Cond_EMA(rng_, 1, sn)
    r = smooth ? rng_smooth : rng_
    var rfilt = array.new_float(2, (h + l) / 2)
    array.set(rfilt, 1, array.get(rfilt, 0))
    if type == 'Type 1'
        if h - r > array.get(rfilt, 1)
            array.set(rfilt, 0, h - r)
        if l + r < array.get(rfilt, 1)
            array.set(rfilt, 0, l + r)
    if type == 'Type 2'
        if h >= array.get(rfilt, 1) + r
            array.set(rfilt, 0, array.get(rfilt, 1) + math.floor(math.abs(h - array.get(rfilt, 1)) / r) * r)
        if l <= array.get(rfilt, 1) - r
            array.set(rfilt, 0, array.get(rfilt, 1) - math.floor(math.abs(l - array.get(rfilt, 1)) / r) * r)
    rng_filt1 = array.get(rfilt, 0)
    hi_band1 = rng_filt1 + r
    lo_band1 = rng_filt1 - r
    rng_filt2 = Cond_EMA(rng_filt1, rng_filt1 != rng_filt1[1], av_n)
    hi_band2 = Cond_EMA(hi_band1, rng_filt1 != rng_filt1[1], av_n)
    lo_band2 = Cond_EMA(lo_band1, rng_filt1 != rng_filt1[1], av_n)
    rng_filt = av_rf ? rng_filt2 : rng_filt1
    hi_band = av_rf ? hi_band2 : hi_band1
    lo_band = av_rf ? lo_band2 : lo_band1
    [hi_band, lo_band, rng_filt]

// Moving Average Function
ma_function(source, length, type) =>
    if type == 'RMA'
        ta.rma(source, length)
    else if type == 'SMA'
        ta.sma(source, length)
    else if type == 'EMA'
        ta.ema(source, length)
    else if type == 'WMA'
        ta.wma(source, length)
    else if type == 'HMA'
        if (length < 2)
            ta.hma(source, 2)
        else
            ta.hma(source, length)
    else 
        ta.vwma(source, length)

// Get Table Size
table_size(s) => 
    switch s
        "Auto"   => size.auto   
        "Huge"   => size.huge   
        "Large"  => size.large  
        "Normal" => size.normal 
        "Small"  => size.small
        => size.tiny

// Confirmation Setup
confirmation_counter = array.new_string(0)
confirmation_val = array.new_string(0)
confirmation_val_short = array.new_string(0)

pushConfirmation(respect, label, longCondition, shortCondition) =>
    if respect
        array.push(confirmation_counter, label)
        array.push(confirmation_val, longCondition ? "✔️" : "❌")
        array.push(confirmation_val_short, shortCondition ? "✔️" : "❌")

leadinglongcond = bool(na)
leadingshortcond = bool(na)
longCond = bool(na)
shortCond = bool(na)
longCondition = bool(na)
shortCondition = bool(na)

// Indicator Setup Inputs
setup_group = "████████ Indicator Setup ████████"
signalexpiry = input.int(defval=3, title='Signal Expiry Candle Count', group=setup_group, inline='expiry', tooltip="Number of candles to wait for all indicators to confirm a signal. Default is 3.")
alternatesignal = input.bool(true, "Alternate Signal", group=setup_group, inline='alternate')
showsignal = input.bool(true, "Show Long/Short Signal", group=setup_group, inline='showsignal', tooltip="Option to turn on/off the Long/Short signal shown on the chart.")
showdashboard = input.bool(true, "Show Dashboard", group=setup_group, inline='dashboard')

string i_tab1Ypos = input.string('bottom', 'Dashboard Position', group=setup_group, inline='dashboard2', options=['top', 'middle', 'bottom'])
string i_tab1Xpos = input.string('right', '', inline='dashboard2', group=setup_group, options=['left', 'center', 'right'])
in_dashboardtab_size = input.string(title="Dashboard Size", defval="Normal", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group=setup_group, inline="dashboard3")

// Confirmation Indicator Settings
confirmation_group = "████████ Confirmation Indicators (filter) ████████"
respectce = input.bool(false, "Chandelier Exit", group=confirmation_group, inline='ce')
respectema = input.bool(false, "EMA Filter", group=confirmation_group, inline='respectema')
respectemaperiod = input.int(defval=200, minval=1, title='', group=confirmation_group, inline='respectema', tooltip="EMA filter for confirmation.")
respectst = input.bool(false, "SuperTrend", group=confirmation_group, inline='st')
respectstc = input.bool(false, "Schaff Trend Cycle (STC)", group=confirmation_group, inline='stc')

// Switchboard Indicators
switchboard_group = "████ Switch Board (Turn On/Off Overlay Indicators) ████"
switch_ema = input.bool(false, "EMA", group=switchboard_group, inline='Switch1')
switch_supertrend = input.bool(false, "Supertrend", group=switchboard_group, inline='Switch2')
switch_stc = input.bool(false, "STC", group=switchboard_group, inline='Switch3')

// ----------------------------------------
// 4. Indicator Code

// Chandelier Exit
////////////////////////////////////////////////
////// Chandelier Exit
///////////////////////////////////////////////
ChandelierE = "██████████ Chandelier Exit ██████████"
ce_length = input.int(title='ATR Period', defval=22, group=ChandelierE)
ce_mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0, group=ChandelierE)
showLabels = input.bool(title='Show Buy/Sell Labels?', defval=true, group=ChandelierE)
useClose = input.bool(title='Use Close Price for Extremums?', defval=true, group=ChandelierE)
highlightState = input.bool(title='Highlight State?', defval=true, group=ChandelierE)

ce_atr = ce_mult * ta.atr(ce_length)
longStop = (useClose ? ta.highest(close, ce_length) : ta.highest(ce_length)) - ce_atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop

shortStop = (useClose ? ta.lowest(close, ce_length) : ta.lowest(ce_length)) + ce_atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop

var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

ce_long = dir == 1 
ce_short = dir == -1

// EMA Filter
////////////////////////////////////////////////////////////////////////////
//////////// EMA Filter
////////////////////////////////////////////////////////////////////////////
respectemavalue = ta.ema(close, respectemaperiod)
isaboverespectema = close > respectemavalue
isbelowrespectema = close < respectemavalue

// SuperTrend Calculation
////////////////////////////////
///// SuperTrend
//////////////////////////////
sp_group = "██████████ SuperTrend ██████████"
Periods = input.int(title='ATR Period', defval=10, group=sp_group)
stsrc = input.source(hl2, title='Source', group=sp_group)
Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=3.0, group=sp_group)
changeATR = input.bool(title='Change ATR Calculation Method?', defval=true, group=sp_group)

statr2 = ta.sma(ta.tr, Periods)
statr = changeATR ? ta.atr(Periods) : statr2
stup = stsrc - Multiplier * statr
up1 = nz(stup[1], stup)
stup := close[1] > up1 ? math.max(stup, up1) : stup
dn = stsrc + Multiplier * statr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
sttrend = 1
sttrend := nz(sttrend[1], sttrend)
sttrend := sttrend == -1 and close > dn1 ? 1 : sttrend == 1 and close < up1 ? -1 : sttrend
stbuySignal = sttrend == 1 and sttrend[1] == -1
stsellSignal = sttrend == -1 and sttrend[1] == 1

isstup = bool(na)
isstdown = bool(na)
isstup := sttrend == 1
isstdown := sttrend != 1

// Schaff Trend Cycle (STC)
/////////////////////////
/// STC overlay signal
/////////////////////////
stc_group = "██████████ Schaff Trend Cycle (STC) ██████████"
fastLength = input.int(title='MACD Fast Length', defval=23, group=stc_group)
slowLength = input.int(title='MACD Slow Length', defval=50, group=stc_group)
cycleLength = input.int(title='Cycle Length', defval=10, group=stc_group)
d1Length = input.int(title='1st %D Length', defval=3, group=stc_group)
d2Length = input.int(title='2nd %D Length', defval=3, group=stc_group)
srcstc = input.source(title='Source', defval=close, group=stc_group)
upper = input.int(title='Upper Band', defval=75, group=stc_group)
lower = input.int(title='Lower Band', defval=25, group=stc_group)
v_show_last  = input.int(2000, "Plotting Length", group=stc_group)

macd = ta.ema(srcstc, fastLength) - ta.ema(srcstc, slowLength)
k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLength)))
d = ta.ema(k, d1Length)
kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
stc = ta.ema(kd, d2Length)
stc := math.max(math.min(stc, 100), 0)

stcColor1 = stc > stc[1] ? color.green : color.red
stcColor2 = stc > upper ? color.green : stc <= lower ? color.red : color.orange

upperCrossover = ta.crossover(stc, upper)
upperCrossunder = ta.crossunder(stc, upper)
lowerCrossover = ta.crossover(stc, lower)
lowerCrossunder = ta.crossunder(stc, lower)
stcup = stc >= upper
stcdown = stc <= lower

// ----------------------------------------
// 5. Switchboard Code

// Additional code for EMA from Switchboard
/////////////////////////////////////////////////////////////////////////
// EMA Selection
/////////////////////////////////////////////////////////////////////////
ma_group= "██████████ MAs Line ██████████"

len1bool = input.bool(true, '', group=ma_group, inline='len1')
len1 = input.int(5, title='MA 1', group=ma_group, inline='len1')
string ma_1_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA', 'HMA', 'VWMA'], inline='len1', group=ma_group)
color ma_1_colour = input.color(color.rgb(254, 234, 74, 0), '', inline='len1', group=ma_group)

len2bool = input.bool(true, '', group=ma_group, inline='len2')
len2 = input.int(13, minval=1, title='MA 2', group=ma_group, inline='len2')
string ma_2_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA', 'HMA', 'VWMA'], inline='len2', group=ma_group)
color ma_2_colour = input.color(color.rgb(253, 84, 87, 0), '', inline='len2', group=ma_group)

len3bool = input.bool(false, '', group=ma_group, inline='len3')
len3 = input.int(20, minval=1, title='MA 3', group=ma_group, inline='len3')
string ma_3_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA', 'HMA', 'VWMA'], inline='len3', group=ma_group)
color ma_3_colour = input.color(color.new(color.aqua, 0), '', inline='len3', group=ma_group)

len4bool = input.bool(true, '', group=ma_group, inline='len4')
len4 = input.int(50, minval=1, title='MA 4', group=ma_group, inline='len4')
string ma_4_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA', 'HMA', 'VWMA'], inline='len4', group=ma_group)
color ma_4_colour = input.color(color.new(color.blue, 0), '', inline='len4', group=ma_group)

len5bool = input.bool(true, '', group=ma_group, inline='len5')
len5 = input.int(200, minval=1, title='MA 5', group=ma_group, inline='len5')
string ma_5_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA', 'HMA', 'VWMA'], inline='len5', group=ma_group)
color ma_5_colour = input.color(color.new(color.white, 0), '', inline='len5', group=ma_group)

// Request Security for MA calculations
ema1 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len1, ma_1_type))
ema2 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len2, ma_2_type))
ema3 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len3, ma_3_type))
ema4 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len4, ma_4_type))
ema5 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len5, ma_5_type))

// Plot the Moving Averages
plot(len1bool and switch_ema ? ema1 : na, color=ma_1_colour, linewidth=2, title='MA 1')
plot(len2bool and switch_ema ? ema2 : na, color=ma_2_colour, linewidth=2, title='MA 2')
plot(len3bool and switch_ema ? ema3 : na, color=ma_3_colour, linewidth=2, title='MA 3')
plot(len4bool and switch_ema ? ema4 : na, color=ma_4_colour, linewidth=2, title='MA 4')
plot(len5bool and switch_ema ? ema5 : na, color=ma_5_colour, linewidth=2, title='MA 5')

// Additional code for SuperTrend from switchboard
///////////////////////////////////////////////////
// SuperTrend - Switchboard
///////////////////////////////////////////////////
upPlot = plot(sttrend == 1 and switch_supertrend ? stup : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
plotshape(stbuySignal and switch_supertrend ? stup : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))

dnPlot = plot(sttrend != 1 and switch_supertrend ? dn : na, title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))
plotshape(stsellSignal and switch_supertrend ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))

// Additional code for Schaff Trend Cycle (STC) from switchboard
/////////////////////////////////////////////
// Schaff Trend Cycle (STC) - Switchboard
/////////////////////////////////////////////
plotshape(stcdown and switch_stc ? true : na, style=shape.circle, location=location.top, show_last=v_show_last, color=color.new(color.red, 0), title='STC Sell')
plotshape(stcup and switch_stc ? true : na, style=shape.circle, location=location.top, show_last=v_show_last, color=color.new(color.green, 0), title='STC Buy')

// ----------------------------------------
// 6. Declare and Initialize 'leadingindicator'
leadingindicator = input.string(title="Leading Indicator", defval="Chandelier Exit",
  options=["Chandelier Exit"], group="████████ Main Indicator (signal) ████████")

// 6. Leading Indicator Logic
if leadingindicator == 'Chandelier Exit'
    leadinglongcond := ce_long
    leadingshortcond := ce_short

// ----------------------------------------
// 7. Confirmation Indicator Logic
longCond := leadinglongcond
shortCond := leadingshortcond

longCond := longCond  and   (respectce ? ce_long : justcontinue)
shortCond := shortCond and   (respectce ? ce_short : justcontinue)

longCond := longCond  and   (respectema ? isaboverespectema : justcontinue)
shortCond := shortCond and   (respectema ? isbelowrespectema : justcontinue)

longCond := longCond  and   (respectst ? isstup : justcontinue)
shortCond := shortCond and   (respectst ? isstdown : justcontinue)

longCond := longCond  and   (respectstc ? stcup : justcontinue)


// ----------------------------------------
// 7. Confirmation Indicator Logic

longCond := leadinglongcond
shortCond := leadingshortcond

longCond := longCond  and   (respectce ? ce_long : justcontinue)
shortCond := shortCond and   (respectce ? ce_short : justcontinue)

longCond := longCond  and   (respectema ? isaboverespectema : justcontinue)
shortCond := shortCond and   (respectema ? isbelowrespectema : justcontinue)

longCond := longCond  and   (respectst ? isstup : justcontinue)
shortCond := shortCond and   (respectst ? isstdown : justcontinue)

longCond := longCond  and   (respectstc ? stcup : justcontinue)
shortCond := shortCond and   (respectstc ? stcdown : justcontinue)

// ----------------------------------------
// 8. Function to Update Dashboard Label

pushConfirmation(respectce, "Chandelier Exit", ce_long, ce_short)
pushConfirmation(respectema, "EMA", isaboverespectema, isbelowrespectema)
pushConfirmation(respectst, "SuperTrend", isstup, isstdown)
pushConfirmation(respectstc, "Schaff Trend Cycle", stcup, stcdown)

// ----------------------------------------
// 9. Final Part (Dashboard Table and Signal Plotting)

leadingstatus = leadinglongcond ? "✔️" : "❌"
leadingstatus_short = leadingshortcond ? "✔️" : "❌"

rowcount = int(na)
if array.size(confirmation_counter) == 0
    rowcount := 5
else
    rowcount := array.size(confirmation_counter) + 4

// Signal Expiry Logic
var int leadinglong_count = 0
var int leadinglong_count2 = 0
var int leadingshort_count = 0
var int leadingshort_count2 = 0

if leadinglongcond
    leadinglong_count := leadinglong_count + 1
    leadinglong_count2 := leadinglong_count

for i = 1 to 100
    if leadinglongcond[i]
        leadinglong_count := leadinglong_count + 1
        leadinglong_count2 := leadinglong_count
    else
        leadinglong_count := 0
        break

if leadingshortcond
    leadingshort_count := leadingshort_count + 1
    leadingshort_count2 := leadingshort_count

for i = 1 to 100
    if leadingshortcond[i]
        leadingshort_count := leadingshort_count + 1
        leadingshort_count2 := leadingshort_count
    else
        leadingshort_count := 0
        break

// Expiry Condition
CondIni = 0

// If expiry option is used
longcond_withexpiry = longCond and leadinglong_count2 <= signalexpiry
shortcond_withexpiry = shortCond and leadingshort_count2 <= signalexpiry

// Without expiry
longCondition := longcond_withexpiry and CondIni[1] == -1
shortCondition := shortcond_withexpiry and CondIni[1] == 1

if alternatesignal
    longCondition := longcond_withexpiry and CondIni[1] == -1  
    shortCondition := shortcond_withexpiry and CondIni[1] == 1 
else
    longCondition := longcond_withexpiry  
    shortCondition := shortcond_withexpiry 

CondIni := longcond_withexpiry ? 1 : shortcond_withexpiry ? -1 : CondIni[1]

// Check if expiry count is crossed
is_expiry_count_crossed_long = leadinglong_count2 >= signalexpiry 
is_expiry_count_crossed_short = leadingshort_count2 >= signalexpiry 

// Plot signals on chart
plotshape(showsignal ? (longCondition[1] ? false : longCondition) : na, title='Buy Signal', text='long', textcolor=color.new(color.white, 0), style=shape.labelup, size=size.tiny, location=location.belowbar, color=color.new(color.green, 0))
plotshape(showsignal ? (shortCondition[1] ? false : shortCondition) : na, title='Sell Signal', text='short', textcolor=color.new(color.white, 0), style=shape.labeldown, size=size.tiny, location=location.abovebar, color=color.new(color.red, 0))

// Alerts
alertcondition(longCondition, title='Buy Alert', message='BUY')
alertcondition(shortCondition, title='Sell Alert', message='SELL')
alertcondition(longCondition or shortCondition, title='Buy or Sell Alert', message="Buy or Sell Alert")

/// ----------------------------------------
// 10. Strategy Execution - Entries & Exits

// Use already declared TP & SL values (from the start of the script)

// Long Entry Conditions
if longCondition
    strategy.entry("Long", strategy.long)
    strategy.exit("TakeProfit_Long", from_entry="Long", limit=close + tp_value, stop=close - sl_value)

// Short Entry Conditions
if shortCondition
    strategy.entry("Short", strategy.short)
    strategy.exit("TakeProfit_Short", from_entry="Short", limit=close - tp_value, stop=close + sl_value)