커뮤니티

문의

프로필 이미지
레전드
2025-10-27 03:09:42
105
글번호 227326
답변완료

indicator('Consolidation Range with Signals (Zeiierman)', overlay=true, max_labels_count = 500, max_lines_count = 500) //~~}
// ~~ Tooltips { var string t1 = "Select the method used for detecting ranging market conditions.\n\n  ADX: Uses the Average Directional Index to identify non-trending periods when ADX is below a set threshold.\n\n  Volatility: Detects ranges by identifying periods of compression in volatility using standard deviation, variance, and ATR filters.\n\n  Price Action: Confirms range by measuring the high-low percentage contraction and requiring a minimum number of DMI crosses, suggesting indecision or balance in price action." var string t2 = "Length or period used for detecting the range." var string t3 = "Multiplier applied to the calculated band distance." var string t4 = "Toggle to display Take Profit and Stop Loss levels on the chart." var string t5 = "Minimum number of bars between two consecutive SL/TP entries." var string t6 = "Stop Loss multiplier from the filtered base value." var string t7 = "Take Profit 1 multiplier from the filtered base value." var string t8 = "Take Profit 2 multiplier from the filtered base value." var string t9 = "Take Profit 3 multiplier from the filtered base value." var string t10 = "ADX threshold under which the market is considered ranging." var string t11 = "Smoothing period used for the ADX calculation." var string t12 = "Standard deviation compression threshold used to detect low volatility." var string t13 = "Variance compression threshold used to detect low volatility." var string t14 = "ATR compression threshold used to detect low volatility." //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs { // ~~ Range { method    = input.string("ADX", options=["ADX", "Volatility"], title="Range Detection Method", group="Range Detection", tooltip=t1) len       = input.int(10, minval=2, title="Range Period", group="Range Detection", tooltip=t2) band_mult = input.float(1.8, step=0.1, minval=0.01,title="Range Multiplier", group="Range Detection", tooltip=t3) upper_col = input.color(#0060e6, title="Range", group="Range Detection", inline="bandcol") lower_col = input.color(#29fafa, title="", group="Range Detection", inline="bandcol") pos_col = input.color(#0060e6, title="Trend", group="Range Detection", inline="trendcol") neg_col = input.color(#29fafa, title="", group="Range Detection", inline="trendcol") //~~} // ~~ SL/TP { showTP    = input.bool(true, title="Show SL/TP Levels", group="Targets", tooltip=t4) cooldown  = input.int(20, title="SL/TP Cooldown (Bars)", group="Targets", tooltip=t5) sl_mult   = input.float(0.4, step=0.1, minval=0.01,title="SL", group="Targets", inline="sl", tooltip=t6) showsl    = input.bool(true, title="", group="Targets", inline="sl", tooltip=t6) tp1_mult  = input.float(0.5, step=0.1, minval=0.01,title="TP1", group="Targets", inline="tp1", tooltip=t7) showtp1   = input.bool(true, title="", group="Targets", inline="tp1", tooltip=t7) tp2_mult  = input.float(1.0, step=0.1, minval=0.01,title="TP2", group="Targets", inline="tp2", tooltip=t8) showtp2   = input.bool(false, title="", group="Targets", inline="tp2", tooltip=t8) tp3_mult  = input.float(2.0, step=0.1, minval=0.01,title="TP3", group="Targets", inline="tp3", tooltip=t9) showtp3   = input.bool(false, title="", group="Targets", inline="tp3", tooltip=t9)
entry_col = input.color(color.blue, title="Entry", group="Targets", inline="tpcol") sl_col    = input.color(#ff0000, title="SL", group="Targets", inline="tpcol") bullColor = input.color(#09c10f, title="TP", group="Targets", inline="tpcol") bearColor = input.color(#ff69cb, title="", group="Targets", inline="tpcol") //~~} // ~~ ADX { adx_thresh = input.int(17, step=1, minval=0,title="ADX Threshold", group="ADX", tooltip=t10) adx_smooth = input.int(10, step=1, minval=0,title="ADX Smoothing", group="ADX", tooltip=t11) //~~} // ~~ Volatility { vol_mult_std = input.float(0.8, step=0.1, minval=0.001, title="StdDev Multiplier", group="Volatility", tooltip=t12) vol_mult_var = input.float(0.8, step=0.1, minval=0.001,title="Variance Multiplier", group="Volatility", tooltip=t13) vol_mult_atr = input.float(0.9, step=0.1, minval=0.001,title="ATR Multiplier", group="Volatility", tooltip=t14) //~~} //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ ADX { [_, _, adx] = ta.dmi(len, adx_smooth) isADX       = adx < adx_thresh //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Volatility Compression { logret  = math.log(close / close[1]) std_now = ta.stdev(logret, len) std_avg = ta.sma(std_now, len) atr_now = ta.atr(len) atr_avg = ta.sma(atr_now, len) var_now = ta.variance(logret, len) var_avg = ta.sma(var_now, len) isVolatility = std_now < std_avg * vol_mult_std and var_now < var_avg * vol_mult_var and atr_now < atr_avg * vol_mult_atr //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Switch { methodDetected = (method == "ADX" and isADX) or                  (method == "Volatility" and isVolatility) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Var { var float rngfilt       = close var color trendColor    = na var bool rangeVisible   = false var float prev_hi       = na var float prev_lo       = na var int rangeStartBar   = na var int rangeBarsActive = 0 var int lastBreakoutBar = na
if methodDetected and na(rangeStartBar)     rangeStartBar := bar_index else if not methodDetected     rangeStartBar := na
if methodDetected     rangeVisible := true //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Range Calculation { diff = math.abs(high - low[1]) r    = ta.sma(2.618 * diff, 2000) * band_mult //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Range Calculation Functions { pricejump(prev) =>     highJump = prev + math.abs(close - prev) / r * r     lowJump  = prev - math.abs(close - prev) / r * r     [highJump, lowJump]
rangefilter(hhjump, lljump, prev) =>     hhBreak    = close > prev     hhTooClose = close - r < prev     hhShift    = close - r     llTooClose = close + r > prev     llShift    = close + r     step1      = hhBreak ? (hhTooClose ? prev : hhShift) : (llTooClose ? prev : llShift)     hhAbove = close >= prev + r     llBelow = close <= prev - r     hhAbove ? hhjump : llBelow ? lljump : step1
bands(filt) => [filt + r, filt - r] trenddir(filt) => [filt > nz(filt[1]), filt < nz(filt[1])] trendcomp(filt) => [filt, ta.sma(filt, 2), ta.sma(filt, 4)]
prev = nz(rngfilt[1]) [hhJ, llJ] = pricejump(prev) rngfilt    := rangefilter(hhJ, llJ, prev) prev_rngfilt      = nz(rngfilt[1]) rngfilt_step_up   = rngfilt > prev_rngfilt rngfilt_step_down = rngfilt < prev_rngfilt
[hiband, loband] = bands(rngfilt) [up, down]       = trenddir(rngfilt) [TrendFast, TrendMed, TrendLong] = trendcomp(rngfilt)
if methodDetected     prev_hi := hiband     prev_lo := loband
if not methodDetected and (close[1] > prev_hi or close[1] < prev_lo)     rangeVisible := false
MIDX1 = (hiband - rngfilt) / 3 MID1  = rngfilt + MIDX1 MID2  = MID1 + MIDX1 MIDX2 = (rngfilt - loband) / 3 MID3  = rngfilt - MIDX2 MID4  = MID3 - MIDX2 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plot { trendColor := up ? pos_col : down ? neg_col : trendColor[1] plotTrend = plot(rangeVisible ? TrendFast : close, "Trend", rangeVisible ? trendColor:color.new(trendColor,100), 1)
plotMid1 = plot(rangeVisible ? MID1 : close, "MID1", rangeVisible ?color.new(upper_col, 50):color.new(upper_col, 100), style= plot.style_stepline)   plotMid2 = plot(rangeVisible ? MID2 : close, "MID2", rangeVisible ?color.new(upper_col, 50):color.new(upper_col, 100), style= plot.style_stepline)   plotMid3 = plot(rangeVisible ? MID3 : close, "MID3", rangeVisible ?color.new(lower_col, 50):color.new(lower_col, 100), style= plot.style_stepline)   plotMid4 = plot(rangeVisible ? MID4 : close, "MID4", rangeVisible ?color.new(lower_col, 50):color.new(lower_col, 100), style= plot.style_stepline)  
fill(plotMid2, plotTrend, MID2, TrendFast, color.new(upper_col, 60),na) fill(plotMid4, plotTrend, MID4, TrendFast, color.new(lower_col, 60),na) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ TP and SL { rangeBarsActive    := na(rangeStartBar) ? 0 : bar_index - rangeStartBar canTriggerBreakout =  (na(lastBreakoutBar) or bar_index - lastBreakoutBar >= cooldown) enterLong  = rangeVisible and rngfilt_step_up and canTriggerBreakout enterShort = rangeVisible and rngfilt_step_down and canTriggerBreakout
calcSLTP(isLong) =>     base = rngfilt     offset = r * sl_mult     tp1off = r * tp1_mult     tp2off = r * tp2_mult     tp3off = r * tp3_mult
    stop_ = isLong ? base - offset : base + offset     tp1_ = isLong ? base + tp1off : base - tp1off     tp2_ = isLong ? base + tp2off : base - tp2off     tp3_ = isLong ? base + tp3off : base - tp3off     [stop_, tp1_, tp2_, tp3_]
drawLevels(entry, sl, tp1, tp2, tp3, col) =>     if showTP         line.new(bar_index, entry, bar_index + 20, entry, color=entry_col, width=2)         if showsl             line.new(bar_index, sl, bar_index + 20, sl, color=color.new(sl_col, 0), width=2)         if showtp1             line.new(bar_index, tp1, bar_index + 20, tp1, color=color.new(col, 0), width=2)         if showtp2             line.new(bar_index, tp2, bar_index + 20, tp2, color=color.new(col, 0), width=2)         if showtp3             line.new(bar_index, tp3, bar_index + 20, tp3, color=color.new(col, 0), width=2)     if showTP         label.new(bar_index+ 20, entry, "Entry", style=label.style_label_left, color=entry_col, textcolor=color.white, size = size.tiny)         if showsl             label.new(bar_index+ 20, sl,    "SL", style=label.style_label_left, color=color.new(sl_col, 0), textcolor=color.white, size = size.tiny)         if showtp1             label.new(bar_index+ 20, tp1,   "TP 1", style=label.style_label_left, color=color.new(col, 0), textcolor=color.white, size = size.tiny)         if showtp2                 label.new(bar_index+ 20, tp2,   "TP 2", style=label.style_label_left, color=color.new(col, 0), textcolor=color.white, size = size.tiny)         if showtp3             label.new(bar_index+ 20, tp3,   "TP 3", style=label.style_label_left, color=color.new(col, 0), textcolor=color.white, size = size.tiny)
var float SL  = na var float TP1 = na var float TP2 = na var float TP3 = na
if enterLong and showTP and (na(lastBreakoutBar) or bar_index - lastBreakoutBar >= cooldown)     [s, t1_, t2_, t3_] = calcSLTP(true)     SL := s, TP1 := t1_, TP2 := t2_, TP3 := t3_     drawLevels(close, SL, TP1, TP2, TP3, bullColor)     lastBreakoutBar := bar_index
if enterShort and showTP and (na(lastBreakoutBar) or bar_index - lastBreakoutBar >= cooldown)     [s, t1_, t2_, t3_] = calcSLTP(false)     SL := s, TP1 := t1_, TP2 := t2_, TP3 := t3_     drawLevels(close, SL, TP1, TP2, TP3, bearColor)     lastBreakoutBar := bar_index //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}    
예스로 부탁드립니다

지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-10-27 18:54:29

안녕하세요. 예스스탁입니다. input:method(1);//1:"ADX",2:"Volatility" input:len(10); input:band_mult(1.8); input:upper_col(Blue); input:lower_col(Cyan); input:pos_col(Blue); input:neg_col(cyan); input:showTP(true); input:cooldown(20); input:sl_mult(0.4); input:showsl(true); input:tp1_mult(0.5); input:showtp1(true); input:tp2_mult(1.0); input:showtp2(false); input:tp3_mult(2.0); input:showtp3(false); input:entry_col(blue); input:sl_col(Red); input:bullColor(Lime); input:bearColor(Pink); input:adx_thresh(17); input:adx_smooth(10); input:vol_mult_std(0.8); input:vol_mult_var(0.8); input:vol_mult_atr(0.9); var : A(0),isADX(False); A = ADX(len);#adx_smooth isADX = A < adx_thresh; var : logret(0),std_now(0),std_avg(0),atr_now(0),atr_avg(0),var_now(0),var_avg(0); var : isVolatility(False),methodDetected(False); logret = log(close / close[1]); std_now = std(logret, len); std_avg = ma(std_now, len); atr_now = atr(len); atr_avg = ma(atr_now, len); var_now = variance(logret, len,1); var_avg = ma(var_now, len); isVolatility = std_now < std_avg * vol_mult_std and var_now < var_avg * vol_mult_var and atr_now < atr_avg * vol_mult_atr; methodDetected = (method == 1 and isADX) or (method == 2 and isVolatility); var :rngfilt(close); var :trendColor(nan); var :rangeVisible(false); var :prev_hi(nan); var :prev_lo(nan); var :rangeStartBar(Nan); var :rangeBarsActive(0); var :lastBreakoutBar(nan); if methodDetected and rangeStartBar == False Then rangeStartBar = index; else if methodDetected == False Then rangeStartBar = Nan; if methodDetected Then rangeVisible = true; var : diff(0),r(0); diff = abs(high - low[1]); r = ma(2.618 * diff, 2000) * band_mult; var : prev(0),hhj(0),llj(0); prev = iff(isnan(rngfilt[1])==true,0,rngfilt[1]); hhJ = prev + abs(close - prev) / r * r; llJ = prev - abs(close - prev) / r * r; //rngfilt := rangefilter(hhJ, llJ, prev) var : hhBreak(False),hhTooClose(False),hhShift(0),llTooClose(False),llShift(0); var : step1(0),hhAbove(False),llBelow(False),prev_rngfilt(0); var : rngfilt_step_up(False),rngfilt_step_down(False); hhBreak = close > prev; hhTooClose = close - r < prev; hhShift = close - r; llTooClose = close + r > prev; llShift = close + r; step1 = iff(hhBreak , IFf(hhTooClose , prev , hhShift) , IFf(llTooClose , prev , llShift)); hhAbove = close >= prev + r; llBelow = close <= prev - r; rngfilt = iff(hhAbove , hhJ , IFf(llBelow , llJ , step1)); prev_rngfilt = iff(isnan(rngfilt[1])==true,0,rngfilt[1]); rngfilt_step_up = rngfilt > prev_rngfilt; rngfilt_step_down = rngfilt < prev_rngfilt; var : hiband(0),loband(0); var : up(False),down(False); var : TrendFast(0),TrendMed(0),TrendLong(0); #trendcomp(filt) => [filt, ta.sma(filt, 2), ta.sma(filt, 4)] hiband = rngfilt+r; loband = rngfilt-r; up = rngfilt > prev_rngfilt; down = rngfilt < prev_rngfilt; TrendFast = rngfilt; TrendMed = ma(rngfilt,2); TrendLong = ma(rngfilt,4); if methodDetected Then { prev_hi = hiband; prev_lo = loband; } if methodDetected == False and (close[1] > prev_hi or close[1] < prev_lo) Then rangeVisible = false; var : MIDX1(0),MID1(0),MID2(0),MIDX2(0),MID3(0),MID4(0); MIDX1 = (hiband - rngfilt) / 3; MID1 = rngfilt + MIDX1; MID2 = MID1 + MIDX1; MIDX2 = (rngfilt - loband) / 3; MID3 = rngfilt - MIDX2; MID4 = MID3 - MIDX2; trendColor = iff(up , pos_col ,IFf( down , neg_col , trendColor[1])); if rangeVisible == true Then { plot1(TrendFast, "Trend", trendColor); plot2(MID1, "MID1", upper_col); plot3(MID2, "MID2", upper_col); plot4(MID3, "MID3", lower_col); plot5(MID4, "MID4", lower_col); } Else { NoPlot(1); NoPlot(2); NoPlot(3); NoPlot(4); NoPlot(5); } var : canTriggerBreakout(False),enterLong(False),enterShort(False); rangeBarsActive = iff(rangeStartBar, 0 , index - rangeStartBar); canTriggerBreakout = lastBreakoutBar or index - lastBreakoutBar >= cooldown; enterLong = rangeVisible and rngfilt_step_up and canTriggerBreakout; enterShort = rangeVisible and rngfilt_step_down and canTriggerBreakout; var : base(0),offset(0),tp1off(0),tp2off(0),tp3off(0); var : s(0),t1_(0),t2_(0),t3_(0); base = rngfilt; offset = r * sl_mult; tp1off = r * tp1_mult; tp2off = r * tp2_mult; tp3off = r * tp3_mult; var : sl(0),tp1(0),tp2(0),tp3(0),CC(0); var : TL1(0),TL2(0),TL3(0),TL4(0),TL5(0); if enterLong and showTP /*and (lastBreakoutBar == False or index - lastBreakoutBar >= cooldown)*/ Then { TL_New(sDate,stime,0,sDate,sTime,999999999); s = base - offset; t1_ = base + tp1off; t2_ = base + tp2off; t3_ = base + tp3off; CC = close; SL = s; TP1 = t1_; TP2 = t2_; TP3 = t3_; TL1 = TL_New(sDate,sTime,CC,NextBarSdate,NextBarStime,CC); if showsl == true Then TL2 = TL_New(sDate,sTime,SL,NextBarSdate,NextBarStime,SL); if showtp1 == true Then TL3 = TL_New(sDate,sTime,TP1,NextBarSdate,NextBarStime,TP1); if showtp2 == true Then TL4 = TL_New(sDate,sTime,TP2,NextBarSdate,NextBarStime,TP2); if showtp3 == true Then TL5 = TL_New(sDate,sTime,TP3,NextBarSdate,NextBarStime,TP3); TL_SetColor(TL1,entry_col); TL_SetColor(TL2,sl_col); TL_SetColor(TL3,bullColor); TL_SetColor(TL4,bullColor); TL_SetColor(TL5,bullColor); lastBreakoutBar = index; } Else { if Index < lastBreakoutBar+20 Then { TL_SetEnd(TL1,NextBarSdate,NextBarStime,CC); TL_SetEnd(TL2,NextBarSdate,NextBarStime,SL); TL_SetEnd(TL3,NextBarSdate,NextBarStime,TP1); TL_SetEnd(TL4,NextBarSdate,NextBarStime,TP2); TL_SetEnd(TL5,NextBarSdate,NextBarStime,TP3); } } if enterShort and showTP and (lastBreakoutBar == False or index - lastBreakoutBar >= cooldown) Then { TL_New(sDate,stime,0,sDate,sTime,999999999); s = base + offset; t1_ = base - tp1off; t2_ = base - tp2off; t3_ = base - tp3off; CC = close; SL = s; TP1 = t1_; TP2 = t2_; TP3 = t3_; TL1 = TL_New(sDate,sTime,CC,NextBarSdate,NextBarStime,CC); if showsl == true Then TL2 = TL_New(sDate,sTime,SL,NextBarSdate,NextBarStime,SL); if showtp1 == true Then TL3 = TL_New(sDate,sTime,TP1,NextBarSdate,NextBarStime,TP1); if showtp2 == true Then TL4 = TL_New(sDate,sTime,TP2,NextBarSdate,NextBarStime,TP2); if showtp3 == true Then TL5 = TL_New(sDate,sTime,TP3,NextBarSdate,NextBarStime,TP3); TL_SetColor(TL1,entry_col); TL_SetColor(TL2,sl_col); TL_SetColor(TL3,bearColor); TL_SetColor(TL4,bearColor); TL_SetColor(TL5,bearColor); lastBreakoutBar = index; } 즐거운 하루되세요