Fine_Fractals_v1
Download scriptThis tool is designed to identify specific turning points in price action on a trading chart. It works by scanning historical price data to locate "fractals"—which are essentially peaks and valleys where the market changes direction—and marking them clearly for the user.
The logic behind this script can be broken down into three primary functions:
1. Identification of Market Peaks and Valleys
The script continuously monitors the high and low prices of candles to find structural extremes. It looks for instances where a price point is higher (for a peak) or lower (for a valley) than the candles immediately surrounding it. When these conditions are met, the tool places visual markers on the chart:
- Upper Fractals: Marked in red to signify a local ceiling or resistance point.
- Lower Fractals: Marked in green to signify a local floor or support point.
2. Advanced Sensitivity and Precision
The script includes specific logic to increase the accuracy of these markers under certain market conditions:
- Fine Sensitivity: This feature allows the tool to be more "permissive" in identifying a fractal. It checks the surrounding price action more deeply to ensure that even subtle peaks or valleys are captured, which might be missed by standard identification methods.
- Flat Shift Logic: Markets often move sideways in "flat" periods where several candles in a row share the exact same high or low price. This script contains a mechanism to detect these flat zones and automatically shift the marker to the earliest point of that movement. This prevents the markers from appearing cluttered and ensures they represent the true beginning of a structural change.
3. Real-Time Monitoring and Alerts
Beyond just drawing on the chart, the script is capable of active monitoring. It can be configured to watch for brand-new fractals as they form in real-time. If a new peak or valley is confirmed at the most recent data point, the script can trigger a pop-up alert, notifying the user immediately of the price action change without them having to constantly watch the screen.
Summary for the User: Think of this tool as an automated "high-low" scanner. It cleans up the noise of the market by identifying significant turning points, ensuring that flat price movements don't create confusing duplicates, and providing optional notifications so you can stay informed on price shifts as they happen.
//+------------------------------------------------------------------+
//| Fine Fractals.mq4 |
//| Copyright © 2009 Äåíèñ Îðëîâ |
//| http://denis-or-love.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009 Äåíèñ Îðëîâ"
#property link "http://denis-or-love.narod.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern bool Fine=True;
extern bool FlatShift=True;
extern bool NewFAlert=False;
//+------------------------------------------------------------------+
//| iCustom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0,164);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexEmptyValue(0, 0.0);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 164);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexEmptyValue(1, 0.0);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("Fine Fractals");
SetIndexLabel(0, "iFractalsUp");
SetIndexLabel(1, "iFractalsDn");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
//----
int limit;
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
//---- îñíîâíîé öèêë
for(int i = 2; i < limit; i++)
{
double
HP1=High[i+1],HP2=High[i],HP3=High[i-1],HPi=High[i-2],
LP1=Low[i+1],LP2=Low[i],LP3=Low[i-1], LPi=Low[i-2],
res=iFractals(NULL, 0, MODE_UPPER, i);
if(res==0 && Fine)//ïîâûøåííàÿ ÷óâñòâèòåëüíîñòü
{
if(HP1<HP2&&HP2>HP3 && (LP2>=LP3 || HP2>HPi)) res=HP2;
}
if(FlatShift && res!=0)// ñäâèãàåò ôðàêòàë ôëåòà
while(iHigh(NULL,0,i)==iHigh(NULL,0,i+1)) i++;
ExtMapBuffer1[i] = res;
if(res!=0 && i==2 && NewFAlert) Alert("Íîâûé âåðõíèé ôðàêòàë "+DoubleToStr(res,Digits));
res= iFractals(NULL, 0, MODE_LOWER, i);
if(res==0 && Fine)
{
if(LP1>LP2&&LP2<LP3&& (HP2<=HP3 || LP2<LPi)) res=LP2;
}
if(FlatShift && res!=0)
while(iLow(NULL,0,i)==iLow(NULL,0,i+1)) i++;
ExtMapBuffer2[i] =res;
if(res!=0 && i==2 && NewFAlert) Alert("Íîâûé íèæíèé ôðàêòàë "+DoubleToStr(res,Digits));
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments