Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(shorttitle='Heiken Ashi SBB with cancellation', title='SBB_cancel', overlay=true, timeframe='')
- //SETTINGS
- src = input(close, title='Source')
- length = input.int(34, minval=1, title='Bollinger Bands Length')
- len = input.int(9, minval=1, title='Trend Line Period')
- Periods = input(title='ATR Period', defval=1)
- Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=0.9)
- mult = input.float(1.750, minval=0.001, maxval=50, title='Dev')
- offset = input.int(0, 'Offset', minval=-500, maxval=500)
- changeATR = input(title='Change ATR Calculation Method ?', defval=true)
- showsignals = input(title='Show Buy/Sell Signals ?', defval=true)
- highlighting = input(title='Highlighter On/Off ?', defval=true)
- //BOLLINGER BANDS
- basis = ta.sma(src, length)
- dev = mult * ta.stdev(src, length)
- upper = basis + dev
- lower = basis - dev
- p1 = plot(upper, 'bb_upper', color=color.new(#f70606, 0), offset=offset)
- p2 = plot(lower, 'bb_lower', color=color.new(color.lime, 0), offset=offset)
- fill(p1, p2, title='RangeColor', color=color.new(color.purple, 90))
- // Plot the basis line too for completeness
- plot(basis, 'bb_basis', color=color.new(color.gray, 50), offset=offset, display=display.none)
- ////SMA
- smma = 0.0
- smma := na(smma[1]) ? ta.ema(src, len) : (smma[1] * (len - 1) + src) / len
- plot(smma, 'trend_line_smma', color=color.new(#ff9800, 0))
- //Average True Range
- atr2 = ta.sma(ta.tr, Periods)
- atr = changeATR ? ta.atr(Periods) : atr2
- up = src - Multiplier * atr
- up1 = nz(up[1], up)
- up := close[1] > up1 ? math.max(up, up1) : up
- dn = src + Multiplier * atr
- dn1 = nz(dn[1], dn)
- dn := close[1] < dn1 ? math.min(dn, dn1) : dn
- trend = 1
- trend := nz(trend[1], trend)
- trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
- //Signal Generator & Trend HighLighter
- buySignal = trend == 1 and trend[1] == -1
- sellSignal = trend == -1 and trend[1] == 1
- // Original signals (keep them)
- plotshape(buySignal and showsignals ? up : na, title='Buy', text='Buy', location=location.belowbar, style=shape.triangleup, size=size.tiny, color=color.new(color.green, 20), textcolor=color.new(#0a5500, 20))
- plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='Sell', location=location.abovebar, style=shape.triangledown, size=size.tiny, color=color.new(color.red, 20), textcolor=color.new(#530000, 0))
- // Fix the unnamed plots and add proper export-friendly names
- mPlot = plot(ohlc4, title='price_ohlc4', style=plot.style_linebr, linewidth=0, display=display.none)
- upPlot = plot(trend == 1 ? up : na, title='atr_support_line', style=plot.style_linebr, linewidth=0, color=color.new(color.green, 100))
- dnPlot = plot(trend == 1 ? na : dn, title='atr_resistance_line', style=plot.style_linebr, linewidth=0, color=color.new(color.red, 100))
- // Add additional export data with scripting-friendly names
- plot(trend, 'trend_direction', display=display.data_window)
- plot(buySignal ? 1 : 0, 'buy_signal', display=display.data_window)
- plot(sellSignal ? 1 : 0, 'sell_signal', display=display.data_window)
- plot(atr, 'atr_value', display=display.data_window)
- plot(up, 'atr_support_value', display=display.data_window)
- plot(dn, 'atr_resistance_value', display=display.data_window)
- // Add change condition for trend reversals
- changeCond = trend != trend[1]
- plot(changeCond ? 1 : 0, 'trend_change', display=display.data_window)
- // Add volatility and momentum indicators for better analysis
- plot(ta.stdev(src, length), 'bollinger_stdev', display=display.data_window)
- plot(volume, 'volume', display=display.data_window)
- longFillColor = highlighting ? trend == 1 ? color.green : color.green : color.green
- shortFillColor = highlighting ? trend == -1 ? color.red : color.red : color.red
- fill(mPlot, upPlot, title='Buying Trend Highligter', color=longFillColor, transp=70)
- fill(mPlot, dnPlot, title='Selling Trend Highligter', color=shortFillColor, transp=70)
- // FIXED GEMINI CODE - barstate.time should be just time
- varip bool live_buy_established_this_bar = false
- varip float live_buy_price_at_establishment = na
- varip bool live_sell_established_this_bar = false
- varip float live_sell_price_at_establishment = na
- varip int last_live_bar_time_processed = na
- if (barstate.isrealtime)
- // Force reset if this is a genuinely new real-time bar
- if (time != last_live_bar_time_processed)
- live_buy_established_this_bar := false
- live_sell_established_this_bar := false
- live_buy_price_at_establishment := na
- live_sell_price_at_establishment := na
- // Update the tracker to this new bar's time
- last_live_bar_time_processed := time
- if (buySignal)
- if (not live_buy_established_this_bar)
- live_buy_price_at_establishment := up
- live_buy_established_this_bar := true
- live_sell_established_this_bar := false
- live_sell_price_at_establishment := na
- // Ensure this bar's time is marked as processed for this tick
- if (barstate.isrealtime)
- last_live_bar_time_processed := time
- if (sellSignal)
- if (not live_sell_established_this_bar)
- live_sell_price_at_establishment := dn
- live_sell_established_this_bar := true
- live_buy_established_this_bar := false
- live_buy_price_at_establishment := na
- // Ensure this bar's time is marked as processed for this tick
- if (barstate.isrealtime)
- last_live_bar_time_processed := time
- bool show_live_buy_X = barstate.isrealtime and live_buy_established_this_bar and not buySignal
- bool show_live_sell_X = barstate.isrealtime and live_sell_established_this_bar and not sellSignal
- // --- Plotting for Live Bar Indelible Signals + X ---
- plotshape(live_buy_established_this_bar and showsignals and barstate.isrealtime ? live_buy_price_at_establishment : na,
- title='Live Indelible Buy', text='Buy', style=shape.triangleup,
- location=location.absolute, color=color.new(color.green, 20), textcolor=color.new(#0a5500, 20), size=size.tiny)
- plotchar(show_live_buy_X and showsignals ? live_buy_price_at_establishment : na,
- title='Live Buy Cancelled (X)', char='×',
- location=location.absolute, color=color.new(color.red, 0), size=size.small)
- plotshape(live_sell_established_this_bar and showsignals and barstate.isrealtime ? live_sell_price_at_establishment : na,
- title='Live Indelible Sell', text='Sell', style=shape.triangledown,
- location=location.absolute, color=color.new(color.red, 20), textcolor=color.new(#530000, 0), size=size.tiny)
- plotchar(show_live_sell_X and showsignals ? live_sell_price_at_establishment : na,
- title='Live Sell Cancelled (X)', char='×',
- location=location.absolute, color=color.new(color.green, 0), size=size.small)
- //Buy & Sell Alert Settings
- alertcondition(buySignal, title='Buy', message='BUY - {{ticker}}, {{interval}}, Entry={{open}}, SL={{low}}, TP={{high}}, Secure=20Pips, Make Profit=50Pips, Trade Goal=100Pips')
- alertcondition(sellSignal, title='Sell', message='SELL - {{ticker}}, {{interval}}, Entry={{open}}, SL={{high}}, TP={{low}}, Secure=20Pips, Make Profit=50Pips, Trade Goal=100Pips')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement