Hallo brother, tried to ask the AI like Beatle and got the following/similar response. No offence. Maybe a code can clarify.pin12 wrote: Thu Sep 11, 2025 7:49 am The Snake NRP doesn't repaint the history. What you're interpreting as repainting is actually the update of the last candle, which is normal for any real-time indicator. If you look at bars that have already closed, they never change value or color.
analyse the following mt4 code. is the indicator truly non repainting on closed bars? recalculation on live forming bars is acceptable
Code: Select all
No, this indicator is not non-repainting. It repaints significantly on closed bars.
Detailed Breakdown of the Repainting Mechanism
The repainting originates from the SnakeFirstCalc(int Shift) function, which is responsible for calculating the indicator's foundational value.
1. The "Smoking Gun" in the Code
Let's examine the central loop within SnakeFirstCalc:
code Mql4
IGNORE_WHEN_COPYING_START
IGNORE_WHEN_COPYING_END
// ... inside SnakeFirstCalc(int Shift)
else
{
// ...
for (j = Shift - Snake_HalfCycle, i = Shift + Snake_HalfCycle, w = 1;
w <= Snake_HalfCycle;
j++, i--, w++)
{
Snake_Sum += w * (SnakePrice(i) + SnakePrice(j)); // <-- The problem is here
// ...
}
// ...
}
Shift: This is the index of the bar for which the indicator value is being calculated.
In MQL4, a higher index means an older bar (e.g., Shift=1 is the last closed bar, Shift=100 is 100 bars ago).
i = Shift + Snake_HalfCycle: This accesses data from the past, which is correct and non-repainting.
j = Shift - Snake_HalfCycle: This accesses data from the future. When the code is calculating the value for bar Shift,
it is looking ahead Snake_HalfCycle bars to get price data.
2. A Concrete Example
Let's assume the default Snake_HalfCycle = 5.
The indicator needs to calculate the value for the bar at Shift = 10 (a historical, closed bar).
The loop starts with j = 10 - 5 = 5.
It then proceeds to access SnakePrice(5), SnakePrice(6), SnakePrice(7), SnakePrice(8), and SnakePrice(9).
All of these bars are newer than the bar at Shift = 10.
When the bar at Shift = 10 originally closed, the prices for bars 5 through 9 were not yet finalized.
As each of those future bars forms and closes, the calculated value for the bar at Shift = 10 will change.
This is the definition of repainting on closed bars. The indicator's line will shift and redraw its past values as new price data
becomes available.
3. The Vertex Detection Logic Also Repaints
The second loop in the start() function, which determines the color changes, also repaints for two reasons:
It relies on repainting data: It reads from Snake_Buffer, which we've already established is calculated using future data.
Any logic built on top of repainting data will also repaint.
It looks ahead to find peaks/troughs: The logic if (valPrev > val && valPrev > valNext) checks the bars at i, i+1, and i+2 to find a
peak at i+1. To definitively know that i+1 is a peak, you must wait for the bar at i to form and confirm a lower value.
This is another form of looking into the future.
Why Does It Look So Perfect on a Chart?
Repainting indicators often look deceptively perfect in hindsight because they retroactively plot their signals at the
most optimal points (peaks and troughs) after those points have already formed. The signals were not actually there in real-time when
the bar closed. This makes them useless for live trading decisions, as the signals will appear, disappear, and move.
Summary
Feature Analysis
Is it Non-Repainting?
- No.
Primary Cause
- The SnakeFirstCalc function uses a centered moving average algorithm. By definition, a centered average requires data
from both the past and the future of a given data point, causing it to repaint.
Recalculation
- It recalculates values for up to Snake_HalfCycle closed bars every time a new tick arrives.
Usability for Trading
- Unreliable for real-time signal generation due to the repainting nature. The signals you see on the historical chart were not
present at the moment those bars closed.