Core Architecture Shift in Pine v5
1. ta.lowestbars() Index Offset: ta.lowestbars(low[1], 15) returns a negative offset (e.g., -4 means 4 bars before bar 1, so 5 bars ago from the current candle). Subtracting this value converts it cleanly into a positive shift index (1 - (-4) = 5) that can index into low[5] or stochK[5].
2. Native Dynamic Indexing: In Pine v5, using variables inside series subscripting (stochK[shiftRecentLow]) is natively supported without needing array.get() calls.
3. plotshape() vs Objects: Unlike MT4/MT5 where drawing persistent chart objects clutters chart memory, plotshape() evaluates once per bar on the GPU/server engine and doesn't require any manual cleanup code.
4. Alert Engine Integration: The included alertcondition() functions allow instant webhook routing out to automated trading bots or Telegram alerts.
How to detect divergence in forex scalping?
Re: How to detect divergence in forex scalping?
Cool, but it seems to me little bit more complicated.
Do you think it is possible to make it more simple?
Do you think it is possible to make it more simple?
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
-
FXS Prop Desk
- Posts: 1689
- Joined: Wed Oct 07, 2026 9:52 am
Re: How to detect divergence in forex scalping?
The explanation of why a computer needs explicit pivots is helpful for beginners. The subtle problem is confirmation. A pivot defined as "higher than the 3 bars on each side" is only known 3 bars after it forms. If the EA compares the current bar's indicator value with an unconfirmed pivot, it will show divergences that vanish a few bars later, and the backtest will look better than live trading.
Using only confirmed pivots, and accepting that the signal arrives N bars late, keeps backtest and live behaviour the same. It also helps to require a minimum distance between the two pivots so tiny wiggles aren't counted as separate highs.
Using only confirmed pivots, and accepting that the signal arrives N bars late, keeps backtest and live behaviour the same. It also helps to require a minimum distance between the two pivots so tiny wiggles aren't counted as separate highs.
FXS Official Team | The Idea Lab & Strategy
-
Shadow Trader
- Posts: 5594
- Joined: Wed Sep 09, 2026 5:19 pm
Re: How to detect divergence in forex scalping?
Nice breakdown of the logic. Splitting it into "find two swing points, compare price, compare the oscillator" is much easier to follow than the ZigZag-based versions that float around.
One thing that's worth flagging for anyone building on this: the confirmation of a swing point always comes after the fact. If the code defines a swing low as a bar with two higher lows on each side, it can only confirm that swing two bars after it happens. In a backtest it's very easy to accidentally use the swing as soon as the low is printed, which means the EA is seeing the future and the results look far better than anything achievable live. Shifting the signal by the confirmation bars fixes it, but it also makes the entries noticeably later, which matters a lot on a one-minute chart.
The other practical issue is how far apart the two swings are allowed to be. If they're too close, almost every small wiggle becomes a "divergence". If they're too far apart, the market conditions between them may be completely different. Making the minimum and maximum distance explicit inputs and testing a few values helps show whether there's a real effect or just one lucky setting.
It's also worth counting how many divergences appear in a session. On fast timeframes they can be very frequent, and many of them resolve with price continuing in the trend direction anyway, so a filter for trend or higher-timeframe location usually does as much work as the divergence itself.
One thing that's worth flagging for anyone building on this: the confirmation of a swing point always comes after the fact. If the code defines a swing low as a bar with two higher lows on each side, it can only confirm that swing two bars after it happens. In a backtest it's very easy to accidentally use the swing as soon as the low is printed, which means the EA is seeing the future and the results look far better than anything achievable live. Shifting the signal by the confirmation bars fixes it, but it also makes the entries noticeably later, which matters a lot on a one-minute chart.
The other practical issue is how far apart the two swings are allowed to be. If they're too close, almost every small wiggle becomes a "divergence". If they're too far apart, the market conditions between them may be completely different. Making the minimum and maximum distance explicit inputs and testing a few values helps show whether there's a real effect or just one lucky setting.
It's also worth counting how many divergences appear in a session. On fast timeframes they can be very frequent, and many of them resolve with price continuing in the trend direction anyway, so a filter for trend or higher-timeframe location usually does as much work as the divergence itself.