Fractals_Adjustable_Lookback
Download scriptThis script is a visual trading tool designed to identify specific price action patterns on a currency chart. Its primary purpose is to highlight "Fractals," which are structural points in the market that indicate potential reversals or shifts in momentum.
Core Functionality
The tool automatically scans the historical price data to locate two specific types of price formations:
- Upper Fractals: These represent local peaks where the price reaches a high point before pulling back. The script identifies these and marks them with an upward-facing arrow.
- Lower Fractals: These represent local troughs where the price hits a low point before moving higher. The script identifies these and marks them with a downward-facing arrow.
How the Logic Works
- Pattern Recognition: The script looks back at a specific number of candles (defined by a "Lookback" setting) to confirm whether a peak or trough is significant enough to be considered a Fractal. By requiring a specific number of candles to settle before confirming the point, it helps filter out minor market "noise."
- Visual Plotting: Once a Fractal is confirmed, the script places an arrow on your chart. To ensure these markers do not overlap with the actual price candles, the tool includes an "Offset" feature, which nudges the arrows slightly above the highs and below the lows for better visibility.
- Stability Options: The logic includes a specific toggle regarding how it handles data persistence. Users can choose whether the indicators should remain static or follow specific rules regarding how they appear as new data populates the chart.
Practical Use for Traders
For a non-technical user, this tool acts as an automated "scout." Instead of manually searching for every tiny peak and valley in the price history, this script highlights them automatically. Traders typically use these markers to identify areas of potential support and resistance, helping them decide where to enter or exit a trade based on the market's structural turning points.
//+------------------------------------------------------------------+
//| BasketStrengthGroups.mq4 |
//| Copyright © 2007, sjcoinc |
//| sjcoinc2000@yahoo.com |
//+------------------------------------------------------------------+
//smjones ff 2008 http://www.forexfactory.com/showpost.php?p=2384212&postcount=9
//mod. +-leavetrail
#property copyright "Copyright © 2007, sjcoinc"
#property link "sjcoinc2000@yahoo.com"
#property indicator_chart_window
#property indicator_buffers 2
extern color FractalColorUp = Magenta;
extern color FractalColorDn = DeepSkyBlue;
extern int FractalLookback = 3; //non repainting =3; repainting (mt4std) =2;
extern double ArrowOffset = 10;
extern bool leavetrail = false;
double upper[], lower[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,upper);
SetIndexStyle(0,DRAW_ARROW,0,0, FractalColorUp);
SetIndexArrow(0,217);
SetIndexLabel(0,"Upper");
SetIndexBuffer(1,lower);
SetIndexStyle(1,DRAW_ARROW,0,0,FractalColorDn);
SetIndexArrow(1,218);
SetIndexLabel(1,"Lower");
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexEmptyValue(1,EMPTY_VALUE);
//----
return(0);
}
//+----------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
Comment(" ");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double up=0,down=0;
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
up = iFractals(Symbol(),0,MODE_UPPER,i+FractalLookback);
down = iFractals(Symbol(),0,MODE_LOWER,i+FractalLookback);
if ( up != 0 ) upper[i+FractalLookback] = up + ArrowOffset*Point;
else if (!leavetrail) upper[i+FractalLookback] = EMPTY_VALUE;
if ( down != 0 ) lower[i+FractalLookback] = down - ArrowOffset*Point;
else if (!leavetrail) lower[i+FractalLookback] = EMPTY_VALUE;
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments