This indicator is used specifically for heiken ashi candles. It indicates a reversal signal and only appears when a high volume doji candle forms
# Precision Trend Scalping (Non-Repaint, Intuitive, Plot on Last Confirming Bar)
# - Non-repainting: uses only completed prior candles for confirmation
# - Intuitive mapping: Above EMA -> flat bottoms (bullish), Below EMA -> flat tops (bearish)
# - Plots signal on the LAST confirming candle by shifting back minConsecutiveCandles bars
# Precision Trend Scalping (Non-Repaint, Intuitive, Plot on Last Confirming Bar)
# - Non-repainting: uses only completed prior candles for confirmation
# - Intuitive mapping: Above EMA -> flat bottoms (bullish), Below EMA -> flat tops (bearish)
# - Plots signal on the LAST confirming candle by shifting back minConsecutiveCandles bars
Code:
# Precision Trend Scalping (Non-Repaint, Intuitive, Plot on Last Confirming Bar)
# - Non-repainting: uses only completed prior candles for confirmation
# - Intuitive mapping: Above EMA -> flat bottoms (bullish), Below EMA -> flat tops (bearish)
# - Plots signal on the LAST confirming candle by shifting back minConsecutiveCandles bars
declare upper;
input emaLength = 100;
input minConsecutiveCandles = 2;
input maxWickRatio = 0.05;
input maxWickTicks = 2;
input maxDojiBodyRatio = 0.3;
input minWickTotalRatio = 0.7;
# -------------------------
# EMA
# -------------------------
def ema = ExpAverage(close, emaLength);
plot EMAline = ema;
EMAline.SetDefaultColor(Color.WHITE);
# -------------------------
# Heikin Ashi (Manual Calculation - Compatible)
# -------------------------
rec haClose = (open + high + low + close) / 4;
rec haOpen =
if BarNumber() == 1
then (open + close) / 2
else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haOpen, haClose));
def haLow = Min(low, Min(haOpen, haClose));
def haBullish = haClose > haOpen;
def haBearish = haClose < haOpen;
def haTotalSize = haHigh - haLow;
def haBodySize = AbsValue(haClose - haOpen);
def haUpperWick = haHigh - Max(haOpen, haClose);
def haLowerWick = Min(haOpen, haClose) - haLow;
def wickTolerance = TickSize() * maxWickTicks;
def okSize = haTotalSize > 0;
def haFlatBottom =
haBullish and okSize and
(haLowerWick / haTotalSize <= maxWickRatio) and
(haLowerWick <= wickTolerance);
def haFlatTop =
haBearish and okSize and
(haUpperWick / haTotalSize <= maxWickRatio) and
(haUpperWick <= wickTolerance);
def haDoji =
okSize and
(haBodySize / haTotalSize <= maxDojiBodyRatio) and
((haUpperWick + haLowerWick) / haTotalSize >= minWickTotalRatio);
def prevTotal = haHigh[1] - haLow[1];
def largerThanPrev = haTotalSize >= prevTotal;
# -------------------------
# EMA zones (regular candles)
# -------------------------
def fullyAboveEMA = low > ema;
def fullyBelowEMA = high < ema;
# -------------------------
# Consecutive confirmation using ONLY prior completed bars:
# Require the last N bars (1..N) to all be flat.
# -------------------------
def allPriorFlatBottoms =
(fold fb_i = 1 to minConsecutiveCandles + 1
with fb_flag = 1
do fb_flag * (if GetValue(haFlatBottom, fb_i) then 1 else 0)) == 1;
def allPriorFlatTops =
(fold ft_i = 1 to minConsecutiveCandles + 1
with ft_flag = 1
do ft_flag * (if GetValue(haFlatTop, ft_i) then 1 else 0)) == 1;
# Confirmed signals (true on the bar AFTER the last confirming bar)
def bullishConfirmed = fullyAboveEMA and allPriorFlatBottoms and haDoji and largerThanPrev;
def bearishConfirmed = fullyBelowEMA and allPriorFlatTops and haDoji and largerThanPrev;
# Shift plots back so the arrow prints on the LAST confirming bar
plot Bull = bullishConfirmed[minConsecutiveCandles];
Bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bull.SetDefaultColor(Color.LIME);
Bull.SetLineWeight(3);
plot Bear = bearishConfirmed[minConsecutiveCandles];
Bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bear.SetDefaultColor(Color.RED);
Bear.SetLineWeight(3);
Last edited by a moderator: