Untitled
unknown
plain_text
a year ago
5.6 kB
5
Indexable
Never
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © VinDB //@version=5 indicator("BTX V2", overlay = true, max_boxes_count = 500) // Define input variables len = input.int(10, "Lookback Length") thresh = input.float(30.0, "Minimum Body Size (%)") min_body_size = input.float(40.0, "Minimum Body Size of First Candle (%)") patternDisplay = input.bool(false, "Display Patterns", inline="display") fvgDisplay = input.bool(false, "Display FVG", inline="display") // Compute body size thresholds thresh_abs = thresh / 100 * ta.atr(len) min_body_size_abs = min_body_size / 100 * ta.atr(len) // Compute candle characteristics for bullish engulfing pattern is_bearish = close < open is_bullish = close > open is_large_body = math.abs(close - open) >= thresh_abs is_higher_low = low > low[1] and high > high[1] is_engulfing_bullish = is_bearish[1] and is_bullish and is_large_body and is_higher_low and close > open[1] is_large_body_1 = math.abs(close[1] - open[1]) >= min_body_size_abs is_bearish_1 = close[1] < open[1] // Compute candle characteristics for bearish engulfing pattern is_bullish_2 = close > open is_bearish_2 = close < open is_large_body_2 = math.abs(close - open) >= thresh_abs is_lower_high = low < low[1] and high < high[1] is_engulfing_bearish = is_bullish_2[1] and is_bearish_2 and is_large_body_2 and is_lower_high and close < open[1] is_large_body_3 = math.abs(close[1] - open[1]) >= min_body_size_abs is_bullish_3 = close[1] > open[1] // Plot signals plotshape(is_engulfing_bullish and is_large_body_1 and is_bearish_1 and patternDisplay, title="Custom Bullish Engulfing", style=shape.labelup, text="", location=location.belowbar, color=color.green, textcolor=color.white) plotshape(is_engulfing_bearish and is_large_body_3 and is_bullish_3 and patternDisplay, title="Custom Bearish Engulfing", style=shape.labeldown, text="", location=location.abovebar, color=color.red, textcolor=color.white) fvgStructBreakingColor = color.rgb(31, 131, 84) fvgStructBreakingColorDn = color.rgb(219, 39, 39) fvgBorderTransparency = fvgDisplay ? 90 : 100 fvgBoxBorder = line.style_solid fvgLabelSize = size.small fvgLabelColor = fvgDisplay ? color.white : color.new(color.white, 100) fvgAvailable = input.int(5, "FVG Lookahead Length") fvgMinPips = input.float(2.0, "FVG minimum (in pips)", 0, step=0.1) var bullBoxes = array.new_box() var bearBoxes = array.new_box() GetPipSize() => syminfo.mintick * (syminfo.type == "forex" ? 10 : 1) if close[1] > high[2] and low > high[2] and math.abs(high[2]-low) / GetPipSize() > fvgMinPips _box = box.new(bar_index-2, low, bar_index+fvgAvailable, high[2], bgcolor=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1, text="FVG", text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor) array.push(bullBoxes, _box) if close[1] < low[2] and high < low[2] and math.abs(high-low[2]) / GetPipSize() > fvgMinPips _box = box.new(bar_index-2, high, bar_index+fvgAvailable, low[2], bgcolor=color.new(fvgStructBreakingColorDn, fvgBorderTransparency), border_color=color.new(fvgStructBreakingColorDn, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1, text="FVG", text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor) array.push(bearBoxes, _box) bullMsg = input.string("Bull signal", "Bull message") bearMsg = input.string("Bear signal", "Bear message") maxBox = 3 // for i=1 to array.size(bullBoxes)>0 ? array.size(bullBoxes)-1 : na if array.size(bullBoxes) > 0 box = array.get(bullBoxes, array.size(bullBoxes)-1) if low < math.max(box.get_top(box), box.get_bottom(box)) and box.get_right(box) > bar_index box.set_right(box, bar_index) if array.size(bearBoxes) > 0 box = array.get(bearBoxes, array.size(bearBoxes)-1) if high > math.min(box.get_top(box), box.get_bottom(box)) and box.get_right(box) > bar_index box.set_right(box, bar_index) if array.size(bullBoxes) > 0 and is_engulfing_bullish and is_large_body_1 and is_bearish_1 box = array.get(bullBoxes, array.size(bullBoxes)-1) if box.get_right(box) >= bar_index-1 if (low < math.max(box.get_top(box), box.get_bottom(box)) and math.min(close, open) > math.max(box.get_top(box), box.get_bottom(box))) or (low[1] < math.max(box.get_top(box), box.get_bottom(box)) and math.min(close[1], open[1]) > math.max(box.get_top(box), box.get_bottom(box))) label.new(bar_index, low, "", color=color.lime, style=label.style_label_up) alert(bullMsg, alert.freq_once_per_bar_close) if array.size(bearBoxes) > 0 and is_engulfing_bearish and is_large_body_3 and is_bullish_3 box = array.get(bearBoxes, array.size(bearBoxes)-1) if box.get_right(box) >= bar_index-1 // if high > math.min(box.get_top(box), box.get_bottom(box)) or high[1] > math.min(box.get_top(box), box.get_bottom(box)) if (high > math.min(box.get_top(box), box.get_bottom(box)) and math.max(close, open) < math.min(box.get_top(box), box.get_bottom(box))) or (high[1] > math.min(box.get_top(box), box.get_bottom(box)) and math.max(close[1], open[1]) < math.min(box.get_top(box), box.get_bottom(box))) label.new(bar_index, high, "", color=color.orange, style=label.style_label_down) alert(bearMsg, alert.freq_once_per_bar_close)