//@version=6 indicator(title="My Trading Suite", shorttitle="My Trading Suite", max_lines_count = 500, max_labels_count = 500, max_bars_back = 5000, overlay = true) ////////////////////////////////////////////////// // VWAP Function getVWAP(vwap_newSession) => var float vwap_p = na var float vwap_vol = na vwap_p := vwap_newSession ? hlc3 * volume : nz(vwap_p[1]) + hlc3 * volume vwap_vol := vwap_newSession ? volume : nz(vwap_vol[1]) + volume vwap_p / vwap_vol // === TEMA Function === get_tema(src, len) => ema1 = ta.ema(src, len) ema2 = ta.ema(ema1, len) ema3 = ta.ema(ema2, len) 3 * (ema1 - ema2) + ema3 //-------------------------- // MA Funtion //-------------------------- f_ma(_type, _source, _length, _colorUp, _colorDown) => float ma = switch _type "SMA" => ta.sma(_source, _length) "EMA" => ta.ema(_source, _length) "WMA" => ta.wma(_source, _length) "RMA" => ta.rma(_source, _length) "HMA" => ta.hma(_source, _length) "TEMA" => get_tema(_source, _length) "VWMA" => ta.vwma(hlc3, _length) "VWAP Daily" => getVWAP(ta.change(time("D")) != 0) "VWAP Weekly" => getVWAP(ta.change(time("W")) != 0) "VWAP Monthly" => getVWAP(ta.change(time("MN")) != 0) "LinReg" => ta.linreg(_source, _length, 0) => na // MA color logic float prev = nz(ma[1]) color col = ma > prev ? _colorUp : ma < prev ? _colorDown : color.yellow [ma, col] //=> return MA value and MA color // @function Checks whether a specified timeframe string represents a smaller timeframe than the // script's main timeframe. If the specified string represents a higher timeframe, the // function raises a runtime error. // @param lowerTimeframe (series string) The timeframe string to inspect. // @returns (void) The function does not return a usable value. checkLTF(series string lowerTimeframe) => if timeframe.in_seconds(lowerTimeframe) > timeframe.in_seconds(timeframe.main_period) runtime.error( str.format( "Invalid lower timeframe: {2}{0}{2}. The timeframe must be lower than or equal to {2}{1}{2}", lowerTimeframe, timeframe.main_period, "'" ) ) // @function Calculates sums of polarized (positive and negative) `volume` values within a bar on // script's main timeframe and uses the sums to compute the bar's volume delta. The function // also tracks the highest and lowest volume delta values observed within the bar. // It uses the following logic based on `open` and `close` prices to categorize each `volume` // value: // - If the `close` is greater than the `open`, the `volume` is positive. // - If the `close` is less than the `open`, the `volume` is negative. // - If the current `close` equals the current `open` and the `close` is greater than its // previous value, the `volume` is positive. // - If the current `close` equals the current `open` and the `close` is less than its // previous value, the `volume` negative. // - If none of the above apply, the current bar's `volume` has the same positive/negative // status as that of the previous bar. // // This function's result is usable in lower-timeframe `request.*()` calls, as demonstrated in // `requestUpAndDownVolume()`. The results from such a request always represent volume data // based on all intrabars within a *single bar* on the script's *main timeframe*, because the // function resets its calculations at the open of each bar on the `timeframe.main_period` // timeframe. // In contrast to `timeframe.period`, the value of `timeframe.main_period` always represents // the script's main timeframe, even in requested contexts. // @returns ([float, float, float, float, float]) A tuple containing the following values: // - The total positive (up) volume within the bar on the script's main timeframe. // - The total negative (down) volume within the bar on the script's main timeframe, // expressed as a negative quantity. // - The bar's volume delta (i.e., the net difference between up and down volume). // - The highest volume delta observed within the bar. // - The lowest volume delta observed within the bar. upAndDownVolumeCalc() => var float posVol = 0.0 var float negVol = 0.0 var float hiVol = 0.0 var float loVol = 0.0 var bool isBuyVolume = true if timeframe.change(timeframe.main_period) posVol := 0.0 negVol := 0.0 hiVol := 0.0 loVol := 0.0 switch close > open => isBuyVolume := true close < open => isBuyVolume := false close > close[1] => isBuyVolume := true close < close[1] => isBuyVolume := false if isBuyVolume posVol += volume else negVol -= volume // float delta = posVol + negVol // float delta = high == low ? 0 : posVol + negVol float delta = posVol + negVol hiVol := math.max(delta, hiVol) loVol := math.min(delta, loVol) [posVol, negVol, delta, hiVol, loVol] // @function Requests data from a specified lower timeframe and categorizes the volume of each // intrabar within a bar on the script's main timeframe as positive (up) or negative (down). // The function uses this information to calculate the bar's volume delta, i.e., the difference // between the total up and down intrabar volume. // // If the call specifies a `cumulativePeriod` argument representing a period larger than the // main timeframe, it calculates the cumulative volume delta (CVD), which is a running sum // of volume delta across all bars within the period. In addition, the function tracks the // highest and lowest CVD values calculated within each bar over the period. The sum and // highest/lowest calculations reset when a new period starts. // // Calls to this function count toward a script's `request.*()` call limit. // @param lowerTimeframe (series string) The timeframe of the requested intrabar data. Accepts a valid timeframe // string (e.g., "5", "15", "1D"), an empty string, `timeframe.period`, or // `timeframe.main_period`. Smaller timeframes provide higher precision but cover fewer bars // on the script's main timeframe. Larger timeframes cover more bars on the script's main // timeframe but offer less granularity. If the specified timeframe is higher than the script's // main timeframe, it causes a runtime error. // @param cumulativePeriod (series string) Determines the span of the CVD period. Accepts a valid timeframe string // (e.g., "5", "15", "1D"), an empty string, `timeframe.period`, or `timeframe.main_period`. // The calculations reset after a new period starts. For example, a value of "1D" means that // the function accumulates and tracks the values from each bar within a "1D" period and resets // at the open of a new "1D" bar. // @returns ([float, float, float, float]) A tuple containing the following values: // - The opening volume delta/CVD at the start the bar on the script's main timeframe. // This value is always 0 when a new cumulative period starts. // - The maximum volume delta/CVD within the current cumulative period. // - The minimum volume delta/CVD within the current cumulative period. // - The current volume delta/CVD value. requestVolumeDelta(series string lowerTimeframe, series string cumulativePeriod = "") => checkLTF(lowerTimeframe) [_, _, delta, maxVolume, minVolume] = request.security(syminfo.tickerid, lowerTimeframe, upAndDownVolumeCalc()) var float lastVolume = 0.0 bool anchorChange = str.length(str.trim(cumulativePeriod)) == 0 or timeframe.change(cumulativePeriod) or (not na(lastVolume) and na(lastVolume[1])) float openVolume = anchorChange ? 0.0 : lastVolume[1] float hiVolume = openVolume + maxVolume float loVolume = openVolume + minVolume lastVolume := openVolume + delta [openVolume, hiVolume, loVolume, lastVolume] ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// //Ratio High Volume Highlight_Candle = input.bool(true, title="Highlight Candles", group = "Volume Spread Analysis") lengthVolumeMA = input(defval=20, title="Length of MA applied on Volume", group ="Volume Spread Analysis") colorUltraHigh = input.color(color.purple, title="", inline="UHV" , group="Volume Spread Analysis") //color.red colorVeryHigh = input.color(color.blue, title="", inline="VHV" , group="Volume Spread Analysis") //color.orange colorHighVol = input.color(color.orange, title="", inline="HV" , group="Volume Spread Analysis") //color.green colorNormalVol = input.color(color.silver, title="", inline="NV" , group="Volume Spread Analysis") //color.blue colorLowVol = input.color(#636363, title="", inline="LV" , group="Volume Spread Analysis") //color.silver colorVeryLowVol = input.color(#2e2e2e, title="", inline="VLV" , group="Volume Spread Analysis") //color.silver ratioUltraVolume = input.float(defval=2.2, step=0.1, title="Ultra High Volume", inline="UHV", group ="Volume Spread Analysis") //2.2 - 3.0 ratioVeryHighVolume = input.float(defval=1.8, step=0.1, title="Very High Volume" , inline="VHV", group ="Volume Spread Analysis") //1.8 - 2.5 ratioHighVolume = input.float(defval=1.4, step=0.1, title="High Volume" , inline="HV", group ="Volume Spread Analysis") //1.2 - 1.4 ratioNormalVolume = input.float(defval=1.0, step=0.1, title="Normal Volume" , inline="NV", group ="Volume Spread Analysis") //0.8 - 1.0 ratioLowVolume = input.float(defval=0.5, step=0.1, title="Low Volume" , inline="LV", group ="Volume Spread Analysis") //0.3 - 0.5 ratioVeryLowVolume = input.float(defval=0.5, step=0.1, title="Very Low Volume" , inline="VLV", group ="Volume Spread Analysis") //0.3 - 0.5 ////////////////////////////////////////////////// volumeMA = ta.sma(volume, lengthVolumeMA) // Volume Zones ultraHighVolumeMin = volumeMA * ratioUltraVolume veryHighVolumeMin = volumeMA * ratioVeryHighVolume highVolumeMin = volumeMA * ratioHighVolume normalVolumeMin = volumeMA * ratioNormalVolume lowVolumeMin = volumeMA * ratioLowVolume veryLowVolumeMin = volumeMA * ratioVeryLowVolume volUltraHigh = volume >= ultraHighVolumeMin and high != low volVeryHigh = volume >= veryHighVolumeMin and volume < ultraHighVolumeMin and high != low volHigh = volume >= highVolumeMin and volume < veryHighVolumeMin and high != low volNormal = volume >= normalVolumeMin and volume < highVolumeMin and high != low volLow = volume >= lowVolumeMin and volume < normalVolumeMin and high != low volVeryLow = volume < lowVolumeMin and high != low //---------------------- // Logic color //---------------------- volColor = volUltraHigh ? colorUltraHigh : volVeryHigh ? colorVeryHigh : volHigh ? colorHighVol : volNormal ? colorNormalVol : volLow ? colorLowVol : volVeryLow ? colorVeryLowVol : na barcolor(Highlight_Candle and (volume != 0) ? volColor : na) ////////////////////////////////////////////////// ////////////////////////////////////////////////// //---------------- MA1 ---------------- showMA1 = input.bool(true, "Show MA1", inline="ma1", group="MAs Setting") MA1_color_up = input.color(#00ff00, "- MA1 Up", inline="ma1", group="MAs Setting") MA1_color_dn = input.color(#ff0000, "- MA1 Down", inline="ma1", group="MAs Setting") MA1_type = input.string("VWMA", "- Type", options = ["SMA","EMA","WMA","RMA","HMA","TEMA","VWMA", "VWAP Daily","VWAP Weekly","VWAP Monthly","LinReg"], inline="ma11", group="MAs Setting") MA1_length = input.int(20, "- Length", inline="ma11", group="MAs Setting") MA1_width = input.int(2, "Width", inline="ma11", group="MAs Setting") //---------------- MA2 ---------------- showMA2 = input.bool(true, "Show MA2", inline="ma2", group="MAs Setting") MA2_color_up = input.color(#00ff00, "- MA2 Up", inline="ma2", group="MAs Setting") MA2_color_dn = input.color(#ff0000, "- MA2 Down", inline="ma2", group="MAs Setting") MA2_type = input.string("EMA", "- Type", options = ["SMA","EMA","WMA","RMA","HMA","TEMA","VWMA", "VWAP Daily","VWAP Weekly","VWAP Monthly","LinReg"], inline="ma22", group="MAs Setting") MA2_length = input.int(20, "- Length", inline="ma22", group="MAs Setting") MA2_width = input.int(2, "Width", inline="ma22", group="MAs Setting") //---------------- MA3 ---------------- showMA3 = input.bool(true, "Show MA3", inline="ma3", group="MAs Setting") MA3_color_up = input.color(#00ff00, "- MA3 Up", inline="ma3", group="MAs Setting") MA3_color_dn = input.color(#ff0000, "- MA3 Down", inline="ma3", group="MAs Setting") MA3_type = input.string("TEMA", "- Type", options = ["SMA","EMA","WMA","RMA","HMA","TEMA","VWMA", "VWAP Daily","VWAP Weekly","VWAP Monthly","LinReg"], inline="ma33", group="MAs Setting") MA3_length = input.int(20, "- Length", inline="ma33", group="MAs Setting") MA3_width = input.int(2, "Width", inline="ma33", group="MAs Setting") //---------------------------------- // PLOT MA3 //---------------------------------- [MA3_val, MA3_col] = f_ma(MA3_type, close, MA3_length, MA3_color_up, MA3_color_dn) plotMA3 = plot(showMA3 ? MA3_val : na, title="MA3", color=MA3_col, linewidth=MA3_width, force_overlay = true) //---------------------------------- // PLOT MA2 //---------------------------------- [MA2_val, MA2_col] = f_ma(MA2_type, close, MA2_length, MA2_color_up, MA2_color_dn) plotMA2 = plot(showMA2 ? MA2_val : na, title="MA2", color=MA2_col, linewidth=MA2_width, force_overlay = true) //---------------------------------- // PLOT MA1 //---------------------------------- [MA1_val, MA1_col] = f_ma(MA1_type, close, MA1_length, MA1_color_up, MA1_color_dn) plotMA1 = plot(showMA1 ? MA1_val : na, title="MA1", color=MA1_col, linewidth=MA1_width, force_overlay = true) ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// show_E_big_R_big_signal = input.bool(true, "Show E>R> Signal", inline="1", group="ER Candle: Signal and Box") E_big_R_big_colorUp = input.color(color.aqua, "Bullish", inline="2", group="ER Candle: Signal and Box") E_big_R_big_colorDn = input.color(color.fuchsia, "Bearish", inline="2", group="ER Candle: Signal and Box") show_E_small_R_big_signal = input.bool(true, "Show E Signal", inline="3", group="ER Candle: Signal and Box") E_small_R_big_colorUp = input.color(#00ff00, "Bullish", inline="4", group="ER Candle: Signal and Box") E_small_R_big_colorDn = input.color(#ff0000, "Bearish", inline="4", group="ER Candle: Signal and Box") show_E_big_R_small_signal = input.bool(true, "Show E>R< Signal", inline="0", group="ER Candle: Signal and Box") E_big_R_small_colorUp = input.color(color.new(color.yellow, 30), "Bullish", inline="0", group="ER Candle: Signal and Box") E_big_R_small_colorDn = input.color(color.new(color.yellow, 30), "Bearish", inline="0", group="ER Candle: Signal and Box") ER_ratio = input.float(1.5, "Spread Ratio Compare With Prev Candle", minval=1.0, step=0.5, group="ER Candle: R>") ER_x_bars_checkATR1 = input.int(3, "Prev Bars to Check ATR", minval=1, group="ER Candle: R>") E_big_R_big_checkVolMax = input.bool(true, "E>R> Candle Check: Max Volume?", group="ER Candle: R>") ER_x_bars_checkVolMax = input.int(3, "Prev Bars to Check Max Volume", minval=1, group="ER Candle: R>") ER_maLen = lengthVolumeMA ER_maVolRatio1 = input.float(1.0, "MA Volume Ratio check E>R>/E", minval=0.1, step=0.1, group="ER Candle: R>") ER_x_bars_checkSpead1 = input.int(3, "Prev Bars to Check Spread (Body) E>R>/E", minval=1, group="ER Candle: R>") ER_x_bars_checkATR2 = input.int(3, "Prev Bars to Check ATR", minval=1, group="ER Candle: R>") wick_spread_ratio = input.float(2.0, "E>R< Candle Check: Wick >= Spread x Ratio", minval=2.0, step=0.5, group="ER Candle: R<") ER_maVolRatio2 = input.float(1.4, "MA Volume Ratio check E>R<", minval=0.1, step=0.1, group="ER Candle: R<") ER_x_bars_checkSpead2 = input.int(20, "Prev Bars to Check Spread (Body) E>R<", minval=1, group="ER Candle: R<") show_E_big_R_big_box = input.bool(true, "Show E>R> Box", group="ER Candle: Signal and Box") show_E_small_R_big_box = input.bool(true, "Show E Box", group="ER Candle: Signal and Box") ER_box_transp = input.int(80, "Box Transparency", inline="box", group="ER Candle: Signal and Box") ER_box_offset = input.int(40, "Offset Right Box", inline="box", group="ER Candle: Signal and Box") name_E_big_R_big_box_up = input.string("E>R>\nDz", "Name Box Up E>R>", group="ER Candle: Signal and Box") //This input defines the box name for the EA to read and extract data name_E_big_R_big_box_down = input.string("Sz\nE>R>", "Name Box Down E>R>", group="ER Candle: Signal and Box") //This input defines the box name for the EA to read and extract data name_E_small_R_big_box_up = input.string("E\nDz", "Name Box Up E", group="ER Candle: Signal and Box") //This input defines the box name for the EA to read and extract data name_E_small_R_big_box_down = input.string("Sz\nE", "Name Box Down E", group="ER Candle: Signal and Box") //This input defines the box name for the EA to read and extract data // ==== Caculation ==== ER_wickPrev = math.abs(high[1] - low[1]) ER_wickCur = math.abs(high - low) ER_spreadPrev = math.abs(close[1] - open[1]) ER_spreadCur = math.abs(close - open) ER_maxSpread = ta.highest(ER_spreadCur, ER_x_bars_checkSpead1) ER_atr1 = ta.atr(ER_x_bars_checkATR1) ER_VolMax = ta.highest(volume, ER_x_bars_checkVolMax) vol_ratio_compare = 90/100 //90% E_big_R_big_vol_check = volume > volume[1] * vol_ratio_compare and (not E_big_R_big_checkVolMax or volume >= ER_VolMax) //use for E>R> E_small_R_big_vol_check = volume * vol_ratio_compare < volume[1] // ==== Volume MA ==== ER_maVol = ta.sma(volume, ER_maLen) // ======== --- E>R> --- ======== // ==== --- E>R> Up --- ==== E_big_R_big_condUp = (close[1] < open[1] or close[2] < open[2]) and close > open and close > high[1] and ER_spreadCur > ER_spreadPrev * ER_ratio and ER_spreadCur == ER_maxSpread and ER_spreadCur > ER_atr1 and volume > ER_maVol * ER_maVolRatio1 and E_big_R_big_vol_check // ==== --- E>R> Down --- ==== E_big_R_big_condDn = (close[1] > open[1] or close[2] > open[2]) and close < open and close < low[1] and ER_spreadCur > ER_spreadPrev * ER_ratio and ER_spreadCur == ER_maxSpread and ER_spreadCur > ER_atr1 and volume > ER_maVol * ER_maVolRatio1 and E_big_R_big_vol_check // ==== --- Plot Signal E>R> --- ==== plotshape(E_big_R_big_condUp and show_E_big_R_big_signal, title="Signal Up", text="E>R>", location=location.belowbar, color=E_big_R_big_colorUp, style=shape.triangleup, size=size.tiny, textcolor=E_big_R_big_colorUp, force_overlay=true) // add Alert, Send Notification, Send Mail and get ID Buffer // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal plotshape(E_big_R_big_condDn and show_E_big_R_big_signal, title="Signal Down", text="E>R>", location=location.abovebar, color=E_big_R_big_colorDn, style=shape.triangledown, size=size.tiny, textcolor=E_big_R_big_colorDn, force_overlay=true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal // ======== --- E --- ======== // ==== --- E Up --- ==== E_small_R_big_condUp = (close[1] < open[1] or close[2] < open[2]) and close > open and close > math.max(open[1], close[1]) and ER_spreadCur > ER_spreadPrev * ER_ratio and ER_spreadCur == ER_maxSpread and ER_spreadCur > ER_atr1 and E_small_R_big_vol_check // ==== --- E Down --- ==== E_small_R_big_condDn = (close[1] > open[1] or close[2] > open[2]) and close < open and close < math.min(open[1], close[1]) and ER_spreadCur > ER_spreadPrev * ER_ratio and ER_spreadCur == ER_maxSpread and ER_spreadCur > ER_atr1 and E_small_R_big_vol_check // ==== --- Plot Signal E --- ==== plotshape(E_small_R_big_condUp and show_E_small_R_big_signal, title="Signal Up", text="E", location=location.belowbar, color=E_small_R_big_colorUp, style=shape.triangleup, size=size.tiny, textcolor=E_small_R_big_colorUp, force_overlay=true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal plotshape(E_small_R_big_condDn and show_E_small_R_big_signal, title="Signal Down", text="E", location=location.abovebar, color=E_small_R_big_colorDn, style=shape.triangledown, size=size.tiny, textcolor=E_small_R_big_colorDn, force_overlay=true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal // ======== --- E>R< --- ======== ER_wickCur_upper = high - math.max(open, close) ER_wickCur_lower = math.min(open, close) - low // compare upperwick and lowerwick E_big_R_small_wick_up = ER_wickCur_upper <= ER_wickCur_lower E_big_R_small_wick_dn = ER_wickCur_upper > ER_wickCur_lower ER_atr2 = ta.atr(ER_x_bars_checkATR2) ER_spreadCur_avg = ta.sma(ER_spreadCur, ER_x_bars_checkSpead2) //trung bình thân nến của x nến gần nhất // ==== --- E>R< Up --- ==== E_big_R_small_condUp1 = E_big_R_small_wick_up and //close >= open and ER_wickCur > ER_wickPrev and ER_wickCur >= ER_spreadCur * wick_spread_ratio and volume > ER_maVol * ER_maVolRatio2 and ER_wickCur > ER_atr2 E_big_R_small_condUp2 = E_big_R_small_wick_up and ER_wickCur >= ER_spreadCur * wick_spread_ratio and volume > ER_maVol * 1.5 and ER_spreadCur <= ER_spreadCur_avg // ==== --- E>R< Down --- ==== E_big_R_small_condDn1 = E_big_R_small_wick_dn and //close < open and ER_wickCur > ER_wickPrev and ER_wickCur >= ER_spreadCur * wick_spread_ratio and volume > ER_maVol * ER_maVolRatio2 and ER_wickCur > ER_atr2 E_big_R_small_condDn2 = E_big_R_small_wick_dn and ER_wickCur >= ER_spreadCur * wick_spread_ratio and volume > ER_maVol * 1.5 and ER_spreadCur <= ER_spreadCur_avg E_big_R_small_condUp = E_big_R_small_condUp1 or E_big_R_small_condUp2 E_big_R_small_condDn = E_big_R_small_condDn1 or E_big_R_small_condDn2 // ==== --- Plot Signal E>R< --- ==== plotshape(E_big_R_small_condUp and show_E_big_R_small_signal, title="Signal Up", text="ER-", location=location.belowbar, //text="E>R<" color=E_big_R_small_colorUp, style=shape.triangleup, size=size.tiny, textcolor=E_big_R_small_colorUp, force_overlay=true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal plotshape(E_big_R_small_condDn and show_E_big_R_small_signal, title="Signal Down", text="ER-", location=location.abovebar, //text="E>R<" color=E_big_R_small_colorDn, style=shape.triangledown, size=size.tiny, textcolor=E_big_R_small_colorDn, force_overlay=true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal ////////////////////////////////////////////////// ////////////////////////////////////////////////// // Manage ER boxes // ===== BOX HANDLE ===== var box box_Ebig_Rbig_Up = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information var box box_Ebig_Rbig_Dn = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information var box box_Esmall_Rbig_Up = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information var box box_Esmall_Rbig_Dn = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information // ======================================================= // ===================== E > R > (UP) ===================== // ======================================================= bool sig_Ebig_Rbig_Up = E_big_R_big_condUp and show_E_big_R_big_signal and show_E_big_R_big_box if sig_Ebig_Rbig_Up if not na(box_Ebig_Rbig_Up) box.delete(box_Ebig_Rbig_Up) box_Ebig_Rbig_Up := box.new(bar_index[1], high[1], bar_index + ER_box_offset, math.min(low, low[1]), border_color = E_big_R_big_colorUp, border_style = line.style_dotted, bgcolor = color.new(E_big_R_big_colorUp, ER_box_transp), text = name_E_big_R_big_box_up, text_size = size.small, text_color = color.white, text_halign = text.align_right, text_valign = text.align_bottom) else if not na(box_Ebig_Rbig_Up) box.set_right(box_Ebig_Rbig_Up, bar_index + ER_box_offset) // ======================================================= // ===================== E > R > (DN) ===================== // ======================================================= bool sig_Ebig_Rbig_Dn = E_big_R_big_condDn and show_E_big_R_big_signal and show_E_big_R_big_box if sig_Ebig_Rbig_Dn if not na(box_Ebig_Rbig_Dn) box.delete(box_Ebig_Rbig_Dn) box_Ebig_Rbig_Dn := box.new( bar_index[1], math.max(high, high[1]), bar_index + ER_box_offset, low[1], border_color = E_big_R_big_colorDn, border_style = line.style_dotted, bgcolor = color.new(E_big_R_big_colorDn, ER_box_transp), text = name_E_big_R_big_box_down, text_size = size.small, text_color = color.white, text_halign = text.align_right, text_valign = text.align_top) else if not na(box_Ebig_Rbig_Dn) box.set_right(box_Ebig_Rbig_Dn, bar_index + ER_box_offset) // ======================================================= // ===================== E < R > (UP) ===================== // ======================================================= bool sig_Esmall_Rbig_Up = E_small_R_big_condUp and show_E_small_R_big_signal and show_E_small_R_big_box if sig_Esmall_Rbig_Up if not na(box_Esmall_Rbig_Up) box.delete(box_Esmall_Rbig_Up) box_Esmall_Rbig_Up := box.new(bar_index[1], high[1], bar_index + ER_box_offset, math.min(low, low[1]), border_color = E_small_R_big_colorUp, border_style = line.style_dotted, bgcolor = color.new(E_small_R_big_colorUp, ER_box_transp), text = name_E_small_R_big_box_up, text_size = size.small, text_color = color.white, text_halign = text.align_right, text_valign = text.align_bottom) else if not na(box_Esmall_Rbig_Up) box.set_right(box_Esmall_Rbig_Up, bar_index + ER_box_offset) // ======================================================= // ===================== E < R > (DN) ===================== // ======================================================= bool sig_Esmall_Rbig_Dn = E_small_R_big_condDn and show_E_small_R_big_signal and show_E_small_R_big_box if sig_Esmall_Rbig_Dn if not na(box_Esmall_Rbig_Dn) box.delete(box_Esmall_Rbig_Dn) box_Esmall_Rbig_Dn := box.new(bar_index[1], math.max(high, high[1]), bar_index + ER_box_offset, low[1], border_color = E_small_R_big_colorDn, border_style = line.style_dotted, bgcolor = color.new(E_small_R_big_colorDn, ER_box_transp), text = name_E_small_R_big_box_down, text_size = size.small, text_color = color.white, text_halign = text.align_right, text_valign = text.align_top) else if not na(box_Esmall_Rbig_Dn) box.set_right(box_Esmall_Rbig_Dn, bar_index + ER_box_offset) ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// lowerTimeframeTooltip = "The indicator scans lower timeframe data to approximate up and down volume used in the delta calculation. By default, the timeframe is chosen automatically. These inputs override this with a custom timeframe. \n\nHigher timeframes provide more historical data, but the data will be less precise." CDVuseCustomTimeframe = input.bool(true, "Use Auto custom timeframe", tooltip = lowerTimeframeTooltip, group="CDV Candle") CDVltf = input.timeframe('1', 'LTF Manual (when Auto custom TF = false)', group="CDV Candle") // --- use CDVuseCustomTimeframe --- var string CDVlowerTimeframe = na CDVlowerTimeframe := switch CDVuseCustomTimeframe == false => CDVltf timeframe.isseconds => "1S" timeframe.isintraday => "1" timeframe.isdaily => "15" => "60" // --- Function CDV --- CDVrequestVolumeDelta(series string lowerTimeframe, float lastVolume) => checkLTF(lowerTimeframe) [_, _, delta, maxVolume, minVolume] = request.security(syminfo.tickerid, lowerTimeframe, upAndDownVolumeCalc()) float CDVopenVolume = nz(lastVolume, 0) float CDVhiVolume = CDVopenVolume + maxVolume float CDVloVolume = CDVopenVolume + minVolume float CDVlastVolume = CDVopenVolume + delta [CDVopenVolume, CDVhiVolume, CDVloVolume, CDVlastVolume] // --- Candle cho CDV var float CDVlastVolume = 0.0 [ltf_o, ltf_h, ltf_l, ltf_c] = CDVrequestVolumeDelta(CDVlowerTimeframe, CDVlastVolume) CDVlastVolume := ltf_c o_ = ltf_o c_ = ltf_c h_ = ltf_h l_ = ltf_l spread_price = math.abs(close - open) spread_CDV = math.abs(c_ - o_) price_CDV_div = (spread_price > spread_price[1] and spread_CDV < spread_CDV[1] and high != low) or (spread_price < spread_price[1] and spread_CDV > spread_CDV[1] and high != low) ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// // ===== ===== All CDVma input // --- Input MA of CDV Candles CDVmaType = input.string("TEMA", "Type of MA", options = ["SMA","EMA","WMA","RMA","HMA","TEMA","VWMA", "VWAP Daily","VWAP Weekly","VWAP Monthly","LinReg"], inline="ma2", group="MA of CDV") CDVmaLength = input.int(20, "MA Length", inline="ma2", group="MA of CDV") CDVma_colorup = input.color(color.lime, title="Up", inline="col", group="MA of CDV") CDVma_colordown = input.color(color.red, title="Down", inline="col", group="MA of CDV") // --- Input CDVma Cross CDVma_useSpreadFilter = input.bool(true, "Use OC/HL Spread Filter?", inline = "ma3", group="MA of CDV") CDVma_SpreadRatio = input.int(30, "OC Compare to HL Ratio %", minval=0, step=5, inline = "ma3", group="MA of CDV") CDVma_useMAVol = input.bool(false, "Use MA Volume To Check Signal?", inline = "ma4", group="MA of CDV") CDVma_VolRatio = input.float(1.0, "MA Volume Ratio", minval=0.1, step=0.1, inline = "ma4", group="MA of CDV") // --- Input CDVma shadow + signal + box showCDVma_shadow = input.bool(true, "Show CDV_MA Shadow", group="CDV_MA Shadow") showCDVma_shadow_break = input.bool(true, "Show CDV_MA Shadow Cross", inline = "line3", group="CDV_MA Shadow Break") CDVma_shadow_break_useMAVol = input.bool(true, "Use MA Volume To Check Signal?", group="BCDV_MA Shadow Break") CDVma_shadow_break_VolRatio = input.float(1.0, "MA Volume Ratio", minval=0.1, step=0.1, group="CDV_MA Shadow Break") showCDVma_trend_signal = input.bool(true, "Show Trend Signal", inline = "sig", group="CDV_MA Shadow Trend") showCDVma_trend_shadow = input.bool(true, "Show Trend Shadow", inline = "sd", group="CDV_MA Shadow Trend") showCDVma_trend_bg = input.bool(true, "Show Trend Background", inline = "bg", group="CDV_MA Shadow Trend") CDVma_trend_bg_transp = input.int(90, "Transparency", minval=0, maxval=100, inline = "bg", group="CDV_MA Shadow Trend") showCDVma_shadow_box = input.bool(true, "Show CDV_MA Shadow Box", inline = "b1", group="Box + RR Lines") showCDVma_shadow_break_box = input.bool(true, "Show CDV_MA Shadow Box", inline = "b2", group="Box + RR Lines") showCDVma_trend_box = input.bool(true, "Show CDV_MA Trend Box", inline = "b3", group = "Box + RR Lines") name_CDVma_shadow_box = input.string("Shadow", "- Box Name", inline = "b1", group="Box + RR Lines") //This input defines the box name for the EA to read and extract data name_CDVma_shadow_break_box = input.string("Shadow\nBreak", "- Box Name", inline = "b2", group="Box + RR Lines") //This input defines the box name for the EA to read and extract data name_CDVma_trend_box = input.string("Shadow\nTrend", "- Box Name", inline = "b3", group = "Box + RR Lines") //This input defines the box name for the EA to read and extract data box_transp = input.int(70, "Transparency", minval=0, maxval=100, group="Box + RR Lines") box_length = input.int(10, "Length", group="Box + RR Lines") box_offset = input.int(2, "Offset", group="Box + RR Lines") box_showRRlines = input.bool(true, "Show RR Lines", group="Box + RR Lines") box_RR_lines_count = input.int(5, "Number of RR Lines", minval=1, maxval=10, group="Box + RR Lines") ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// // ===== ===== All CDVma LOGIC // --- Get value CDVma and color [CDVmaLine, CDVmaLine_color] = f_ma(CDVmaType, c_, CDVmaLength, CDVma_colorup, CDVma_colordown) ////////////////////////////////////////////////// // ===== CDVma_cross logic // --- Body Candle Condition CDVma_spread = math.abs(close - open) CDVma_spreadCondition = not CDVma_useSpreadFilter or ((high-low) > 0 and (math.abs(close - open) / (high-low) * 100 >= CDVma_SpreadRatio)) // --- MA Volume Condition CDVma_MAVol = ta.sma(volume, CDVmaLength) CDVma_volCondition = CDVma_useMAVol ? (volume > CDVma_MAVol * CDVma_VolRatio) : (volume > volume[1]) // --- Cross signals CDVma_crossUp_weak = ta.crossover(c_, CDVmaLine) CDVma_crossDown_weak = ta.crossunder(c_, CDVmaLine) CDVma_crossUp_strong1 = CDVma_crossUp_weak and low <= low[1] and CDVma_spread >= CDVma_spread[1] CDVma_crossDown_strong1 = CDVma_crossDown_weak and high >= high[1] and CDVma_spread >= CDVma_spread[1] CDVma_crossUp_strong2 = ta.crossover(c_, CDVmaLine) and CDVma_volCondition and CDVma_spreadCondition CDVma_crossDown_strong2 = ta.crossunder(c_, CDVmaLine) and CDVma_volCondition and CDVma_spreadCondition CDVma_crossUp_strong = CDVma_crossUp_strong1 or CDVma_crossUp_strong2 CDVma_crossDown_strong = CDVma_crossDown_strong1 or CDVma_crossDown_strong2 ////////////////////////////////////////////////// // ===== CDVma Shadow logic // ===================================================== // CDV MA Cross – Candle Shadow State (Array-based) // This block replaces the original CDVma_CrossCandleShadow() function // using manual array-based state management (no helper functions). // ===================================================== // ===== Candle shadow (current / previous) ===== // [0] = current candle // [1] = previous candle var float[] arr_candleLow = array.new_float(2, na) var float[] arr_candleHigh = array.new_float(2, na) // ===== Previous-confirm candle (trend confirmation) ===== // These values are captured ONLY when a valid cross occurs // They store the candle state BEFORE the cross bar var float[] arr_candleLow_prevConfirm = array.new_float(2, na) var float[] arr_candleHigh_prevConfirm = array.new_float(2, na) // ===== CDV candle shadow (current / previous) ===== var float[] arr_cdvLow = array.new_float(2, na) var float[] arr_cdvHigh = array.new_float(2, na) // ===== Signal state & visual color ===== var bool[] arr_crossValid = array.new_bool(2, false) var color[] arr_shadowColor = array.new_color(2, na) // ===================================================== // Cross detection // ===================================================== bool IsCDVma_CrossCandle = CDVma_crossUp_strong or CDVma_crossDown_strong // Check if a previous candle shadow already exists bool hasPrev = not na(array.get(arr_candleHigh, 1)) and not na(array.get(arr_candleLow, 1)) // ===================================================== // Cross validity logic (same as original function) // ===================================================== bool crossValid = (CDVma_crossUp_strong and (not hasPrev or low >= array.get(arr_candleHigh, 1))) or (CDVma_crossDown_strong and (not hasPrev or high <= array.get(arr_candleLow, 1))) or (not CDVma_crossUp_strong and not CDVma_crossDown_strong) // ===================================================== // State update logic // ===================================================== if IsCDVma_CrossCandle and crossValid // --------------------------------- // Push candle shadow (current → previous) // --------------------------------- array.set(arr_candleLow, 1, array.get(arr_candleLow, 0)) array.set(arr_candleHigh, 1, array.get(arr_candleHigh, 0)) // --------------------------------- // Set current candle shadow // --------------------------------- array.set(arr_candleLow, 0, low) array.set(arr_candleHigh, 0, high) // --------------------------------- // Store previous-confirm candle // Captured only at the cross bar // --------------------------------- array.set(arr_candleLow_prevConfirm, 1, array.get(arr_candleLow_prevConfirm, 0)) array.set(arr_candleHigh_prevConfirm, 1, array.get(arr_candleHigh_prevConfirm, 0)) array.set(arr_candleLow_prevConfirm, 0, array.get(arr_candleLow, 1)) array.set(arr_candleHigh_prevConfirm, 0, array.get(arr_candleHigh, 1)) // --------------------------------- // CDV candle shadow update // --------------------------------- array.set(arr_cdvLow, 1, array.get(arr_cdvLow, 0)) array.set(arr_cdvHigh, 1, array.get(arr_cdvHigh, 0)) array.set(arr_cdvLow, 0, l_) array.set(arr_cdvHigh, 0, h_) // --------------------------------- // Cross state flag // --------------------------------- array.set(arr_crossValid, 1, array.get(arr_crossValid, 0)) array.set(arr_crossValid, 0, true) // --------------------------------- // Shadow color selection // --------------------------------- array.set(arr_shadowColor, 1, array.get(arr_shadowColor, 0)) array.set( arr_shadowColor, 0, CDVma_crossUp_strong ? CDVma_colorup : CDVma_crossDown_strong ? CDVma_colordown : array.get(arr_shadowColor, 1) ) else // --------------------------------- // Carry forward candle shadow state // --------------------------------- array.set(arr_candleLow, 1, array.get(arr_candleLow, 0)) array.set(arr_candleHigh, 1, array.get(arr_candleHigh, 0)) array.set(arr_candleLow, 0, array.get(arr_candleLow, 0)) array.set(arr_candleHigh, 0, array.get(arr_candleHigh, 0)) // --------------------------------- // Carry forward previous-confirm state // --------------------------------- array.set(arr_candleLow_prevConfirm, 1, array.get(arr_candleLow_prevConfirm, 0)) array.set(arr_candleHigh_prevConfirm, 1, array.get(arr_candleHigh_prevConfirm, 0)) array.set(arr_candleLow_prevConfirm, 0, array.get(arr_candleLow_prevConfirm, 0)) array.set(arr_candleHigh_prevConfirm, 0, array.get(arr_candleHigh_prevConfirm, 0)) // --------------------------------- // Carry forward CDV candle state // --------------------------------- array.set(arr_cdvLow, 1, array.get(arr_cdvLow, 0)) array.set(arr_cdvHigh, 1, array.get(arr_cdvHigh, 0)) array.set(arr_cdvLow, 0, array.get(arr_cdvLow, 0)) array.set(arr_cdvHigh, 0, array.get(arr_cdvHigh, 0)) // --------------------------------- // Reset cross flag & keep last color // --------------------------------- array.set(arr_crossValid, 1, array.get(arr_crossValid, 0)) array.set(arr_crossValid, 0, false) array.set(arr_shadowColor, 1, array.get(arr_shadowColor, 0)) array.set(arr_shadowColor, 0, array.get(arr_shadowColor, 1)) // ===================================================== // Output variables (drop-in replacement for function return) // ===================================================== bool CDVma_Cross_crossValid = array.get(arr_crossValid, 0) bool CDVma_Cross_hasPrev = hasPrev float CDVma_Cross_candleLow = array.get(arr_candleLow, 0) float CDVma_Cross_candleHigh = array.get(arr_candleHigh, 0) float CDVma_Cross_candleLow_prev = array.get(arr_candleLow_prevConfirm, 0) float CDVma_Cross_candleHigh_prev = array.get(arr_candleHigh_prevConfirm, 0) float CDVma_Cross_CDVcandleLow = array.get(arr_cdvLow, 0) float CDVma_Cross_CDVcandleHigh = array.get(arr_cdvHigh, 0) color CDVma_Cross_colorShadow = array.get(arr_shadowColor, 0) ////////////////////////////////////////////////// // ===== CDVma Shadow break logic //================================================== // CDV MA Break Shadow – State Management (Array-based) //================================================== //-------------------------------------------------- // WAIT BREAK STATE (Buy / Sell) //-------------------------------------------------- var bool[] arr_waitbreak_buy = array.new_bool(2, false) // [0]=current, [1]=previous var bool[] arr_waitbreak_sell = array.new_bool(2, false) //-------------------------------------------------- // SIGNAL STATE // 0 = no signal // 1 = BUY // -1 = SELL //-------------------------------------------------- var int[] arr_breakshadow_state = array.new_int(2, 0) //-------------------------------------------------- // UPDATE WAIT-BREAK FLAGS (ON BAR CLOSE) //-------------------------------------------------- // Shift previous state array.set(arr_waitbreak_buy , 1, array.get(arr_waitbreak_buy , 0)) array.set(arr_waitbreak_sell, 1, array.get(arr_waitbreak_sell, 0)) // New cross candle → allow waiting for break if IsCDVma_CrossCandle array.set(arr_waitbreak_buy , 0, true) array.set(arr_waitbreak_sell, 0, true) else // Keep previous state array.set(arr_waitbreak_buy , 0, array.get(arr_waitbreak_buy , 1)) array.set(arr_waitbreak_sell, 0, array.get(arr_waitbreak_sell, 1)) //-------------------------------------------------- // MA VOLUME CONDITION //-------------------------------------------------- breakshadow_maLength = CDVmaLength breakshadow_MAVol = ta.sma(volume, breakshadow_maLength) breakshadow_volCondition = CDVma_shadow_break_useMAVol ? (volume > breakshadow_MAVol * CDVma_shadow_break_VolRatio) : (volume > volume[1]) //-------------------------------------------------- // BREAK SHADOW CONDITIONS //-------------------------------------------------- breakshadow_cond_buy = close >= CDVma_Cross_candleHigh and (breakshadow_volCondition or c_ > CDVma_Cross_CDVcandleHigh) and close >= open and close > high[1] breakshadow_cond_sell = close <= CDVma_Cross_candleLow and (breakshadow_volCondition or c_ < CDVma_Cross_CDVcandleLow) and close <= open and close < low[1] //-------------------------------------------------- // DETECT NEW SIGNAL (ON BAR CLOSE) //-------------------------------------------------- int breakshadow_cond_new_signal = 0 int prevState = array.get(arr_breakshadow_state, 0) if breakshadow_cond_buy and prevState != 1 breakshadow_cond_new_signal := 1 else if breakshadow_cond_sell and prevState != -1 breakshadow_cond_new_signal := -1 //-------------------------------------------------- // UPDATE SIGNAL STATE //-------------------------------------------------- // Shift previous state array.set(arr_breakshadow_state, 1, array.get(arr_breakshadow_state, 0)) // Update current state if breakshadow_cond_new_signal != 0 array.set(arr_breakshadow_state, 0, breakshadow_cond_new_signal) else array.set(arr_breakshadow_state, 0, array.get(arr_breakshadow_state, 1)) //-------------------------------------------------- // OUTPUT STATES (FOR EA / OTHER LOGIC) //-------------------------------------------------- // 1 = BUY // -1 = SELL // 0 = NONE bool CDVma_waitBreakBuy = array.get(arr_waitbreak_buy , 0) bool CDVma_waitBreakSell = array.get(arr_waitbreak_sell, 0) int CDVma_breakSignalState = array.get(arr_breakshadow_state, 0) ////////////////////////////////////////////////// // ===== CDVma Shadow Trend logic //──────────────────────────────────────────────────────────────────────────── // CDVma_Cross Shadow TREND (COMPACT – ARRAY BASED) //──────────────────────────────────────────────────────────────────────────── // === Trend State === // 1 = Up Trend // -1 = Down Trend // 0 = Neutral var int[] arr_trendState = array.new_int(2, 0) // === Trend Zones === var float[] arr_trendUp_upper = array.new_float(2, na) var float[] arr_trendUp_lower = array.new_float(2, na) var float[] arr_trendDown_upper = array.new_float(2, na) var float[] arr_trendDown_lower = array.new_float(2, na) var float[] arr_trend_mid = array.new_float(2, na) //────────────────── // Trend Conditions //────────────────── // Up Trend condition bool CDVma_isTrendUp = (CDVma_Cross_crossValid and CDVma_crossUp_strong and (not CDVma_Cross_hasPrev or low >= CDVma_Cross_candleHigh_prev)) or (close > CDVma_Cross_candleHigh_prev and close > CDVma_Cross_candleHigh) // Down Trend condition bool CDVma_isTrendDown = (CDVma_Cross_crossValid and CDVma_crossDown_strong and (not CDVma_Cross_hasPrev or high <= CDVma_Cross_candleLow_prev)) or (close < CDVma_Cross_candleLow_prev and close < CDVma_Cross_candleLow) //────────────────── // Update Trend State //────────────────── // push previous trend state array.set(arr_trendState, 1, array.get(arr_trendState, 0)) // assign current trend state if CDVma_isTrendUp and close > high[1] array.set(arr_trendState, 0, 1) else if CDVma_isTrendDown and close < low[1] array.set(arr_trendState, 0, -1) else array.set(arr_trendState, 0, array.get(arr_trendState, 1)) //────────────────── // Detect New Trend //────────────────── bool CDVma_isNewTrendUp = array.get(arr_trendState, 0) == 1 and array.get(arr_trendState, 1) != 1 bool CDVma_isNewTrendDown = array.get(arr_trendState, 0) == -1 and array.get(arr_trendState, 1) != -1 //────────────────── // Push Previous Zones //────────────────── array.set(arr_trendUp_upper, 1, array.get(arr_trendUp_upper, 0)) array.set(arr_trendUp_lower, 1, array.get(arr_trendUp_lower, 0)) array.set(arr_trendDown_upper, 1, array.get(arr_trendDown_upper, 0)) array.set(arr_trendDown_lower, 1, array.get(arr_trendDown_lower, 0)) array.set(arr_trend_mid, 1, array.get(arr_trend_mid, 0)) //────────────────── // Create New Trend Zones //────────────────── // New Up Trend if CDVma_isNewTrendUp array.set(arr_trendUp_upper, 0, math.max(open, close)) array.set(arr_trendUp_lower, 0, math.min(CDVma_Cross_candleLow, CDVma_Cross_candleLow_prev)) array.set(arr_trend_mid, 0, math.min(CDVma_Cross_candleHigh, CDVma_Cross_candleHigh_prev)) // New Down Trend if CDVma_isNewTrendDown array.set(arr_trendDown_upper, 0, math.max(CDVma_Cross_candleHigh, CDVma_Cross_candleHigh_prev)) array.set(arr_trendDown_lower, 0, math.min(open, close)) array.set(arr_trend_mid, 0, math.max(CDVma_Cross_candleLow, CDVma_Cross_candleLow_prev)) //────────────────── // Export Values //────────────────── int CDVma_trendState = array.get(arr_trendState, 0) float CDVma_TrendUp_upper = array.get(arr_trendUp_upper, 0) float CDVma_TrendUp_lower = array.get(arr_trendUp_lower, 0) float CDVma_TrendDown_upper = array.get(arr_trendDown_upper, 0) float CDVma_TrendDown_lower = array.get(arr_trendDown_lower, 0) float CDVma_Trend_mid = array.get(arr_trend_mid, 0) ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// // ===== ===== All CDVma plot + signal // ===== CDVma Shadow plot_CDVma_Cross_candleLow = plot(showCDVma_shadow and CDVma_Cross_candleLow == CDVma_Cross_candleLow[1] ? CDVma_Cross_candleLow : na, "Shadow Low", color = CDVma_Cross_colorShadow, style = plot.style_steplinebr, force_overlay = false) plot_CDVma_Cross_candleHigh = plot(showCDVma_shadow and CDVma_Cross_candleHigh == CDVma_Cross_candleHigh[1] ? CDVma_Cross_candleHigh : na, "Shadow High", color = CDVma_Cross_colorShadow, style = plot.style_steplinebr, force_overlay = false) // add fill as background CDVma_Cross_fillcolorShadow = c_ > CDVma_Cross_CDVcandleHigh ? CDVma_colorup : c_ < CDVma_Cross_CDVcandleLow ? CDVma_colordown : color.yellow fill(plot_CDVma_Cross_candleHigh, plot_CDVma_Cross_candleLow, color = color.new(CDVma_Cross_fillcolorShadow, box_transp)) ////////////////////////////////////////////////// // ===== CDVma Shadow break plotshape(showCDVma_shadow_break and breakshadow_cond_new_signal == 1, "Shadow Break up", style = shape.triangleup, location = location.belowbar, color = CDVma_colorup, size = size.small) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal plotshape(showCDVma_shadow_break and breakshadow_cond_new_signal == -1, "Shadow Break down", style = shape.triangledown, location = location.abovebar, color = CDVma_colordown, size = size.small) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal ////////////////////////////////////////////////// // ===== CDVma Shadow trend //──────────────────────────────────────────────────────────── // Plotshape Signals for Trend Up / Trend Down (First bar of new trend) //──────────────────────────────────────────────────────────── // Plotshape for Trend Up: plotshape( showCDVma_trend_signal and CDVma_isNewTrendUp, title = "CDVma Trend Up", style = shape.triangleup, location = location.belowbar, color = CDVma_colorup, size = size.normal, force_overlay = true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal // Plotshape for Trend Down: // Appears at the high of the candle plotshape( showCDVma_trend_signal and CDVma_isNewTrendDown, title = "CDVma Trend Down", style = shape.triangledown, location = location.abovebar, color = CDVma_colordown, size = size.normal, force_overlay = true) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal //──────────────────────────────────────────────────────────── // Plot CDVma Trend Upper and Lower //──────────────────────────────────────────────────────────── plot(showCDVma_trend_shadow and CDVma_trendState == 1 ? CDVma_TrendUp_upper : showCDVma_trend_shadow and CDVma_trendState == -1 ? CDVma_TrendDown_upper : na, "CDVma Trend Upper", CDVma_trendState == 1 ? CDVma_colorup : CDVma_trendState == -1 ? CDVma_colordown : na, linewidth = 2, style = plot.style_circles, force_overlay = true) plot(showCDVma_trend_shadow and CDVma_trendState == 1 ? CDVma_TrendUp_lower : showCDVma_trend_shadow and CDVma_trendState == -1 ? CDVma_TrendDown_lower : na, "CDVma Trend Lower", CDVma_trendState == 1 ? CDVma_colorup : CDVma_trendState == -1 ? CDVma_colordown : na, linewidth = 2, style = plot.style_circles, force_overlay = true) plot(showCDVma_trend_shadow ? CDVma_Trend_mid : na, "CDVma Trend Middle", color.yellow, linewidth = 2, style = plot.style_circles, force_overlay = true) //──────────────────────────────────────────────────────────────────────────── // Background Coloring Based on Trend State //──────────────────────────────────────────────────────────────────────────── // If Trend Up → use CDVma_colorup // If Trend Down → use CDVma_colordown // If Neutral → use yellow color bgcolor(showCDVma_trend_bg and CDVma_trendState == 1 ? color.new(CDVma_colorup, CDVma_trend_bg_transp) : showCDVma_trend_bg and CDVma_trendState == -1 ? color.new(CDVma_colordown, CDVma_trend_bg_transp) : color.new(color.yellow, CDVma_trend_bg_transp)) ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// // ===== ===== All CDVma Box + RR lines // ===== CDVma Shadow Box //================================================== // CDV MA Shadow Box (EA-friendly logic) // - Create the box only once (fixed ID) // - Update position and price levels on bar close // - Easier for EA to track and manage //================================================== //-------------------------------------------------- // Shadow Box //-------------------------------------------------- var box CDVma_shadow_box = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information bool isNewCDVma_shadow = showCDVma_shadow and showCDVma_shadow_box CDVma_shadow_box_left_offset = box_offset CDVma_shadow_box_right_offset = CDVma_shadow_box_left_offset + box_length //===== CREATE BOX (ONE TIME ONLY) ===== // Create the box when the signal appears for the first time if isNewCDVma_shadow and na(CDVma_shadow_box) CDVma_shadow_box := box.new( left = bar_index + CDVma_shadow_box_left_offset, right = bar_index + CDVma_shadow_box_right_offset, top = CDVma_Cross_candleHigh, bottom = CDVma_Cross_candleLow, border_color = CDVma_Cross_colorShadow, bgcolor = color.new(CDVma_Cross_colorShadow, box_transp), text = name_CDVma_shadow_box, //"Shadow", text_color = color.white, force_overlay = true) //===== UPDATE BOX (ON BAR CONFIRM) ===== // Move the box forward and update High / Low dynamically if not na(CDVma_shadow_box) box.set_left (CDVma_shadow_box, bar_index + CDVma_shadow_box_left_offset) box.set_right (CDVma_shadow_box, bar_index + CDVma_shadow_box_right_offset) box.set_top (CDVma_shadow_box, CDVma_Cross_candleHigh) box.set_bottom(CDVma_shadow_box, CDVma_Cross_candleLow) box.set_border_color(CDVma_shadow_box, CDVma_Cross_colorShadow) box.set_bgcolor(CDVma_shadow_box, color.new(CDVma_Cross_colorShadow, box_transp)) //-------------------------------------------------- // RR Lines & Labels (Risk / Reward Projection) //-------------------------------------------------- var line[] CDVma_shadow_box_upperRR_lines = array.new_line() var line[] CDVma_shadow_box_lowerRR_lines = array.new_line() var label[] CDVma_shadow_box_upperRR_labels = array.new_label() var label[] CDVma_shadow_box_lowerRR_labels = array.new_label() //===== CREATE RR LINES & LABELS (ONE TIME) ===== // Initialize RR lines and labels only once if isNewCDVma_shadow and array.size(CDVma_shadow_box_upperRR_lines) == 0 and box_showRRlines for i = 1 to box_RR_lines_count // Upper RR line array.push(CDVma_shadow_box_upperRR_lines, line.new(na, na, na, na, color=CDVma_colorup, width=1)) // Lower RR line array.push(CDVma_shadow_box_lowerRR_lines, line.new(na, na, na, na, color=CDVma_colordown, width=1)) // Upper RR label array.push(CDVma_shadow_box_upperRR_labels, label.new(na, na, "", color=color.new(CDVma_colorup, 100), style=label.style_label_right, textcolor=color.white, size=size.small)) // Lower RR label array.push(CDVma_shadow_box_lowerRR_labels, label.new(na, na, "", color=color.new(CDVma_colordown, 100), style=label.style_label_right, textcolor=color.white, size=size.small)) //===== UPDATE RR LINES & LABELS ===== // Recalculate RR levels and move lines on bar close if box_showRRlines float CDVma_shadow_box_range = CDVma_Cross_candleHigh - CDVma_Cross_candleLow for i = 0 to array.size(CDVma_shadow_box_upperRR_lines) - 1 float CDVma_shadow_box_rr = (i + 1) float CDVma_shadow_box_upper = CDVma_Cross_candleHigh + CDVma_shadow_box_range * CDVma_shadow_box_rr float CDVma_shadow_box_lower = CDVma_Cross_candleLow - CDVma_shadow_box_range * CDVma_shadow_box_rr //----- Upper RR line & label ----- line.set_xy1(array.get(CDVma_shadow_box_upperRR_lines, i), bar_index + CDVma_shadow_box_left_offset, CDVma_shadow_box_upper) line.set_xy2(array.get(CDVma_shadow_box_upperRR_lines, i), bar_index + CDVma_shadow_box_right_offset, CDVma_shadow_box_upper) label.set_xy(array.get(CDVma_shadow_box_upperRR_labels, i), bar_index + CDVma_shadow_box_right_offset, CDVma_shadow_box_upper) label.set_text(array.get(CDVma_shadow_box_upperRR_labels, i), str.tostring(i + 1) + "R") //----- Lower RR line & label ----- line.set_xy1(array.get(CDVma_shadow_box_lowerRR_lines, i), bar_index + CDVma_shadow_box_left_offset, CDVma_shadow_box_lower) line.set_xy2(array.get(CDVma_shadow_box_lowerRR_lines, i), bar_index + CDVma_shadow_box_right_offset, CDVma_shadow_box_lower) label.set_xy(array.get(CDVma_shadow_box_lowerRR_labels, i), bar_index + CDVma_shadow_box_right_offset, CDVma_shadow_box_lower) label.set_text(array.get(CDVma_shadow_box_lowerRR_labels, i), str.tostring(i + 1) + "R") ////////////////////////////////////////////////// // ===== CDVma Shadow break Box //========= CDVma Shadow break RANGE ARRAYS // [0] = current // [1] = previous var float[] CDVma_shadow_break_box_upper = array.new_float(2, na) var float[] CDVma_shadow_break_box_lower = array.new_float(2, na) //-------------------------------------------------- // Shadow Break Box //-------------------------------------------------- var box CDVma_shadow_break_box = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information bool isNewCDVma_shadow_break = showCDVma_shadow_break and showCDVma_shadow_break_box //──────────────────────────────────────────────────────────── // SHIFT PREVIOUS CDVma Shadow break RANGE //──────────────────────────────────────────────────────────── if breakshadow_cond_new_signal != 0 array.set(CDVma_shadow_break_box_upper, 1, array.get(CDVma_shadow_break_box_upper, 0)) array.set(CDVma_shadow_break_box_lower, 1, array.get(CDVma_shadow_break_box_lower, 0)) //──────────────────────────────────────────────────────────── // SET CURRENT CDVma Shadow break RANGE //──────────────────────────────────────────────────────────── if breakshadow_cond_new_signal == 1 array.set(CDVma_shadow_break_box_upper, 0, math.max(open, close)) array.set(CDVma_shadow_break_box_lower, 0, CDVma_Cross_candleLow) if breakshadow_cond_new_signal == -1 array.set(CDVma_shadow_break_box_upper, 0, CDVma_Cross_candleHigh) array.set(CDVma_shadow_break_box_lower, 0, math.min(open, close)) CDVma_shadow_break_box_left_offset = CDVma_shadow_box_right_offset CDVma_shadow_break_box_right_offset = CDVma_shadow_break_box_left_offset + box_length CDVma_shadow_break_box_color = CDVma_breakSignalState == 1 ? CDVma_colorup : CDVma_breakSignalState == -1 ? CDVma_colordown : color.yellow //===== CREATE BOX (ONE TIME ONLY) ===== // Create the box when the signal appears for the first time if isNewCDVma_shadow_break and na(CDVma_shadow_break_box) CDVma_shadow_break_box := box.new( left = bar_index + CDVma_shadow_break_box_left_offset, right = bar_index + CDVma_shadow_break_box_right_offset, top = array.get(CDVma_shadow_break_box_upper, 0), bottom = array.get(CDVma_shadow_break_box_lower, 0), border_color = CDVma_shadow_break_box_color, bgcolor = color.new(CDVma_shadow_break_box_color, box_transp), text = name_CDVma_shadow_break_box, //"Shadow\nBreak", text_color = color.white, force_overlay = true) //===== UPDATE BOX (ON BAR CONFIRM) ===== // Move the box forward and update High / Low dynamically if not na(CDVma_shadow_break_box) box.set_left (CDVma_shadow_break_box, bar_index + CDVma_shadow_break_box_left_offset) box.set_right (CDVma_shadow_break_box, bar_index + CDVma_shadow_break_box_right_offset) box.set_top (CDVma_shadow_break_box, array.get(CDVma_shadow_break_box_upper, 0)) box.set_bottom(CDVma_shadow_break_box, array.get(CDVma_shadow_break_box_lower, 0)) box.set_border_color(CDVma_shadow_break_box, CDVma_shadow_break_box_color) box.set_bgcolor(CDVma_shadow_break_box, color.new(CDVma_shadow_break_box_color, box_transp)) //-------------------------------------------------- // RR Lines & Labels (Risk / Reward Projection) //-------------------------------------------------- var line[] CDVma_shadow_break_box_upperRR_lines = array.new_line() var line[] CDVma_shadow_break_box_lowerRR_lines = array.new_line() var label[] CDVma_shadow_break_box_upperRR_labels = array.new_label() var label[] CDVma_shadow_break_box_lowerRR_labels = array.new_label() //===== CREATE RR LINES & LABELS (ONE TIME) ===== // Initialize RR lines and labels only once if isNewCDVma_shadow_break and array.size(CDVma_shadow_break_box_upperRR_lines) == 0 and box_showRRlines for i = 1 to box_RR_lines_count // Upper RR line array.push(CDVma_shadow_break_box_upperRR_lines, line.new(na, na, na, na, color=CDVma_colorup, width=1)) // Lower RR line array.push(CDVma_shadow_break_box_lowerRR_lines, line.new(na, na, na, na, color=CDVma_colordown, width=1)) // Upper RR label array.push(CDVma_shadow_break_box_upperRR_labels, label.new(na, na, "", color=color.new(CDVma_colorup, 100), style=label.style_label_right, textcolor=color.white, size=size.small)) // Lower RR label array.push(CDVma_shadow_break_box_lowerRR_labels, label.new(na, na, "", color=color.new(CDVma_colordown, 100), style=label.style_label_right, textcolor=color.white, size=size.small)) //===== UPDATE RR LINES & LABELS ===== // Recalculate RR levels and move lines on bar close if box_showRRlines float CDVma_shadow_break_box_range = array.get(CDVma_shadow_break_box_upper, 0) - array.get(CDVma_shadow_break_box_lower, 0) for i = 0 to array.size(CDVma_shadow_break_box_upperRR_lines) - 1 float CDVma_shadow_break_box_rr = (i + 1) float CDVma_shadow_break_box_upperRR = array.get(CDVma_shadow_break_box_upper, 0) + CDVma_shadow_break_box_range * CDVma_shadow_break_box_rr float CDVma_shadow_break_box_lowerRR = array.get(CDVma_shadow_break_box_lower, 0) - CDVma_shadow_break_box_range * CDVma_shadow_break_box_rr //----- Upper RR line & label ----- line.set_xy1(array.get(CDVma_shadow_break_box_upperRR_lines, i), bar_index + CDVma_shadow_break_box_left_offset, CDVma_shadow_break_box_upperRR) line.set_xy2(array.get(CDVma_shadow_break_box_upperRR_lines, i), bar_index + CDVma_shadow_break_box_right_offset, CDVma_shadow_break_box_upperRR) label.set_xy(array.get(CDVma_shadow_break_box_upperRR_labels, i), bar_index + CDVma_shadow_break_box_right_offset, CDVma_shadow_break_box_upperRR) label.set_text(array.get(CDVma_shadow_break_box_upperRR_labels, i), str.tostring(i + 1) + "R") //----- Lower RR line & label ----- line.set_xy1(array.get(CDVma_shadow_break_box_lowerRR_lines, i), bar_index + CDVma_shadow_break_box_left_offset, CDVma_shadow_break_box_lowerRR) line.set_xy2(array.get(CDVma_shadow_break_box_lowerRR_lines, i), bar_index + CDVma_shadow_break_box_right_offset, CDVma_shadow_break_box_lowerRR) label.set_xy(array.get(CDVma_shadow_break_box_lowerRR_labels, i), bar_index + CDVma_shadow_break_box_right_offset, CDVma_shadow_break_box_lowerRR) label.set_text(array.get(CDVma_shadow_break_box_lowerRR_labels, i), str.tostring(i + 1) + "R") ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// //──────────────────────────────────────────────────────────── // CDVma Trend Box + RR (Single Box, Array-based State) //──────────────────────────────────────────────────────────── //========= TREND RANGE ARRAYS // [0] = current trend // [1] = previous trend var float[] CDVma_trend_box_upper = array.new_float(2, na) var float[] CDVma_trend_box_lower = array.new_float(2, na) var box CDVma_trend_box = na // =====> This box will be used by the EA to retrieve the box ID and read its high and low information //========= RR ARRAYS var line[] CDVma_trend_box_upperRR_lines = array.new_line() var line[] CDVma_trend_box_lowerRR_lines = array.new_line() var label[] CDVma_trend_box_upperRR_labels = array.new_label() var label[] CDVma_trend_box_lowerRR_labels = array.new_label() //========= FLAGS bool CDVma_Trend_isNew = CDVma_isNewTrendUp or CDVma_isNewTrendDown bool CDVma_Trend_hasTrend = CDVma_trendState != 0 //──────────────────────────────────────────────────────────── // SHIFT PREVIOUS TREND RANGE //──────────────────────────────────────────────────────────── if CDVma_Trend_isNew array.set(CDVma_trend_box_upper, 1, array.get(CDVma_trend_box_upper, 0)) array.set(CDVma_trend_box_lower, 1, array.get(CDVma_trend_box_lower, 0)) //──────────────────────────────────────────────────────────── // SET CURRENT TREND RANGE //──────────────────────────────────────────────────────────── if CDVma_isNewTrendUp array.set(CDVma_trend_box_upper, 0, math.max(open, close)) array.set(CDVma_trend_box_lower, 0, math.min(CDVma_Cross_candleLow, CDVma_Cross_candleLow_prev)) if CDVma_isNewTrendDown array.set(CDVma_trend_box_upper, 0, math.max(CDVma_Cross_candleHigh, CDVma_Cross_candleHigh_prev)) array.set(CDVma_trend_box_lower, 0, math.min(open, close)) CDVma_trend_box_left_offset = CDVma_shadow_break_box_right_offset CDVma_trend_box_right_offset = CDVma_trend_box_left_offset + box_length CDVma_trend_box_color = CDVma_trendState == 1 ? CDVma_colorup : CDVma_trendState == -1 ? CDVma_colordown :color.yellow //──────────────────────────────────────────────────────────── // CREATE TREND BOX (ONE TIME ONLY) //──────────────────────────────────────────────────────────── if CDVma_Trend_isNew and na(CDVma_trend_box) and showCDVma_trend_box CDVma_trend_box := box.new( left = bar_index + CDVma_trend_box_left_offset, right = bar_index + CDVma_trend_box_right_offset, top = array.get(CDVma_trend_box_upper, 0), bottom = array.get(CDVma_trend_box_lower, 0), bgcolor = color.new(CDVma_trend_box_color, box_transp), border_color = CDVma_trend_box_color, text = name_CDVma_trend_box, //"Shadow\nTrend", text_color = color.white, force_overlay = true) //──────────────────────────────────────────────────────────── // UPDATE TREND BOX (MOVE + UPDATE RANGE) //──────────────────────────────────────────────────────────── if CDVma_Trend_hasTrend and not na(CDVma_trend_box) box.set_left (CDVma_trend_box, bar_index + CDVma_trend_box_left_offset) box.set_right (CDVma_trend_box, bar_index + CDVma_trend_box_right_offset) box.set_top (CDVma_trend_box, array.get(CDVma_trend_box_upper, 0)) box.set_bottom(CDVma_trend_box, array.get(CDVma_trend_box_lower, 0)) box.set_border_color(CDVma_trend_box, CDVma_trend_box_color) box.set_bgcolor(CDVma_trend_box, color.new(CDVma_trend_box_color, box_transp)) //──────────────────────────────────────────────────────────── // CREATE RR LINES & LABELS (ONE TIME) //──────────────────────────────────────────────────────────── if CDVma_Trend_isNew and box_showRRlines and array.size(CDVma_trend_box_upperRR_lines) == 0 for i = 1 to box_RR_lines_count array.push(CDVma_trend_box_upperRR_lines, line.new(na, na, na, na, color=CDVma_colorup, width=1)) array.push(CDVma_trend_box_lowerRR_lines, line.new(na, na, na, na, color=CDVma_colordown, width=1)) array.push(CDVma_trend_box_upperRR_labels, label.new(na, na, "", style=label.style_label_right, color=color.new(CDVma_colorup,100), textcolor=color.white, size=size.small)) array.push(CDVma_trend_box_lowerRR_labels, label.new(na, na, "", style=label.style_label_right, color=color.new(CDVma_colordown,100), textcolor=color.white, size=size.small)) //──────────────────────────────────────────────────────────── // UPDATE RR LINES & LABELS //──────────────────────────────────────────────────────────── if CDVma_Trend_hasTrend and box_showRRlines float CDVma_trend_box_range = array.get(CDVma_trend_box_upper, 0) - array.get(CDVma_trend_box_lower, 0) for i = 0 to array.size(CDVma_trend_box_upperRR_lines) - 1 float CDVma_trend_box_rr = (i + 1) float CDVma_trend_box_upperRR = array.get(CDVma_trend_box_upper, 0) + CDVma_trend_box_range * CDVma_trend_box_rr float CDVma_trend_box_lowerRR = array.get(CDVma_trend_box_lower, 0) - CDVma_trend_box_range * CDVma_trend_box_rr // Upper RR line.set_xy1(array.get(CDVma_trend_box_upperRR_lines, i), bar_index + CDVma_trend_box_left_offset, CDVma_trend_box_upperRR) line.set_xy2(array.get(CDVma_trend_box_upperRR_lines, i), bar_index + CDVma_trend_box_right_offset, CDVma_trend_box_upperRR) label.set_xy(array.get(CDVma_trend_box_upperRR_labels, i), bar_index + CDVma_trend_box_right_offset, CDVma_trend_box_upperRR) label.set_text(array.get(CDVma_trend_box_upperRR_labels, i), str.tostring(i+1) + "R") // Lower RR line.set_xy1(array.get(CDVma_trend_box_lowerRR_lines, i), bar_index + CDVma_trend_box_left_offset, CDVma_trend_box_lowerRR) line.set_xy2(array.get(CDVma_trend_box_lowerRR_lines, i), bar_index + CDVma_trend_box_right_offset, CDVma_trend_box_lowerRR) label.set_xy(array.get(CDVma_trend_box_lowerRR_labels, i), bar_index + CDVma_trend_box_right_offset, CDVma_trend_box_lowerRR) label.set_text(array.get(CDVma_trend_box_lowerRR_labels, i), str.tostring(i+1) + "R") ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// // ===================================================== // INPUTS / USER SETTINGS // ===================================================== showCDVma_ER_Signal = input.bool(true, "Show CDVma + ER> Signal", group="CDVma + ER> Signal") // Toggle to show/hide signals CDVma_ER_colorBUY = input.color(color.aqua, "Color BUY", inline="col", group="CDVma + ER> Signal") // Color for BUY signals CDVma_ER_colorSELL = input.color(color.fuchsia, "Color SELL", inline="col", group="CDVma + ER> Signal") // Color for SELL signals lookback_check_ER = input.int(5, "Lookback ER", minval = 1, group = "CDVma + ER> Signal") // Number of bars to look back for ER condition // Determine current CDVma trend CDVma_Up = breakshadow_cond_new_signal == 1 or CDVma_isNewTrendUp // True if CDVma indicates uptrend CDVma_Down = breakshadow_cond_new_signal == -1 or CDVma_isNewTrendDown // True if CDVma indicates downtrend // Determine ER (Entry/Exit) conditions ER_check = E_big_R_big_condUp or E_small_R_big_condUp or E_big_R_big_condDn or E_small_R_big_condDn // True if any ER condition occurs ER_check_Up = E_big_R_big_condUp or E_small_R_big_condUp // ER conditions for UP direction ER_check_Down = E_big_R_big_condDn or E_small_R_big_condDn // ER conditions for DOWN direction // ===================================================== // SIGNALS // ===================================================== bool CDVma_ER_buySignal = false // Initialize BUY signal bool CDVma_ER_sellSignal = false // Initialize SELL signal // ================= BUY ================= if CDVma_Up // If CDVma indicates an uptrend bool foundER = false // Flag to check if an ER condition has been found in the lookback for i = 0 to lookback_check_ER // Check each bar in the lookback period if not foundER and ER_check[i] // If ER not found yet and bar i meets ER condition foundER := true // Mark ER as found if ER_check_Up[i] // If ER is in the UP direction CDVma_ER_buySignal := true // Trigger BUY signal // ================= SELL ================= if CDVma_Down // If CDVma indicates a downtrend bool foundER = false // Flag to check ER for i = 0 to lookback_check_ER if not foundER and ER_check[i] // If ER not found yet and bar i meets ER condition foundER := true if ER_check_Down[i] // If ER is in the DOWN direction CDVma_ER_sellSignal := true // Trigger SELL signal // ===================================================== // PLOT / DISPLAY SIGNALS // ===================================================== plotshape(showCDVma_ER_Signal and CDVma_ER_buySignal, title = "BUY ER + CDVma", style = shape.diamond, location = location.belowbar, color = CDVma_ER_colorBUY, size = size.small) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal plotshape(showCDVma_ER_Signal and CDVma_ER_sellSignal, title = "SELL ER + CDVma", style = shape.diamond, location = location.abovebar, color = CDVma_ER_colorSELL, size = size.small) // add Alert, Send Notification, Send Mail // This plotshape will be used as a buffer in MT5 so the EA can read and use it as a signal ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// ////////////////////////////////////////////////// //////////////////////////////////////////////////