Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Your Name Here - Emerald Trading Assistant
- //@version=5
- indicator("Emerald Trading Assistant", shorttitle="ETA", overlay=true,
- max_labels_count=500, max_lines_count=500, max_bars_back=5000)
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── INPUT GROUPS ──────
- // ════════════════════════════════════════════════════════════════════════════════
- string g_fibo = "Fibonacci & Volume Profile"
- string g_fvg = "FVG / Imbalance Settings"
- string g_paa = "PAA Pivot Settings"
- string g_volume = "Volume Analysis"
- string g_rejection = "Rejection Candles"
- string g_liquidity = "Liquidity Grabs"
- string g_trend = "Trend Analysis"
- string g_vwap = "VWAP Settings"
- string g_display = "Display Options"
- string g_risk = "Risk Management"
- string g_alerts = "Alert Settings"
- // --- Fibo & VP Settings ---
- string fibo_timeframe = input.timeframe("D", title="Fibo Timeframe", group=g_fibo, options=["120", "240", "480", "720", "D", "W", "M"], tooltip="Higher timeframe for calculating Fibonacci levels.")
- float fibo_thickness = input.float(0.05, "Fibo Level Thickness (ATR %)", minval=0.01, maxval=1.0, step=0.01, group=g_fibo, tooltip="Controls the thickness of the Fibo levels as a percentage of the 30-period ATR. Smaller value = thinner.")
- string vp_vol_type = input.string("All", title="VP Volume Type", group=g_fibo, options=["Bear", "Bull", "All"], tooltip="Choose Volume Type to Show in Boxes")
- int vp_levels = input.int(12, "VP Volume Levels", group=g_fibo)
- bool show_fibo_levels = input.bool(true, "Show Fibo Levels?", inline="fibo_vis", group=g_fibo)
- bool show_fibo_target = input.bool(true, "Show Fibo Target?", inline="fibo_vis", group=g_fibo)
- bool show_vp = input.bool(false, "Show Volume Profile?", inline="vp_vis", group=g_fibo)
- bool show_poc = input.bool(true, "Show POC?", inline="vp_vis", group=g_fibo)
- float vp_width = input.float(20, "VP Width (%)", minval=1, maxval=100, group=g_fibo)
- int vp_offset = input.int(5, "VP Horizontal Offset", minval=0, group=g_fibo, tooltip="Positions the profile X bars to the RIGHT of the last candle.")
- // --- FVG Settings ---
- bool fvg_show = input.bool(true, "Show FVGs?", group=g_fvg, inline="fvg1")
- int fvg_max_count = input.int(10, "Max FVGs to Show", minval=1, maxval=50, group=g_fvg, inline="fvg1")
- int fvg_max_len = input.int(80, "Max FVG Length (Bars)", minval=0, group=g_fvg, tooltip="Sets the maximum bars an FVG will extend. 0 = Indefinite.")
- float fvg_min_atr_size = input.float(25.0, "Min FVG Size (% of ATR)", minval=0.0, step=5.0, group=g_fvg, tooltip="Filters out small FVGs. Size must be at least this % of the 14-period ATR to be shown.")
- string fvg_htf = input.timeframe("60", "FVG Higher Timeframe (HTF)", group=g_fvg, tooltip="MUST be a higher timeframe than the chart's.")
- color fvg_bull_color = input.color(color.new(color.blue, 85), "Bullish", group=g_fvg, inline="fvgcolor")
- color fvg_bear_color = input.color(color.new(color.red, 85), "Bearish", group=g_fvg, inline="fvgcolor")
- bool fvg_show_partial_fill = input.bool(true, "Show Partial Fills?", group=g_fvg)
- float fvg_lv_atr_mult = input.float(2.0, "Large FVG ATR Multiplier", minval=0.1, group=g_fvg)
- // --- PAA Pivot Settings ---
- int paa_lookback = input.int(15, "PAA Pivot Lookback", minval=5, maxval=50, group=g_paa)
- bool show_paa_pivots = input.bool(true, "Show PAA Pivots", group=g_paa)
- bool paa_extend_lines = input.bool(false, "Extend PAA Lines", group=g_paa)
- int paa_valid_bars = input.int(30, "Max Bars to Keep PAA Levels", minval=10, maxval=100, group=g_paa)
- // --- Volume Analysis Settings ---
- int vol_len = input.int(20, "Average Volume Length", minval=5, maxval=100, group=g_volume)
- float hiVolMult = input.float(1.5, "High Volume Multiplier", minval=1.0, maxval=5.0, step=0.1, group=g_volume)
- float ultraVolMult = input.float(2.5, "Ultra Volume Multiplier", minval=1.5, maxval=10.0, step=0.1, group=g_volume)
- int cvdSmoothLen = input.int(3, "CVD Smoothing Length", minval=1, maxval=20, group=g_volume)
- // --- Rejection Candle Settings ---
- float rejWickMin = input.float(0.60, "Min Rejection Wick (% of bar)", minval=0.1, maxval=0.9, step=0.05, group=g_rejection)
- float rejBodyMax = input.float(0.30, "Max Body Size (% of bar)", minval=0.05, maxval=0.5, step=0.05, group=g_rejection)
- bool enable_rejection = input.bool(true, "Enable Rejection Analysis", group=g_rejection)
- // --- Liquidity Grab Settings ---
- int liqLookback = input.int(5, "Liquidity Lookback Period", minval=3, maxval=20, group=g_liquidity)
- int liqReclaimBars = input.int(2, "Bars to Reclaim Level", minval=1, maxval=10, group=g_liquidity)
- bool enable_liquidity = input.bool(true, "Enable Liquidity Analysis", group=g_liquidity)
- // --- Trend Analysis Settings ---
- bool trend_filter = input.bool(true, "Enable Trend Filter", group=g_trend)
- bool show_trend_bgcolor = input.bool(false, "Show Trend Background Color", group=g_trend)
- int ema_len = input.int(50, "EMA Length", minval=10, maxval=200, group=g_trend)
- // --- VWAP Settings ---
- int length_vwap = input.int(20, "Rolling VWAP Length", minval=5, maxval=200, group=g_vwap)
- bool show_session_vwap = input.bool(true, "Show Session VWAP", group=g_vwap)
- bool show_rolling_vwap = input.bool(true, "Show Rolling VWAP", group=g_vwap)
- // --- Display Settings ---
- bool show_a_grade_labels = input.bool(true, "Show A-Grade Labels", group=g_display)
- bool show_b_grade_labels = input.bool(true, "Show B-Grade Labels", group=g_display)
- bool show_c_grade_labels = input.bool(false, "Show C-Grade Labels", group=g_display)
- int label_offset = input.int(0, "Label Offset", minval=-10, maxval=10, group=g_display)
- bool show_dashboard = input.bool(true, "Show Info Dashboard", group=g_display)
- // --- Risk Management Settings ---
- bool show_risk_labels = input.bool(true, "Show Risk/Reward Labels", group=g_risk)
- float sl_atr_mult = input.float(1.0, "Stop Loss ATR Multiplier", minval=0.1, step=0.1, group=g_risk, tooltip="Sets the Stop Loss distance. E.g., a value of 1.0 places the SL 1 ATR away from the signal candle's high/low.")
- float rr_ratio_1 = input.float(1.0, "Target 1 R:R", minval=0.5, step=0.5, group=g_risk)
- float rr_ratio_2 = input.float(2.0, "Target 2 R:R", minval=0.5, step=0.5, group=g_risk)
- float rr_ratio_3 = input.float(3.0, "Target 3 R:R", minval=0.5, step=0.5, group=g_risk)
- // --- Alert Settings ---
- bool alert_a_setups = input.bool(true, "Alert A-Grade Setups", group=g_alerts)
- bool alert_b_setups = input.bool(true, "Alert B-Grade Setups", group=g_alerts)
- bool alert_c_setups = input.bool(false, "Alert C-Grade Setups", group=g_alerts)
- bool pre_alert = input.bool(true, "Early Setup Alerts", group=g_alerts)
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── ADVANCED FVG SYSTEM (PORTED) ──────
- // ════════════════════════════════════════════════════════════════════════════════
- type fvgObject
- bool isBullish
- bool isLV
- float top
- float bottom
- int startTime
- string tfType
- float currentTop
- float currentBottom
- var string TF_TYPE_LTF = "LTF"
- var string TF_TYPE_HTF = "HTF"
- f_detectFvg(currentAtr) =>
- fvgObject fvg = na
- bool isFvgFound = false
- float minSize = currentAtr * (fvg_min_atr_size / 100.0)
- if low > high[2] and barstate.isconfirmed and (low - high[2]) >= minSize
- isFvgFound := true
- fvg := fvgObject.new()
- fvg.isBullish := true
- fvg.top := low
- fvg.bottom := high[2]
- fvg.startTime := time[2]
- fvg.tfType := TF_TYPE_LTF
- fvg.currentTop := fvg.top
- fvg.currentBottom := fvg.bottom
- fvg.isLV := (fvg.top - fvg.bottom) / currentAtr >= fvg_lv_atr_mult
- else if high < low[2] and barstate.isconfirmed and (low[2] - high) >= minSize
- isFvgFound := true
- fvg := fvgObject.new()
- fvg.isBullish := false
- fvg.top := low[2]
- fvg.bottom := high
- fvg.startTime := time[2]
- fvg.tfType := TF_TYPE_LTF
- fvg.currentTop := fvg.top
- fvg.currentBottom := fvg.bottom
- fvg.isLV := (fvg.top - fvg.bottom) / currentAtr >= fvg_lv_atr_mult
- [isFvgFound, fvg]
- f_detectMultiTFFvg(htfHigh1, htfLow1, htfTime1, htfHigh3, htfLow3, htfTime3, tfAtr) =>
- fvgObject fvg = na
- bool isFvgFound = false
- float minSize = tfAtr * (fvg_min_atr_size / 100.0)
- if not na(htfTime1) and not na(htfTime3)
- if not na(htfLow1) and not na(htfHigh3) and htfLow1 > htfHigh3 and (htfLow1 - htfHigh3) >= minSize
- isFvgFound := true
- fvg := fvgObject.new()
- fvg.isBullish := true
- fvg.top := htfLow1
- fvg.bottom := htfHigh3
- fvg.startTime := int(htfTime3)
- fvg.tfType := TF_TYPE_HTF
- fvg.currentTop := fvg.top
- fvg.currentBottom := fvg.bottom
- fvg.isLV := (fvg.top - fvg.bottom) / tfAtr >= fvg_lv_atr_mult
- else if not na(htfHigh1) and not na(htfLow3) and htfHigh1 < htfLow3 and (htfLow3 - htfHigh1) >= minSize
- isFvgFound := true
- fvg := fvgObject.new()
- fvg.isBullish := false
- fvg.top := htfLow3
- fvg.bottom := htfHigh1
- fvg.startTime := int(htfTime3)
- fvg.tfType := TF_TYPE_HTF
- fvg.currentTop := fvg.top
- fvg.currentBottom := fvg.bottom
- fvg.isLV := (fvg.top - fvg.bottom) / tfAtr >= fvg_lv_atr_mult
- [isFvgFound, fvg]
- f_checkMitigation(isBullish, fvgTop, fvgBottom) => (isBullish and low <= fvgBottom) or (not isBullish and high >= fvgTop)
- f_checkPartialMitigation(isBullish, cTop, cBot) =>
- float newLevel = na
- if isBullish and not na(cTop) and low < cTop
- newLevel := low
- else if not isBullish and not na(cBot) and high > cBot
- newLevel := high
- newLevel
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── GLOBAL VARIABLES & CORE CALCULATIONS ──────
- // ════════════════════════════════════════════════════════════════════════════════
- var fvgs = array.new<fvgObject>()
- var fvgBoxes = array.new<box>()
- var fvgMidLines = array.new<line>()
- var Fibo = array.new_float(6, 0.0)
- var vpBoxes = array.new<box>()
- var fiboBoxes = array.new<box>()
- var box pocBox = na
- var line paa_high_line = line.new(na, na, na, na, color=color.new(color.red, 70), style=line.style_dashed, width=1)
- var label paa_high_label = label.new(na, na, "", color=color.new(color.red, 90), textcolor=color.white, style=label.style_label_down, size=size.tiny)
- var line paa_low_line = line.new(na, na, na, na, color=color.new(color.green, 70), style=line.style_dashed, width=1)
- var label paa_low_label = label.new(na, na, "", color=color.new(color.green, 90), textcolor=color.white, style=label.style_label_up, size=size.tiny)
- var int newWeekBarIndex = na
- var int newWeekTIME = na
- string weeklyTF = timeframe.isdwm ? "M" : "W"
- bool weekChange = timeframe.change(weeklyTF)
- if weekChange
- newWeekBarIndex := bar_index
- newWeekTIME := time
- float ltfAtr = ta.atr(14)
- float fiboAtr = ta.atr(30)
- bool isHtfValid = timeframe.in_seconds(fvg_htf) > timeframe.in_seconds(timeframe.period)
- float htfAtr = request.security(syminfo.tickerid, fvg_htf, ltfAtr)
- [htfHigh1, htfLow1, htfTime1, htfHigh3, htfLow3, htfTime3] = request.security(syminfo.tickerid, fvg_htf, [high[1], low[1], time[1], high[3], low[3], time[3]], lookahead=barmerge.lookahead_on)
- float FH = request.security(syminfo.tickerid, fibo_timeframe, high[1])
- float FL = request.security(syminfo.tickerid, fibo_timeframe, low[1])
- float FC = request.security(syminfo.tickerid, fibo_timeframe, close[1])
- float ema = ta.ema(close, ema_len)
- bool uptrend = trend_filter ? close > ema : true
- bool downtrend = trend_filter ? close < ema : true
- float session_vwap = ta.vwap(hlc3)
- float rolling_vwap = ta.sma(hlc3 * volume, length_vwap) / ta.sma(volume, length_vwap)
- float avg_volume = ta.sma(volume, vol_len)
- bool high_volume = volume > avg_volume * hiVolMult
- bool ultra_volume = volume > avg_volume * ultraVolMult
- float volume_percentile = ta.percentrank(volume, vol_len * 2)
- float pivot_high_price = ta.pivothigh(high, paa_lookback, paa_lookback)
- float pivot_low_price = ta.pivotlow(low, paa_lookback, paa_lookback)
- bool is_high_volume_pivot = high_volume[paa_lookback]
- var float paa_high = na
- var float paa_low = na
- var int paa_high_bar = na
- var int paa_low_bar = na
- var float paa_high_vol = na
- var float paa_low_vol = na
- if not na(pivot_high_price) and is_high_volume_pivot
- paa_high := pivot_high_price
- paa_high_bar := bar_index - paa_lookback
- paa_high_vol := volume[paa_lookback]
- if not na(pivot_low_price) and is_high_volume_pivot
- paa_low := pivot_low_price
- paa_low_bar := bar_index - paa_lookback
- paa_low_vol := volume[paa_lookback]
- var float cvd = 0.0
- float price_range = high - low
- float delta = price_range > 0 ? volume * (close - open) / price_range : 0
- cvd += delta
- float cvd_smooth = ta.ema(cvd, cvdSmoothLen)
- float bar_range = high - low
- float upper_wick = high - math.max(open, close)
- float lower_wick = math.min(open, close) - low
- float body_size = math.abs(close - open)
- bool is_bullish_rejection = enable_rejection and bar_range > 0 and (lower_wick/bar_range >= rejWickMin) and (body_size/bar_range <= rejBodyMax) and (close > open) and high_volume
- bool is_bearish_rejection = enable_rejection and bar_range > 0 and (upper_wick/bar_range >= rejWickMin) and (body_size/bar_range <= rejBodyMax) and (close < open) and high_volume
- float lookback_low = ta.lowest(low, liqLookback)[1]
- float lookback_high = ta.highest(high, liqLookback)[1]
- bool bullish_liquidity = enable_liquidity and low < lookback_low and close > lookback_low and (ta.barssince(close > lookback_low) <= liqReclaimBars) and (is_bullish_rejection or ultra_volume) and close > open
- bool bearish_liquidity = enable_liquidity and high > lookback_high and close < lookback_high and (ta.barssince(close < lookback_high) <= liqReclaimBars) and (is_bearish_rejection or ultra_volume) and close < open
- bool at_paa_low = not na(paa_low) and low <= paa_low * 1.002 and high >= paa_low * 0.998 and bar_index - paa_low_bar <= paa_valid_bars
- bool at_paa_high = not na(paa_high) and high >= paa_high * 0.998 and low <= paa_high * 1.002 and bar_index - paa_high_bar <= paa_valid_bars
- bool above_session_vwap = close > session_vwap
- bool above_rolling_vwap = close > rolling_vwap
- bool vwap_bullish_confluence = above_session_vwap and above_rolling_vwap
- bool vwap_bearish_confluence = not above_session_vwap and not above_rolling_vwap
- [ema5m_close, ema5m_ema] = request.security(syminfo.tickerid, "5", [close, ta.ema(close, ema_len)])
- [ema15m_close, ema15m_ema] = request.security(syminfo.tickerid, "15", [close, ta.ema(close, ema_len)])
- [ema1h_close, ema1h_ema] = request.security(syminfo.tickerid, "60", [close, ta.ema(close, ema_len)])
- [ema4h_close, ema4h_ema] = request.security(syminfo.tickerid, "240", [close, ta.ema(close, ema_len)])
- bool is_5m_bull = ema5m_close > ema5m_ema
- bool is_15m_bull = ema15m_close > ema15m_ema
- bool is_1h_bull = ema1h_close > ema1h_ema
- bool is_4h_bull = ema4h_close > ema4h_ema
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── FVG LOGIC (RUNS ON EVERY BAR) ──────
- // ════════════════════════════════════════════════════════════════════════════════
- if fvg_show
- [isLtfFvg, ltfFvg] = f_detectFvg(ltfAtr)
- if isLtfFvg
- array.push(fvgs, ltfFvg)
- array.push(fvgBoxes, box.new(na, na, na, na, xloc=xloc.bar_time))
- array.push(fvgMidLines, line.new(na, na, na, na, xloc=xloc.bar_time, style=line.style_solid))
- if isHtfValid and not na(htfTime1) and (na(htfTime1[1]) or htfTime1 != htfTime1[1])
- [isHtfFvg, htfFvg] = f_detectMultiTFFvg(htfHigh1, htfLow1, htfTime1, htfHigh3, htfLow3, htfTime3, htfAtr)
- if isHtfFvg
- array.push(fvgs, htfFvg)
- array.push(fvgBoxes, box.new(na, na, na, na, xloc=xloc.bar_time))
- array.push(fvgMidLines, line.new(na, na, na, na, xloc=xloc.bar_time, style=line.style_solid))
- if array.size(fvgs) > 0
- for i = array.size(fvgs) - 1 to 0
- fvgObject fvg = array.get(fvgs, i)
- box b = array.get(fvgBoxes, i)
- line l = array.get(fvgMidLines, i)
- bool isExpired = fvg_max_len > 0 and time > (fvg.startTime + fvg_max_len * timeframe.in_seconds(timeframe.period) * 1000)
- if f_checkMitigation(fvg.isBullish, fvg.top, fvg.bottom) or isExpired
- box.delete(b)
- line.delete(l)
- array.remove(fvgBoxes, i)
- array.remove(fvgMidLines, i)
- array.remove(fvgs, i)
- continue
- if fvg_show_partial_fill
- float newLevel = f_checkPartialMitigation(fvg.isBullish, fvg.currentTop, fvg.currentBottom)
- if not na(newLevel)
- if fvg.isBullish
- fvg.currentTop := newLevel
- else
- fvg.currentBottom := newLevel
- color boxColor = fvg.isBullish ? fvg_bull_color : fvg_bear_color
- color borderColor = fvg.isBullish ? color.new(color.blue, 85) : color.new(color.red, 85)
- color midlineColor = fvg.isBullish ? color.new(color.blue, 70) : color.new(color.red, 70)
- color finalBorderColor = fvg.isLV ? color.new(color.yellow, 20) : borderColor
- color finalMidlineColor = fvg.isLV ? color.new(color.yellow, 20) : midlineColor
- int rightTime = fvg_max_len > 0 ? fvg.startTime + fvg_max_len * timeframe.in_seconds(timeframe.period) * 1000 : time + 500 * timeframe.in_seconds(timeframe.period) * 1000
- box.set_left(b, fvg.startTime)
- box.set_top(b, fvg.currentTop)
- box.set_bottom(b, fvg.currentBottom)
- box.set_right(b, rightTime)
- box.set_bgcolor(b, boxColor)
- box.set_border_color(b, finalBorderColor)
- box.set_border_width(b, fvg.isLV ? 2 : 1)
- if fvg_max_len == 0
- box.set_extend(b, extend.right)
- float midY = (fvg.currentTop + fvg.currentBottom) / 2
- line.set_xy1(l, fvg.startTime, midY)
- line.set_xy2(l, rightTime, midY)
- line.set_color(l, finalMidlineColor)
- if fvg_max_len == 0
- line.set_extend(l, extend.right)
- while array.size(fvgs) > fvg_max_count
- box.delete(array.shift(fvgBoxes))
- line.delete(array.shift(fvgMidLines))
- array.shift(fvgs)
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── SETUP GRADING SYSTEM ──────
- // ════════════════════════════════════════════════════════════════════════════════
- bool long_trend_ok = uptrend
- bool long_location_ok = at_paa_low
- bool long_rejection_ok = is_bullish_rejection
- bool long_liquidity_ok = bullish_liquidity
- bool short_trend_ok = downtrend
- bool short_location_ok = at_paa_high
- bool short_rejection_ok = is_bearish_rejection
- bool short_liquidity_ok = bearish_liquidity
- bool long_strong_confirmation = long_rejection_ok or long_liquidity_ok
- bool short_strong_confirmation = short_rejection_ok or short_liquidity_ok
- bool a_grade_long = long_trend_ok and long_location_ok and long_strong_confirmation
- bool a_grade_short = short_trend_ok and short_location_ok and short_strong_confirmation
- bool b_grade_long_1 = long_trend_ok and long_location_ok and (high_volume or vwap_bullish_confluence)
- bool b_grade_long_2 = long_trend_ok and long_strong_confirmation and not long_location_ok
- bool b_grade_long = (b_grade_long_1 or b_grade_long_2) and not a_grade_long
- bool b_grade_short_1 = short_trend_ok and short_location_ok and (high_volume or vwap_bearish_confluence)
- bool b_grade_short_2 = short_trend_ok and short_strong_confirmation and not short_location_ok
- bool b_grade_short = (b_grade_short_1 or b_grade_short_2) and not a_grade_short
- bool c_grade_long = long_trend_ok and high_volume and vwap_bullish_confluence and not (a_grade_long or b_grade_long)
- bool c_grade_short = short_trend_ok and high_volume and vwap_bearish_confluence and not (a_grade_short or b_grade_short)
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── VISUALIZATION (PLOTS, GRADES, LABELS) ──────
- // ════════════════════════════════════════════════════════════════════════════════
- plot(show_session_vwap ? session_vwap : na, "Session VWAP", color=color.new(#2962FF, 0), linewidth=2)
- plot(show_rolling_vwap ? rolling_vwap : na, "Rolling VWAP", color=color.new(#00BFA5, 40), linewidth=1)
- plotshape(show_paa_pivots and not na(pivot_high_price), "PAA High", shape.triangledown, location.abovebar, color.new(color.red, 40), size=size.small, offset=-paa_lookback)
- plotshape(show_paa_pivots and not na(pivot_low_price), "PAA Low", shape.triangleup, location.belowbar, color.new(color.green, 40), size=size.small, offset=-paa_lookback)
- plot(trend_filter ? ema : na, "Trend EMA", color=uptrend ? color.new(color.green, 80) : color.new(color.red, 80), linewidth=2)
- bgcolor(trend_filter and show_trend_bgcolor ? (uptrend ? color.new(color.green, 95) : color.new(color.red, 95)) : na)
- f_draw_paa_level(bar_pos, price, vol, is_valid, line_obj, label_obj) =>
- if is_valid and show_paa_pivots
- line.set_xy1(line_obj, bar_pos, price)
- line.set_xy2(line_obj, bar_index, price)
- label.set_xy(label_obj, bar_pos, price)
- label.set_text(label_obj, "Vol: " + str.tostring(vol, "#.##"))
- else
- line.set_xy1(line_obj, na, na)
- line.set_xy2(line_obj, na, na)
- label.set_xy(label_obj, na, na)
- if paa_extend_lines
- f_draw_paa_level(paa_high_bar, paa_high, paa_high_vol, bar_index - paa_high_bar < paa_valid_bars, paa_high_line, paa_high_label)
- f_draw_paa_level(paa_low_bar, paa_low, paa_low_vol, bar_index - paa_low_bar < paa_valid_bars, paa_low_line, paa_low_label)
- plotshape(show_a_grade_labels and a_grade_long, "A-Long", shape.labelup, location.belowbar, color.new(#00C853, 0), text="A+", textcolor=color.white, size=size.normal, offset=label_offset)
- plotshape(show_a_grade_labels and a_grade_short, "A-Short", shape.labeldown, location.abovebar, color.new(#D50000, 0), text="A+", textcolor=color.white, size=size.normal, offset=label_offset)
- plotshape(show_b_grade_labels and b_grade_long, "B-Long", shape.labelup, location.belowbar, color.new(#64DD17, 0), text="B", textcolor=color.black, size=size.small, offset=label_offset)
- plotshape(show_b_grade_labels and b_grade_short, "B-Short", shape.labeldown, location.abovebar, color.new(#FF6D00, 0), text="B", textcolor=color.white, size=size.small, offset=label_offset)
- plotshape(show_c_grade_labels and c_grade_long, "C-Long", shape.triangleup, location.belowbar, color.new(color.green, 70), size=size.tiny, offset=label_offset)
- plotshape(show_c_grade_labels and c_grade_short, "C-Short", shape.triangledown, location.abovebar, color.new(color.red, 70), size=size.tiny, offset=label_offset)
- if show_risk_labels
- if a_grade_long or b_grade_long
- float stop_loss = low - (ltfAtr * sl_atr_mult)
- float entry_price = close
- float risk = entry_price - stop_loss
- if risk > 0
- float tp1 = entry_price + risk * rr_ratio_1
- label.new(bar_index, low - ta.tr, "SL: "+str.tostring(stop_loss,"#.##")+"\nTP1: "+str.tostring(tp1,"#.##"), style=label.style_label_up, color=color.new(#263238, 20), textcolor=color.white)
- if a_grade_short or b_grade_short
- float stop_loss = high + (ltfAtr * sl_atr_mult)
- float entry_price = close
- float risk = stop_loss - entry_price
- if risk > 0
- float tp1 = entry_price - risk * rr_ratio_1
- label.new(bar_index, high + ta.tr, "SL: "+str.tostring(stop_loss,"#.##")+"\nTP1: "+str.tostring(tp1,"#.##"), style=label.style_label_down, color=color.new(#263238, 20), textcolor=color.white)
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── LAST BAR LOGIC (FIBO, VP, DASHBOARD) ──────
- // ════════════════════════════════════════════════════════════════════════════════
- if barstate.islast
- float band = fiboAtr * fibo_thickness
- float PP = (FH + FL + FC) / 3
- array.set(Fibo, 0, PP + 0.382 * (FH - FL))
- array.set(Fibo, 1, PP - 0.382 * (FH - FL))
- array.set(Fibo, 2, PP + 0.618 * (FH - FL))
- array.set(Fibo, 3, PP - 0.618 * (FH - FL))
- array.set(Fibo, 4, PP + (FH - FL))
- array.set(Fibo, 5, PP - (FH - FL))
- float FT = array.get(Fibo, 4)
- float FB = array.get(Fibo, 5)
- int BAR1 = na(newWeekBarIndex) ? bar_index : math.min(bar_index - newWeekBarIndex, 4998)
- if BAR1 > 0
- float[] VPlevels = array.new_float(vp_levels + 1)
- float step = (FT - FB) / vp_levels
- for i = 0 to vp_levels by 1
- array.set(VPlevels, i, FB + step * i)
- float[] Volumes = array.new_float(vp_levels, 0.0)
- float[] BUllV = array.new_float(vp_levels, 0.0)
- float[] BEARV = array.new_float(vp_levels, 0.0)
- float totalGreenVol = 0.0
- float totalRedVol = 0.0
- float totalVol = 0.0
- for i = 0 to BAR1
- float close_i = close[i]
- float open_i = open[i]
- float volume_i = nz(volume[i])
- for x = 0 to vp_levels - 1
- if close_i > array.get(VPlevels, x) and close_i < array.get(VPlevels, x + 1)
- array.set(Volumes, x, array.get(Volumes, x) + volume_i)
- if close_i > open_i
- array.set(BUllV, x, array.get(BUllV, x) + volume_i)
- else
- array.set(BEARV, x, array.get(BEARV, x) + volume_i)
- break
- if close_i > open_i
- totalGreenVol += volume_i
- else
- totalRedVol += volume_i
- totalVol += volume_i
- float GR = totalVol > 0 ? totalGreenVol / totalVol : 0
- float RR = totalVol > 0 ? totalRedVol / totalVol : 0
- if array.size(fiboBoxes) > 0
- for i=0 to array.size(fiboBoxes)-1
- box.delete(array.get(fiboBoxes, i))
- array.clear(fiboBoxes)
- box.delete(pocBox)
- if show_fibo_levels
- for i = 0 to 5
- bool C = i == 0 or i == 2 or i == 4
- color fiboColor = C ? color.new(color.red,85) : color.new(color.blue,85)
- color fiboBorderColor = C ? color.new(color.red,60) : color.new(color.blue,60)
- array.push(fiboBoxes, box.new(newWeekTIME, array.get(Fibo, i) + band, time, array.get(Fibo, i) - band, bgcolor=fiboColor, border_color=fiboBorderColor, xloc=xloc.bar_time, extend=extend.right))
- if show_vp
- if array.size(vpBoxes) > 0
- for i = 0 to array.size(vpBoxes) - 1
- box.delete(array.get(vpBoxes, i))
- array.clear(vpBoxes)
- int profileStartTime = time + (vp_offset * timeframe.in_seconds(timeframe.period) * 1000)
- float max_volume = array.max(Volumes) > 0 ? array.max(Volumes) : 1
- float maxProfileWidthInBars = BAR1 * (vp_width / 100.0)
- for i = 0 to vp_levels - 1
- string str = vp_vol_type == "All" ? str.tostring(array.get(Volumes, i), format.volume) : vp_vol_type == "Bear" ? str.tostring(array.get(BEARV, i), format.volume) : str.tostring(array.get(BUllV, i), format.volume)
- float current_volume = array.get(Volumes, i)
- float barWidthInBars = (current_volume / max_volume) * maxProfileWidthInBars
- int barWidthMs = math.round(barWidthInBars * timeframe.in_seconds(timeframe.period) * 1000)
- color vpColor = color.from_gradient(current_volume, 0, max_volume, color.new(color.red,75), color.new(color.green,75))
- array.push(vpBoxes, box.new(profileStartTime, array.get(VPlevels, i + 1), profileStartTime + barWidthMs, array.get(VPlevels, i), xloc=xloc.bar_time, border_color=na, bgcolor=vpColor, text=str, text_color=color.white, text_size=size.tiny, text_halign=text.align_left))
- if show_poc
- int MaxVID = array.indexof(Volumes, array.max(Volumes))
- pocBox := box.new(newWeekTIME, VPlevels.get(MaxVID) + band, time, VPlevels.get(MaxVID + 1) + band, #e0f2e93a, border_style=line.style_solid, bgcolor=color.new(#586161, 75), text="POC", text_color=chart.fg_color, text_halign=text.align_center, text_valign=text.align_center, xloc=xloc.bar_time, extend=extend.right)
- var line targetLine = na
- var label targetLabel = na
- line.delete(targetLine)
- label.delete(targetLabel)
- if (close < FT) and (close > FB) and show_fibo_target
- float targetY = na
- color targetColor = na
- if GR > RR
- if close > (FB + FT) / 2
- targetY := array.get(Fibo, 2)
- else
- targetY := array.get(Fibo, 0)
- targetColor := color.new(color.green, 20)
- else
- if close > (FB + FT) / 2
- targetY := array.get(Fibo, 1)
- else
- targetY := array.get(Fibo, 3)
- targetColor := color.new(color.red, 20)
- if not na(targetY)
- targetLine := line.new(bar_index, hl2, bar_index + 10, targetY, color=targetColor, style=line.style_arrow_right, width=1)
- targetLabel := label.new(bar_index + 10, targetY, "Possible Target", style=label.style_label_lower_left, color=targetColor, textcolor=color.white, size=size.small)
- if show_dashboard
- var table info_table = table.new(position.top_right, 2, 10, bgcolor = color.new(#1e222d, 20), border_color = color.new(color.gray, 80))
- table.clear(info_table, 0, 0, 1, 9)
- color bullColor = color.new(#00C853, 0)
- color bearColor = color.new(#D50000, 0)
- color labelColor = color.new(color.white, 50)
- color headerColor = color.new(color.white, 30)
- table.cell(info_table, 0, 0, "Emerald Dash", 2, 1, bgcolor=color.new(color.gray, 90), text_color=color.white, text_halign=text.align_center, text_size=size.small)
- table.cell(info_table, 0, 1, "Market Trend", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 1, 1, uptrend ? "BULLISH" : "BEARISH", text_color=(uptrend ? bullColor : bearColor), text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 2, "VWAP Position", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 1, 2, above_session_vwap ? "ABOVE" : "BELOW", text_color=(above_session_vwap ? bullColor : bearColor), text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 3, "Dist to VWAP", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- float dist_to_vwap = (close - session_vwap) / session_vwap * 100
- color dist_color = dist_to_vwap > 0.5 or dist_to_vwap < -0.5 ? color.new(color.orange, 20) : color.new(color.white, 40)
- table.cell(info_table, 1, 3, str.tostring(dist_to_vwap, "#.##") + "%", text_color=dist_color, text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 4, "Volume Rank", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- color volRankColor = volume_percentile > 80 ? bullColor : color.new(color.white, 40)
- table.cell(info_table, 1, 4, str.tostring(volume_percentile, "#") + "%", text_color=volRankColor, text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 5, "EMA Lineup", 2, 1, text_color=headerColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 0, 6, "4 H", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 1, 6, is_4h_bull ? "BULLISH" : "BEARISH", text_color=(is_4h_bull ? bullColor : bearColor), text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 7, "1 H", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 1, 7, is_1h_bull ? "BULLISH" : "BEARISH", text_color=(is_1h_bull ? bullColor : bearColor), text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 8, "15 M", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 1, 8, is_15m_bull ? "BULLISH" : "BEARISH", text_color=(is_15m_bull ? bullColor : bearColor), text_halign=text.align_right, text_size=size.small)
- table.cell(info_table, 0, 9, "5 M", text_color=labelColor, text_halign=text.align_left, text_size=size.small)
- table.cell(info_table, 1, 9, is_5m_bull ? "BULLISH" : "BEARISH", text_color=(is_5m_bull ? bullColor : bearColor), text_halign=text.align_right, text_size=size.small)
- // ════════════════════════════════════════════════════════════════════════════════
- // ────── ALERT SYSTEM ──────
- // ════════════════════════════════════════════════════════════════════════════════
- alertcondition(pre_alert and is_bullish_rejection and at_paa_low, "Potential Long Setup", "⚠️ POTENTIAL LONG: Rejection at PAA Support - Price: {{close}}")
- alertcondition(pre_alert and is_bearish_rejection and at_paa_high, "Potential Short Setup", "⚠️ POTENTIAL SHORT: Rejection at PAA Resistance - Price: {{close}}")
- alertcondition(alert_a_setups and a_grade_long, "A-Grade Long", "🟢 A-GRADE LONG: Trend+PAA+Confirmation - Price: {{close}}")
- alertcondition(alert_a_setups and a_grade_short, "A-Grade Short", "🔴 A-GRADE SHORT: Trend+PAA+Confirmation - Price: {{close}}")
- alertcondition(alert_b_setups and b_grade_long, "B-Grade Long", "🟡 B-GRADE LONG: Strong confluence - Price: {{close}}")
- alertcondition(alert_b_setups and b_grade_short, "B-Grade Short", "🟡 B-GRADE SHORT: Strong confluence - Price: {{close}}")
- alertcondition(alert_c_setups and c_grade_long, "C-Grade Long", "⚪ C-GRADE LONG: Basic setup - Price: {{close}}")
- alertcondition(alert_c_setups and c_grade_short, "C-Grade Short", "⚪ C-GRADE SHORT: Basic setup - Price: {{close}}")
- alertcondition(bullish_liquidity, "Bullish Liquidity Grab", "💧 BULLISH LIQUIDITY: Reclaimed level - Price: {{close}}")
- alertcondition(bearish_liquidity, "Bearish Liquidity Grab", "💧 BEARISH LIQUIDITY: Reclaimed level - Price: {{close}}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement