 # FOREX Divergence

An indication that an end to the current trend may be near occurs when the indicator diverges from the security.
A bullish forex divergence occurs when [MACD, Stochastic, RSI, Momentum, Bollinger Bands, PowerRVI or OBV] is making new highs while prices fail to reach new highs.
A bearish forex divergence occurs when  [MACD, Stochastic, RSI, Momentum, Bollinger Bands, PowerRVI or OBV] is making new lows while prices fail to reach new lows.
Both of these divergences are most significant when they occur at relatively overbought/oversold levels.

The main rule is simple. Sell on a bearish forex divergence. Buy on a bullish forex divergence.

## Bullish Forex divergence: Bearish Forex divergence: ## Fractals

A fractal is a series of at least five successive bars, with the highest HIGH in the middle, and two lower HIGHs on both sides.
The reversing set is a series of at least five successive bars, with the lowest LOW in the middle, and two higher LOWs on both sides, which correlates to the sell fractal. Standard Bill William's fractals have period 2: 2+1+2 = 5 bars. We use extended version of fractals with custom period.
In case Fractal.Period = 1 we get 1+1+1 = 3 bars model.
In case Fractal.Period = 3 we get 3+1+3 = 7 bars model.
In case Fractal.Period = 5 we get 5+1+5 = 11 bars model.
etc.

## Forex Divergence Parameters  --- Common ---
extern int AccDigits = 5;
// set AccDigits = 4 if you broker provides 4-digits quotes
// set AccDigits = 5 if you broker provides 5-digits quotes
// in case AccDigits = 5 all pips values will be automatically adjusted by 10

extern int MaxBars = 1000;
// to increase the perfomance we draw the indicator for 1000 last bars only

--- Divergence ---
extern int LeftFractal.Period = 3;
// left-hand divergence peak is 3-bars fractal,  we check 3 bars on both sides to confirm the peak

extern int RightFractal.Period = 1;
// right-hand divergence peak is 1-bars fractal, we check 1 bar on both sides to confirm the peak extern int Width.Min = 1;
// minimal horizontal distance between 2 divergence peaks, bars

extern int Width.Max = 25;
// maximal horizontal distance between 2 divergence peaks, bars

extern int Height.Min = 15;
//minimal vertical distance between 2 divergence peaks, pips

extern int Height.Max = 1000;
// maximal vertical distance between 2 divergence peaks, pips --- Graphic ---
extern int Shift.Arrow = 20;
// vertical shift of a divergence arrow (right-hand divergence peak) on the chart, pips

extern int Shift.Dot = 10;
// vertical shift of a divergence dot (left-hand divergence peak) on the chart, pips

extern int Shift.Line = 1;
// vertical shift of the line between divergence dot and arrow, pips

extern int SignalBar = 1;
// indicator checks this bar for new divergence siganls
// SignalBar value is always equal or higher than RightFractal.Period value
// if RightFractal.Period = 0 then correct SignalBar values ar 0,1,2,3, ...
// if RightFractal.Period = 1 then correct SignalBar values are 1,2,3, ...
// if RightFractal.Period = 2 then correct SignalBar values are 2,3,4, ...
// etc.

extern bool PopupOn = true;
// show popup alert on new divergence true/false extern bool SoundOn = true;
// play sound alert on new divergence true/false