Indicator · Pine Script v6 · On the chart

LuckyFX RBtrader strategy

by MeridianAlgo

LuckyFX RBtrader strategy is a price-chart candle filter.

View on GitHub

GitHub stars9on the repository
Pine versionv6current
Lines of code81
Settings10inputs
LicenceMIT
Last update4 months ago29 Jun 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

81 lines of Pine Script v6 from examples/RBT_strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

RBT_strategy.pine
// 16 nov 2025 23:45
//Logic--> cur should min 30% - max 300% of prev + check doji + check Engulfing + check last 0-4 same orev candle + check mean of atleast 2-50 prev 
//Last update on 02 Dec 2025 New function add---> prev candle high/low taken by cur high/low (On Off botton)
// all have on off options this is latest version
//
// working excellent in XAUUSD 


//@version=6
indicator("LuckyFX RBtrader strategy", overlay=true)

// ----- Inputs & Filters -----
enable_prev_candles  = input.bool(true, "Check: Prev Candles Same Dir?")
same_prev_candles    = input.int(2,    "Prev Candles Same (0–4)", minval=0, maxval=4)
enable_body_percent  = input.bool(true, "Check: Cur > % Prev Body?")
body_percent_min     = input.float(0.3, "Body % Min (0.3)", minval=0.3, maxval=2.0, step=0.05)
body_percent_max     = input.float(3.0, "Body % Max (3.0)", minval=0.3, maxval=3.0, step=0.05)
ignore_doji          = input.bool(true, "Ignore if Prev is Doji")
enable_mean_range    = input.bool(true, "Check: Cur >= Mean Full Candle?")
mean_length          = input.int(5,    "Mean Candle Range (2-50)", minval=2, maxval=50)
ignore_engulf        = input.bool(true, "Ignore if Engulfing (Body Size)")

// ----- NEW: Wick compare toggle -----
enable_wick_compare  = input.bool(false, "Check: Cur wick > Prev wick (on/off)")

// ----- Candle Info -----
prev_open  = open[1]
prev_close = close[1]
prev_high  = high[1]
prev_low   = low[1]
prev_body  = math.abs(prev_close - prev_open)
prev_upper_wick = prev_high - math.max(prev_open, prev_close)
prev_lower_wick = math.min(prev_open, prev_close) - prev_low
prev_total_wick = prev_upper_wick + prev_lower_wick
prev_is_doji = prev_total_wick >= 2 * prev_body
prev_is_bull = prev_close > prev_open
prev_is_bear = prev_close < prev_open

cur_body = math.abs(close - open)
cur_range = high - low
is_bull = close > open
is_bear = close < open
is_bullish_engulf = cur_body > (prev_body + prev_upper_wick)
is_bearish_engulf = cur_body > (prev_body + prev_lower_wick)

// ----- Current wicks -----
cur_upper_wick = high - math.max(open, close)
cur_lower_wick = math.min(open, close) - low

// ---- Mean Full Candle Range (high-low of previous N candles) ----
sum_range = 0.0
for i = 1 to mean_length
    sum_range := sum_range + (high[i] - low[i])
mean_prev_range = sum_range / mean_length
is_cur_range_big_enough = not enable_mean_range or cur_range >= mean_prev_range

// ----- Prev Dir Logic for Flexible N -----
prev_dir = prev_is_bull ? 1 : prev_is_bear ? -1 : 0
match = true
if same_prev_candles > 0
    for i = 2 to same_prev_candles + 1
        match := match and ((close[i] > open[i] ? 1 : close[i] < open[i] ? -1 : 0) == prev_dir)
last_n_same_as_prev = not enable_prev_candles or (prev_dir != 0 and match)

// ----- Body % threshold check -----
body_percent_ok = not enable_body_percent or (cur_body > body_percent_min * prev_body and cur_body < body_percent_max * prev_body)

// ----- Wick comparison condition (single-line to avoid parser issues) -----
wick_condition = not enable_wick_compare or ((is_bull and cur_lower_wick > prev_lower_wick) or (is_bear and cur_upper_wick > prev_upper_wick))

// ----- Signal logic -----
bull_bigger_than_bear = is_bull and prev_is_bear and body_percent_ok and (not ignore_doji or not prev_is_doji) and (not ignore_engulf or not is_bullish_engulf) and last_n_same_as_prev and is_cur_range_big_enough and wick_condition
bear_bigger_than_bull = is_bear and prev_is_bull and body_percent_ok and (not ignore_doji or not prev_is_doji) and (not ignore_engulf or not is_bearish_engulf) and last_n_same_as_prev and is_cur_range_big_enough and wick_condition

// ----- Plot (constant shape/size) -----
// removed explicit alpha from color to keep syntax safe
plotshape(bull_bigger_than_bear, style=shape.triangleup, color=color.rgb(38, 129, 11), size=size.small, location=location.belowbar, title="Bullish Signal")
plotshape(bear_bigger_than_bull, style=shape.triangledown, color=color.rgb(226, 10, 10), size=size.small, location=location.abovebar, title="Bearish Signal")

alertcondition(bull_bigger_than_bear, title="Bullish Signal", message="Bullish > Bearish Setup")
alertcondition(bear_bigger_than_bull, title="Bearish Signal", message="Bearish > Bullish Setup")

Overview

LuckyFX RBtrader strategy marks a bullish condition when the current candle is bullish, the previous candle is bearish, and optional checks pass: body size between a minimum and maximum share of the previous body, prior candles sharing direction, current range at least the mean of recent ranges, and a wick comparison. Bearish conditions reverse those roles. Toggles can ignore dojis and engulfing bodies. It does not place orders or set stops.

Details

Published by

MeridianAlgo on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Candlestick patterns

Markets

Gold

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

code-converterconverterjavascriptpinescripttranspilercode-reviewmeridianalgocode-conversionpinescript-algorithms

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Check: Prev Candles Same Dir?booltrueenable_prev_candles
Prev Candles Same (0–4)int2same_prev_candles
Check: Cur > % Prev Body?booltrueenable_body_percent
Body % Min (0.3)float0.3body_percent_min
Body % Max (3.0)float3.0body_percent_max
Ignore if Prev is Dojibooltrueignore_doji
Check: Cur >= Mean Full Candle?booltrueenable_mean_range
Mean Candle Range (2-50)int5mean_length
Ignore if Engulfing (Body Size)booltrueignore_engulf
Check: Cur wick > Prev wick (on/off)boolfalseenable_wick_compare
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Heikin-Ashi Chart Identifier is an indicator that checks if the current chart uses Heikin-Ashi candles. It tracks matched candles where open equals the average of previous open and close, and verifies no gaps between bars. When conditions match, it display

Indicator v4 Candlestick patterns
Updated 10 days ago · GPL-3.0 GitHub repository of Heikin-Ashi Chart Identifier
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 4 years ago · None stated GitHub repository of [RS]MTF Candle Sticks
257 stars

This indicator detects a large set of classic candlestick patterns and plots colored labels on the price chart. Trend context uses a 50-period simple moving average, or the 50 and 200 averages stacked together, and can be switched off. Users filter bullish, be

Indicator v4 Candlestick patternsTrend
Updated 6 weeks ago · None stated GitHub repository of Snag - All Candlestick Patterns

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers