smli eofcfc

//@version=5 indicator(shorttitle="smli eofcfc", title="smli eofcfc", overlay=true) //============================================================================== //== SECTION 1: BOLLINGER BAND BASED TREND SIGNALS == //============================================================================== string grp_bb = "Bollinger Band Trend" BBperiod = input.int(6, "BB Period", group=grp_bb) BBdeviations = input.float(0.10, "BB Deviations", group=grp_bb) UseATRfilter = input.bool(true, "Use ATR Filter for Trend Line", group=grp_bb) ATRperiod = input.int(1, "ATR Period for Trend Line", group=grp_bb) stopLossMultiplier = input.float(1.5, title="Stop Loss Multiplier", group=grp_bb) targetMultiplier = input.float(2.0, title="Target Multiplier", group=grp_bb) float BBUpper = ta.sma(close, BBperiod) + ta.stdev(close, BBperiod) * BBdeviations float BBLower = ta.sma(close, BBperiod) - ta.stdev(close, BBperiod) * BBdeviations var float TrendLine = 0.0 var int iTrend = 0 float atrForTrend = ta.atr(ATRperiod) int BBSignal = close > BBUpper ? 1 : close < BBLower ? -1 : 0 float newTrendLine = TrendLine if (BBSignal == 1) float base = UseATRfilter ? low - atrForTrend : low newTrendLine := base if (newTrendLine < TrendLine) newTrendLine := TrendLine else if (BBSignal == -1) float base = UseATRfilter ? high + atrForTrend : high newTrendLine := base if (newTrendLine > TrendLine) newTrendLine := TrendLine TrendLine := newTrendLine if (TrendLine > TrendLine[1]) iTrend := 1 else if (TrendLine < TrendLine[1]) iTrend := -1 bool buySignal = ta.crossunder(iTrend, 0) bool sellSignal = ta.crossover(iTrend, 0) var float stopLoss = na var float target = na float atrForSLT = ta.atr(ATRperiod) if buySignal stopLoss := close - (atrForSLT * stopLossMultiplier) target := close + (atrForSLT * targetMultiplier) if sellSignal stopLoss := close + (atrForSLT * stopLossMultiplier) target := close - (atrForSLT * targetMultiplier) float ema200 = ta.ema(close, 200) plot(TrendLine, color=iTrend > 0 ? color.new(color.blue, 0) : color.new(color.red, 0), style=plot.style_line, linewidth=3, title="BB Trend Line") plotshape(buySignal, text='Buy', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.white, size=size.small) plotshape(sellSignal, text='Sell', style=shape.triangledown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small) plot(buySignal or sellSignal ? stopLoss : na, "Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr) plot(buySignal or sellSignal ? target : na, "Target", color=color.green, linewidth=2, style=plot.style_linebr) plot(ema200, color=color.orange, style=plot.style_line, linewidth=2, title="200 EMA") //============================================================================== //== SECTION 2: CCI-DRIVEN SUPERTREND (Main Trend) == //============================================================================== string grp_cci = "CCI Main Trend" res = input.timeframe("D", title="Timeframe", group=grp_cci) CCI_len = input.int(3, "CCI Period", group=grp_cci) ATR_len_cci = input.int(10, "ATR Period", group=grp_cci) Multiplier_cci = input.float(1.0, "ATR Multiplier", group=grp_cci) originalColor = input.bool(false, "Use Simple CCI Color?", group=grp_cci) float cciValue = ta.cci(close, CCI_len) float atrValue = ta.atr(ATR_len_cci) float upperBand = high - Multiplier_cci * atrValue float lowerBand = low + Multiplier_cci * atrValue var float cciSuperTrend = 0.0 var int direction = 1 bool longCondition = cciValue > 0 and cciValue[1] <= 0 bool shortCondition = cciValue < 0 and cciValue[1] >= 0 if longCondition direction := 1 else if shortCondition direction := -1 if direction == 1 cciSuperTrend := math.max(nz(cciSuperTrend[1]), lowerBand) else cciSuperTrend := math.min(nz(cciSuperTrend[1]), upperBand) color trendColor = direction == 1 ? color.green : color.purple color cciBasedColor = cciValue >= 0 ? color.green : color.purple color finalColor = originalColor ? cciBasedColor : trendColor float htfx = request.security(syminfo.tickerid, res, cciSuperTrend[1], lookahead=barmerge.lookahead_on) color htfColor = request.security(syminfo.tickerid, res, finalColor[1], lookahead=barmerge.lookahead_on) plot(htfx, color=htfColor, style=plot.style_line, linewidth=5, title="CCI Main Trend") //============================================================================== //== SECTION 3: SHUKBR EMA LOGIC (converted from version 3) == //============================================================================== string grp_shukbr = "Shukbr EMA Highlight" emaLength = input.int(200, minval=1, title="Shukbr EMA Length", group=grp_shukbr) emaSource = input.source(close, title="Shukbr EMA Source", group=grp_shukbr) emaShukbr = ta.ema(emaSource, emaLength) plot(emaShukbr, color=(close[1] > emaShukbr and close > emaShukbr ? color.green : color.red), linewidth=2, title="Shukbr EMA") //============================================================================== //== SECTION 4: ALERTS == //============================================================================== alertcondition(sellSignal, title="BB Trend Sell", message="BB Trend Sell Signal") alertcondition(buySignal, title="BB Trend Buy", message="BB Trend Buy Signal") alertcondition(buySignal or sellSignal, title="BB Trend Buy/Sell", message="BB Trend Buy/Sell Signal") link

Post a Comment