i-divergencebar
Download scriptThis script is designed to assist traders by identifying specific price action patterns that may signal a potential trend reversal or exhaustion. It functions by analyzing the relationship between current price bars and a specialized moving average system known as the "Alligator."
Core Logic Overview
The tool monitors the market for "divergent" candles—specific instances where the price moves in one direction, but the internal strength of that move appears inconsistent with the overall trend. It focuses on identifying these moments by comparing three specific components of the Alligator indicator: the Lips, the Teeth, and the Jaw.
How the Analysis Works
The script processes historical data to calculate the highest and lowest boundaries formed by these three moving averages. It then scans each price bar to see if it meets specific "reversal" criteria:
1. Identifying Upward Exhaustion (Bearish Signals) The tool looks for bars where the high price is higher than the previous bar, but the closing price fails to stay in the upper half of that bar's range. If this occurs while the price is also positioned above the Alligator boundaries, the script identifies a potential weakness in the upward momentum.
2. Identifying Downward Exhaustion (Bullish Signals) Conversely, the tool looks for bars where the low price is lower than the previous bar, but the closing price remains in the upper half of that bar's range. If this happens while the price is below the Alligator boundaries, it flags a potential weakness in the downward momentum.
Visual Representation
When these specific conditions are met, the script marks the chart with distinct visual histograms:
- Red Markers: Appear when the script detects signs of upward exhaustion (potential selling opportunities).
- Lime Markers: Appear when the script detects signs of downward exhaustion (potential buying opportunities).
Key Features for the User
- Customizable Lookback: Users can define how many bars back the script should analyze to keep the chart clean and responsive.
- Visual Customization: The thickness of the visual markers can be adjusted to suit different screen layouts.
- Automated Filtering: Rather than requiring a trader to manually calculate moving average boundaries, the script automatically filters out market "noise" to only highlight bars that show significant price-action divergence.
//+******************************************************************+
//| i-DivergenceBar.mq4 |
//| Copyright © 2010, Dmitry Zhebrak aka Necron |
//| www.mqlcoder.ru |
//+------------------------------------------------------------------+
//|Äàííûé ïðîäóêò ïðåäíàçíà÷åí äëÿ íåêîìåð÷åñêîãî |
//|èñïîëüçîâàíèÿ. Ïóáëèêàöèÿ ðàçðåøåíà òîëüêî ïðè óêàçàíèè èìåíè |
//|àâòîðà ( Necron ). Ðåäàêòèðîâàíèå èñõîäíîãî ðàçðåøàåòñÿ òîëüêî ïðè|
//|óñëîâèè ñîõðàíåíèÿ äàííîãî òåêñòà, ññûëîê è èìåíè àâòîðà. Ïðîäàæà |
//|èíäèêàòîðà èëè îòäåëüíûõ åãî ÷àñòåé ÇÀÏÐÅÙÅÍÀ. |
//|Àâòîð íå íåñåò îòâåòñòâåííîñòè çà âîçìîæíûå óáûòêè, ïîëó÷åííûå â |
//|ðåçóëüòàòå èñïîëüçîâàíèÿ èíäèêàòîðà. |
//|Ïî âñåì âîïðîñàì, ñâÿçàííûìè ñ ðàáîòîé èíäèêàòîðà èëè |
//|èëè ïðåäëîæåíèÿìè ïî åãî äîðàáîòêå îáðàùàòüñÿ íà email: |
//|mqlcoder@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, D.Zhebrak aka Necron"
#property link "www.mqlcoder.ru"
#property link "mailto: mqlcoder@yandex.ru"
//---
#define version "1.0.0.0"
//---- ïîäêëþ÷àåì ÿäðî ñèñòåìû Profitunity_MT4
//---- íàñòðîéêè öâåòîâ äëÿ îòîáðàæåíèÿ
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Lime
//---- âíåøíèå íàñòðîéêè èíäèêàòîðà
extern int BarsToProcess=200; //ìàêñèìàëüíîå êîëëè÷åñòâî áàðîâ äëÿ ðàñ÷åòà (-1 âñå)
extern int width=2; //òîëùèíà îòîáðàæåíèÿ òåëà ðàçâðîòíîãî áàðà
//---- áóôåðû äëÿ îòîáðàæåíèÿ èíäèêàòîðà
double UpBuffer1[],
DnBuffer1[],
UpBuffer2[],
DnBuffer2[];
//+------------------------------------------------------------------+
//| Èíöèàëèçàöèÿ èíäèêàòîðà |
//+------------------------------------------------------------------+
int init()
{
//---- íà÷àëî èíöèàëèçàöèè èíäèêàòîðà
//---- ñâÿçûâàåì ìàññèâ ñ áóôåðîì èíäèêàòîðà
SetIndexBuffer(0,UpBuffer1);
SetIndexBuffer(1,DnBuffer1);
SetIndexBuffer(2,UpBuffer2);
SetIndexBuffer(3,DnBuffer2);
//---- óñòàíîâèì ñòèëü îòîáðàæåíèÿ ëèíèé
SetIndexStyle(0,DRAW_HISTOGRAM,0,width);
SetIndexStyle(1,DRAW_HISTOGRAM,0,width);
SetIndexStyle(2,DRAW_HISTOGRAM,0,width);
SetIndexStyle(3,DRAW_HISTOGRAM,0,width);
//---- óñòàíîâèì êîðîòêîå èìÿ èíäèêàòîðà è êàæäîé ëèíèè â îòäåëüíîñòè
IndicatorShortName("i-DiverBar");
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
SetIndexLabel(4,NULL);
SetIndexLabel(5,NULL);
//---- èíèöèàëèçàöèÿ çàâåðøåíà
return(0);
}
//+------------------------------------------------------------------+
//| Äåèíèöèàëèçàöèÿ èíäèêàòîðà |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Ðàñ÷åò èíäèêàòîðà |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted(),limit;
double lips,teeth,jaw,up,dn;
//---- ïðîâåðêà íà âîçìîæíûå îøèáêè
if(counted_bars<0) return(-1);
//---- ïðîâåðêà íàëè÷èÿ èñòîðèè
if(iBars(Symbol(),Period())<14)
{
Print("Íåäîñòàòî÷íî áàðîâ äëÿ ðàñ÷åòà èíäèêàòîðà!");
return(-1);
}
//---- íàéäåì êîëè÷åñòâî áàðîâ äëÿ ðàñ÷åòà èíäèêàòîðà
limit=Bars-counted_bars-1;
if(Bars-counted_bars>2) limit=Bars-35;
if(limit>BarsToProcess && BarsToProcess>0) limit=BarsToProcess;
//---- îòîáðàçèì èíäèêàòîð
for(i=limit;i>=0;i--)
{
UpBuffer1[i] =EMPTY;
UpBuffer2[i] =EMPTY;
//---
DnBuffer1[i] =EMPTY;
DnBuffer2[i] =EMPTY;
//---
lips=iAlligator(Symbol(),Period(),13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,i);
teeth=iAlligator(Symbol(),Period(),13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,i);
jaw=iAlligator(Symbol(),Period(),13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,i);
//---
up=MathMax(lips,MathMax(teeth,jaw));
dn=MathMin(lips,MathMin(teeth,jaw));
//---
if(High[i]>High[i+1] && Close[i]<High[i]-0.5*(High[i]-Low[i]) && Low[i]>up)
{
UpBuffer1[i] = Low[i]+(High[i]-Low[i])/2+(High[i]-Low[i])/10;
DnBuffer1[i] = Low[i]+(High[i]-Low[i])/2-(High[i]-Low[i])/10;
}
else
if(Low[i]<Low[i+1] && Close[i]>Low[i]+0.5*(High[i]-Low[i]) && High[i]<dn)
{
UpBuffer2[i] = Low[i]+(High[i]-Low[i])/2+(High[i]-Low[i])/10;
DnBuffer2[i] = Low[i]+(High[i]-Low[i])/2-(High[i]-Low[i])/10;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments