Attachments forums

Re: Rijay's System of Moving Averages

rijay, Thu Jun 04, 2026 8:30 pm

thomdel wrote: Thu Jun 04, 2026 5:15 pm Reason for this Post :
Read the above 2 to 3 posts , but it creates a confusion as to which Indicator is appropriate / correct / right.


Respected Rijay,

Which indicator is Right to Use ? ( Which Indicator will provide the Right info )


XU-MA v3 bg with time frame selection for candles and background both
Or
XU-MA v3 bg with time frame selection for candles and background both new mtf logic


moving_averages gradient color candles mtf 1 four color candle bg arrow
Or
moving_averages gradient color candles mtf 1 four color candle bg arrow nrp
Or
moving_averages gradient color candles mtf 1 four color candle bg arrow nrp true



Thanks for your Indicators, Time, Efforts, Shares.
Thanks a Lot.


if you want more option like background coloring, mtf and arrow display besides color candle , you can use this version, where option of both moving average candle coloring and candle coloring according to xu ma v3 are there in it to select from


to understand what logic is used in this indicator, just asking antigravity or codex is good option.



code interpretation--
Overall Purpose
It's a multi-timeframe (MTF) moving average indicator that colors candles, draws MA lines, shows trend/signal MAs (XU-MA), paints background, and draws alignment arrows — all driven by MA slope and position logic.

Core Components
1. Gradient Color Moving Average Lines
Two MA lines are plotted — a fast MA (e.g. period 14) and a slow MA (e.g. period 34). Both use the same 20-step gradient palette:

The slope angle of the MA is calculated against ATR (normalized angle): angle = atan(change / (ATR × bars)) × 180/π
The angle is mapped to one of 20 color steps between ColorTo (down color, e.g. DeepPink) and ColorFrom (up color, e.g. Lime)
Steep upward slope → vivid green end; steep downward slope → vivid pink end; flat → middle color
2. Colored Candles (4-color MA-position mode)
Each candle is colored based on price position relative to both MAs:

Condition Color
Price below both MAs Red (Bearish)
Price above both MAs Blue (Bullish)
Price below fast, above slow LightBlue
Price above fast, below slow LightRed
When CandleColorTF is set to a higher timeframe (e.g. H4 on an H1 chart), the color is derived from HTF MA values instead of current-chart MAs.

3. MTF Color-Lock (Non-Repainting)
This is the key logic we implemented. The problem it solves:

Without this, every H1 candle inside the same H4 bar would retroactively change color every tick as the H4 MA shifts.

How it works:

A candleColorLocked[] buffer tracks which bars have been permanently assigned
When a lower-TF bar first closes (transitions from bar 0 to bar 1), the HTF color at that exact moment is written and locked = 1.0
On every subsequent tick, if locked == 1.0, the bar is skipped — its color never changes again
Only the live forming bar (i == 0) always recalculates freely
This same lock pattern is applied to:

Candle colors (candleColorLocked) — via CandleColorTF
Arrow state (arrowStateLocked) — via TF1/TF2
XU-MA state (xuTrendLocked) — via TRENDtf/SIGNALtf
4. TF Alignment Arrows
Compares MA color state on two user-selected timeframes (TF1, TF2):

Both blue (bullish) → up arrow (↑) drawn below the bar, state = 1.0
Both red (bearish) → down arrow (↓) drawn above the bar, state = 0.0
Uses edge detection — arrow only fires on the first bar where alignment occurs, not on every subsequent bar
Arrow state is also used to color candles in CANDLE_COLOR_ARROW mode.

5. XU-MA TREND + SIGNAL (Band-based MA)
Two separate MAs (TREND and SIGNAL) each use three handles:

MA(PRICE_HIGH) — upper band
MA(PRICE_LOW) — lower band
MA(median/close) — center line for display
Direction logic per MA:

price > MA(High) → direction = +1 (bullish breakout above band)
price < MA(Low) → direction = -1 (bearish breakdown below band)
price inside band → direction = hold previous (persistence/no-flip zone)
Combined xtrend:

TREND=+1 AND SIGNAL=+1 → xtrend = +1 (both bull → Blue line)
TREND=-1 AND SIGNAL=-1 → xtrend = -1 (both bear → Crimson line)
anything else → xtrend = 0 (disagreement → no line)
In CANDLE_COLOR_XUMT mode, candles use xtrend:

xtrend=+1 → Blue
xtrend=-1 → Red
TREND bull but SIGNAL not → LightBlue
TREND bear but SIGNAL not → LightRed
6. Background Coloring
Uses OBJ_RECTANGLE objects drawn behind the chart (OBJPROP_BACK=true). Each bar gets a rectangle from its open time to its close time, colored to match the candle color. BgMaxBars limits how far back rectangles are drawn. All rectangles are cleaned up in OnDeinit and when the feature is toggled off.

7. Candle Color Mode Switch
Three modes selectable via CandleColorMode:

Mode Source
CANDLE_COLOR_MA 4-color MA position logic
CANDLE_COLOR_ARROW Arrow state (TF1/TF2 alignment)
CANDLE_COLOR_XUMT XU-MA TREND+SIGNAL xtrend
All files in topic