Super Algo
Super Algo
indicator('Super Algo Setup [Aura]', 'Super Algo + Market Sentiment V1.7', true)
//------------------------------------------------------------
// Calculations
//------------------------------------------------------------
// Function
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// RSI
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
source = close
macd_ma_fast = ta.ema(source, macd_length_fast)
macd_ma_slow = ta.ema(source, macd_length_slow)
macd = macd_ma_fast - macd_ma_slow
macd_signal = ta.ema(macd, macd_length_signal)
macd_histogram = macd - macd_signal
ema = ta.ema(source, ema_length)
length = 20
maType = "SMA"
BBsrc = close
mult = 2.0
offset = 0
basis = ma(BBsrc, length, maType)
dev = mult * ta.stdev(BBsrc, length)
upper = basis + dev
lower = basis - dev
bh = math.max(open, close)
bl = math.min(open, close)
bm = (open+close)/2
mx = math.max(high, high[1])
mn = math.min(low, low[1])
if not na(pl)
sup := pl
if not na(ph)
res := ph
// Range Calculation
ll = ta.lowest(low, a)
hh = ta.highest(high, a)
diff = hh - ll
rdiff = close - (hh + ll) / 2
level_40 = ob
level_40smi = SMIsignal > level_40 ? SMIsignal : level_40
level_m40 = os
level_m40smi = SMIsignal < level_m40 ? SMIsignal : level_m40
var pos = 0
if isB
pos := 1
if isS
pos := -1
shpUp = ta.crossover(close,upper)
shpDn = ta.crossover(close,lower)
//------------------------------------------------------------
// Outputs
//------------------------------------------------------------
plotshape(BullRev
, 'Bull Reversal'
, shape.labelup
, location.belowbar
, color.green
, 0
, 'R'
, color.white
, size = size.small
, display = display.none)
plotshape(BearRev
, 'Bear Reversal'
, shape.labeldown
, location.abovebar
, color.red
, 0
, 'R'
, color.white
, size = size.small
, display = display.none)
plot(res
, "Plot"
, res == res[1] ? resCol : na
, 1
, plot.style_line)
plot(sup
, "Plot"
, sup == sup[1] ? supCol : na
, 1
, plot.style_line)
plot(vwap
, 'VWAP'
, color.blue
, 2)
plot(pvwap
, 'Prev Day VWAP'
, color.teal
, 2
, display = display.none)
plot(supertrend
, "SuperTrend"
, direction < 0 ? color.green : color.red
, 2
, display = display.none)
barcolor(elder_color)
plotshape(exb
, 'Shapes'
, shape.xcross
, location.abovebar
, color.red
, 0
, 'Exit'
, size = size.tiny)
plotshape(exs
, 'Shapes'
, shape.xcross
, location.belowbar
, color.red
, 0
, 'Exit'
, size = size.tiny)
plotshape(bsl
, 'Buy SL'
, shape.xcross
, location.belowbar
, color.red
, 0
, 'SL'
, size = size.tiny
, editable = false)
plotshape(ssl
, 'Sell SL'
, shape.xcross
, location.abovebar
, color.red
, 0
, 'SL'
, size = size.tiny
, editable = false)
plot(pdh
, "Previous Day High"
, #ff0000
, 2
, display = display.none)
plot(pdl
, "Previous Day Low"
, #13d71a
, 2
, display = display.none)
if isB
Blb.push(label.new(bar_index
, low
, slt1
, xloc.bar_index
, color = color.rgb(1,154,6)
, textcolor = color.white
, style = label.style_label_up
, size = size.normal))
if isS
Slb.push(label.new(bar_index
, high
, slt2
, xloc.bar_index
, color = color.rgb(187,5,5)
, textcolor = color.white
, style = label.style_label_down
, size = size.normal))
if not hist
if Blb.size() > 5
label.delete(Blb.shift())
if Slb.size() > 5
label.delete(Slb.shift())
// Alerts
alertcondition(isB, "BUY Alert", "BUY Alert", alert.freq_once_per_bar_close)
alertcondition(isS, "SELL Alert", "SELL Alert", alert.freq_once_per_bar_close)
if show
ln.delete()
lb.delete()
ln := line.new(bar_index, y , bar_index + 5, y ,
color = css , style = line.style_dotted , width = 2)
if ext
ln.set_x2(bar_index + 5)
if isB or isS
Tg1 := En0 + k * 2.618 * Risk
Tg2 := En0 + k * 3.618 * Risk
Tg3 := En0 + k * 5.236 * Risk
last_signal := 'buy'
last_signal := 'sell'
// Book profit labels based on ATR, only plot once
if not na(buy_entry_price) and not buy_label_plotted
buy_profit_target = buy_entry_price + atr_multiplier * atr_value
if close >= buy_profit_target
label.new(bar_index, high, "Book Profit", color=color.blue,
style=label.style_label_down, textcolor=color.white, size=size.small)
buy_label_plotted := true // Mark label as plotted
//------------------------------------------------------------
//------------------------------------------------------------
//------------------------------------------------------------
getVolume(tf) =>
priceDiff = close - open
buyVol = request.security(syminfo.tickerid, tf, priceDiff > 0 ? volume : 0)
sellVol = request.security(syminfo.tickerid, tf, priceDiff < 0 ? volume : 0)
netVol = buyVol - sellVol
diff = buyVol + sellVol != 0 ? (netVol / (buyVol + sellVol)) * 100 : na
sentiment = diff > 0 ? "Bullish" : diff < 0 ? "Bearish" : "Neutral"
[buyVol, sellVol, netVol, diff, sentiment]
// Timeframes
[bv5, sv5, nv5, df5, st5] = getVolume("5")
[bv15, sv15, nv15, df15, st15] = getVolume("15")
[bv30, sv30, nv30, df30, st30] = getVolume("30")
[bv60, sv60, nv60, df60, st60] = getVolume("60")
[bv240, sv240, nv240, df240, st240] = getVolume("240")
[bvD, svD, nvD, dfD, stD] = getVolume("D")
// Totals
totalBuy = bv5 + bv15 + bv30 + bv60 + bv240 + bvD
totalSell = sv5 + sv15 + sv30 + sv60 + sv240 + svD
totalNet = totalBuy - totalSell
totalDiff = totalBuy + totalSell != 0 ? (totalNet / (totalBuy + totalSell)) * 100 :
na
overallSent = totalDiff > 0 ? "Bullish" : totalDiff < 0 ? "Bearish" : "Neutral"
// Table
var table t = table.new(position.top_right, 6, 8, border_width=1)
// Update table
table.clear(t, 0, 0)
// Header
headerBg = color.new(#263238, 0)
table.cell(t, 0, 0, "TF", bgcolor=headerBg, text_color=color.white)
table.cell(t, 1, 0, "Buy", bgcolor=headerBg, text_color=color.white)
table.cell(t, 2, 0, "Sell", bgcolor=headerBg, text_color=color.white)
table.cell(t, 3, 0, "Net", bgcolor=headerBg, text_color=color.white)
table.cell(t, 4, 0, "Diff%", bgcolor=headerBg, text_color=color.white)
table.cell(t, 5, 0, "Sentiment", bgcolor=headerBg, text_color=color.white)
// Data rows
showRow(1, "5min", bv5, sv5, nv5, df5, st5)
showRow(2, "15min", bv15, sv15, nv15, df15, st15)
showRow(3, "30min", bv30, sv30, nv30, df30, st30)
showRow(4, "1h", bv60, sv60, nv60, df60, st60)
showRow(5, "4h", bv240, sv240, nv240, df240, st240)
showRow(6, "1d", bvD, svD, nvD, dfD, stD)
// =============================================
// Part 3: Zero Lag Trend Signals (Tight to Candles)
// =============================================
length_zlt = input.int(70, "Length", group="Zero Lag Trend Signals")
mult_zlt = input.float(1.2, "Band Multiplier", group="Zero Lag Trend Signals")
green_zlt = input.color(#002aff, "Bullish Color", group="Zero Lag Trend Signals")
red_zlt = input.color(#002aff, "Bearish Color", group="Zero Lag Trend Signals")
src_zlt = close
lag_zlt = math.floor((length_zlt - 1) / 2)
zlema = ta.ema(src_zlt + (src_zlt - src_zlt[lag_zlt]), length_zlt)
volatility = ta.highest(ta.atr(length_zlt), length_zlt*3) * mult_zlt
var trend = 0
if ta.crossover(close, zlema+volatility)
trend := 1
if ta.crossunder(close, zlema-volatility)
trend := -1