
다중 기술 지표 금 즉각적인 변화 감지 및 위험 관리 전략은 1 분 헤이킨 아시 차트를 기반으로 한 금 거래 시스템으로, 여러 기술 지표를 거래 신호 및 확인 도구로 결합합니다. 이 전략은 주로 폭락 출구를 ((Chandelier Exit) 을 주요 지표로 사용하고, 선택적으로 EMA 필터, 슈퍼 트렌드 ((SuperTrend)) 및 모래 트렌드 사이클 ((Schaff Trend Cycle)) 과 같은 지표를 확인 도구로 결합합니다. 이 전략은 유연한 중지 손실 메커니즘을 채택하고 직관적인 거래 기계를 제공하여 거래자가 거래 상태를 실시간으로 모니터링 할 수 있습니다.
이 전략은 다단계 신호 확인 시스템을 기반으로, 핵심 논리는 다음과 같다:
주요 지표 신호 생성전략: 台出口 (Chandelier Exit) 을 지배적인 지표로 한다. 台出口 (Chandelier Exit) 은 ATR (Average True Range) 의 곱을 사용하여 스톱 포지션을 결정하고 다중 헤드 및 공중 헤드 신호를 생성하는 트렌드 추적 지표이다.
지표 필터 확인이 전략은 트레이더에게 선택적으로 여러 가지 확인 지표를 사용할 수 있도록 허용합니다.
신호 소멸 메커니즘: 전략은 신호의 소멸 기능을 구현하여 신호의 유효한 수를 설정하여 오래된 신호에서 거래되는 것을 방지한다.
트랜잭션 실행 논리: 모든 선택 조건이 충족되면, 전략은 출전 신호를 생성하고, 자동으로 고정 점수의 스톱 스톱을 설정한다.
데이터 처리 최적화: 전략 사용 조건 샘플링 EMA와 SMA 함수, 그리고 전용 범위 필터, 기술 지표의 계산 효율을 높인다.
시각화 시스템: 각 지표의 상태를 표시하는 거래 디스플레이를 제공하며, 거래 신호와 스톱 손실 위치를 차트에 표시합니다.
다중 인증 메커니즘다중 지표 확인을 통해 가짜 신호를 현저히 줄이고 거래 정확도를 향상시킵니다. 여러 지표가 함께 한 방향을 확인 할 때 거래 신호는 더 신뢰할 수 있습니다.
유연한 지표 조합: 사용자는 다양한 확인 지표를 선택하여 사용하거나 사용하지 않고, 시장 조건에 따라 전략을 조정할 수 있습니다.
정확한 위험 관리: 전략은 사용자가 특정 스톱 스톱 손실 포인트를 설정할 수 있도록 허용하며, 각 거래의 위험과 수익률을 정확하게 제어 할 수 있습니다.
신호 경과 제어: 신호 유효 기간을 설정하여, 노후 된 신호에 거래하는 것을 피하고, 지연 위험을 줄이는 전략.
높은 시각화 거래 인터페이스: 거래 디스플레이가 모든 지표의 상태를 직관적으로 표시하여 거래자가 시장 조건을 신속하게 평가할 수 있도록 도와줍니다.
금 시장에 대한 최적화: 전략은 금 시장의 특성에 대한 파라미터를 최적화하고, 특히 포인트 가치 전환을 고려한다 ((1 포인트 = 0.1 달러) )
고주파 거래 적응성1분 시간 사이클은 전략이 단기 가격 변동을 포착할 수 있도록 해줍니다. 1분 시간 사이클은 전략이 단기 가격 변동을 포착할 수 있도록 해줍니다.
과도한 거래의 위험: 1분 주기에는 거래비용 증가와 과도한 거래로 인한 과도한 거래 신호가 발생할 수 있습니다. 해결 방법은 확인 지표 수를 조정하거나 신호 필터링 조건을 추가하는 것입니다.
시장 소음의 영향: 낮은 시간 사이클은 시장 소음에 방해가 될 수 있으며, 잘못된 신호를 발생시킨다. 높은 변동성 기간 동안 신중하게 사용하거나 더 긴 사이클과 결합하여 트렌드를 확인하는 것이 좋습니다.
지표가 쌓여지는 후진성다중 지표 확인은 가짜 신호를 줄이면서도 시스템의 지연성을 증가시켜 수익 기회를 놓치게 할 수 있다. 응답 속도를 높이기 위해 확인 지표 수를 줄이는 것을 고려할 수 있다.
고정 정지 손실의 한계: 고정 점수의 스톱 스로드는 시장의 변동성을 고려하지 않고, 높은 변동기에는 너무 가까이, 낮은 변동기에는 너무 멀리 멈출 수 있습니다. 현재 ATR 동력에 따라 스톱 스로드 값을 조정하는 것이 좋습니다.
금 시장의 특별한 위험금 시장은 인플레이션 데이터, 중앙은행 정책, 지리적 정치 등과 같은 여러 거시 경제 요인에 의해 영향을 받으며, 순수 기술 분석은 이러한 영향을 무시 할 수 있습니다. 기초 분석과 함께 사용하는 것이 좋습니다.
주요 지표의 의존성: 전략은 台出口에 과도하게 의존하고 있으며, 이 지표는 지역 시장에서 좋지 않은 성과를 낼 수 있습니다. 여러 가지 지표를 선택할 수 있는 옵션을 추가하는 것이 좋습니다.
주요 지표다양성현재 전략은 우도 수출만을 주요 지표로 지원하고, 다양한 시장 환경에 적응하기 위해 부린 띠, MACD 또는 적응형 이동 평균과 같은 다양한 주요 지표 옵션을 지원할 수 있습니다.
동적 중지 중지 손실: 고정 점수 스톱 스톱을 ATR 기반의 동적 스톱 스톱으로 변경하여 시장의 변동성에 더 잘 적응할 수 있습니다. 예를 들어,sl_value = atr(14) * 1.5고정 점수 대신
시간 필터 통합거래 시간 필터를 추가하고, 유동성이 낮은 시간이나 중요한 보도 시간대를 피하면 슬라이드 포인트와 예상치 못한 가격 변동의 위험을 줄일 수 있습니다.
볼륨 분석 추가: 통합 거래량 지표는 가격 이동의 강도를 검증하여 신호의 질을 향상시킵니다. 예를 들어, 거래량이 증가했을 때만 돌파 신호를 확인합니다.
기계 학습 최적화: 기계 학습 알고리즘을 도입하여 지표의 무게를 역동적으로 조정하고, 최근 시장의 성과에 따라 자율적 전략 파라미터를 조정한다.
출전 배당 메커니즘: 세 차례의 입출장 및 세 차례의 청산과 같은 단일 입출장 시점의 시간적 위험을 줄이기 위해 세 차례의 입출장 제도를 시행한다.
다중 시간 주기 확인: 더 높은 시간 주기의 트렌드를 확인하고, 높은 시간 주기의 트렌드 방향으로만 포지션을 개시하여 역동 거래 위험을 줄여줍니다.
지표 관련성 분석: 선택된 지표들 사이의 연관성을 분석하고, 높은 연관성을 가진 지표를 확인으로 사용하는 것을 피하십시오. 이것은 가짜의 여러 가지 확인을 초래할 수 있습니다.
다중 기술 지표 금 즉각적인 변화 탐지 및 위험 관리 전략은 단기 거래자를 대상으로 한 복합 거래 시스템으로, 여러 기술 지표를 통합하여 더 신뢰할 수있는 거래 신호를 제공합니다. 이 전략의 핵심 장점은 유연한 지표 확인 메커니즘과 직관적인 시각적 인터페이스로, 거래자가 시장 상황에 따라 전략 매개 변수를 조정할 수 있습니다. 그러나 사용자는 과도한 거래 및 시장 소음 영향을 포함하여 낮은 주기 거래의 고유한 위험에 대해 경계해야합니다.
제안된 최적화 조치를 실행함으로써, 특히 동적 스톱로스, 다중 시간 주기의 확인 및 유도 지표의 다양화를 통해, 이 전략은 더욱 적응성과 안정성을 향상시킬 수 있습니다. 이 전략은 일일 거래자와 단선 금 거래 애호가들에게 기술 분석 프레임워크를 제공하지만, 자산 관리 원칙과 시장의 기본 이해를 결합하여 사용되어야합니다.
결국, 거래의 성공은 전략 자체에 달려있을뿐만 아니라 거래자의 전략에 대한 이해와 올바른 실행에 달려 있습니다. 지속적인 전략 피드백, 최적화 및 적응은 장기적으로 안정적인 거래 결과를 달성하는 데 중요합니다.
/*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)