Superb Fractal 1.0
Download scriptThis custom technical indicator is designed to help traders identify significant market structural shifts and potential reversal points by monitoring price extremes. It operates by tracking "fractals"—which are essentially the highest highs or lowest lows over a specific window of time—and uses these levels to determine the prevailing market trend.
Core Logic and Functionality
1. Identification of Market Extremes (Fractals) The script continuously scans historical price data to locate local peaks and valleys. It looks for points where the price reaches a maximum or minimum compared to its immediate neighbors. These points act as "anchors" for the analysis, representing significant levels where the market has demonstrated strength or weakness.
2. Dynamic Trend Tracking Instead of just highlighting every peak, the indicator maintains an internal memory of the current market trend. It works on a "breakout" logic:
- Bearish Shift: If the price drops below a previously established low fractal, the script recognizes a shift in momentum toward a downward trend.
- Bullish Shift: If the price climbs above a previously established high fractal, the script recognizes a shift toward an upward trend.
The indicator only updates its trend status when these specific structural boundaries are breached, effectively filtering out minor market noise and focusing on significant movements.
3. Visual Signal Generation Once a trend change is confirmed by a breach of a fractal level, the script places visual markers (arrows) on the chart:
- Downside Signals: When a bearish shift occurs, it places an arrow below the price action to signal potential resistance or downward momentum.
- Upside Signals: When a bullish shift occurs, it places an arrow above the price action to signal potential support or upward momentum.
4. Precision Positioning To ensure that the visual signals do not clutter the actual price bars, the script uses a mathematical calculation (based on the Average True Range) to "offset" the arrows. This ensures that the markers appear at a clean distance from the candles, making them easier for the trader to see and interpret quickly during live market conditions.
Summary for Traders
This tool serves as a trend-following filter. Rather than alerting you to every small fluctuation, it waits for the market to "prove" its direction by breaking through established historical highs or lows. It then provides clear visual cues to help you stay aligned with the dominant market structure.
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_type1 DRAW_ARROW
#property indicator_type2 DRAW_ARROW
#property indicator_color1 clrDeepSkyBlue
#property indicator_color2 clrTomato
#property indicator_width1 2
#property indicator_width2 2
input int inp_size = 2; // size
double ext_arrow_up[];
double ext_arrow_dn[];
double ext_trend[];
double ext_fractal_up[];
double ext_fractal_dn[];
//+------------------------------------------------------------------+
int OnInit() {
IndicatorBuffers(5);
SetIndexBuffer(0,ext_arrow_up);
SetIndexBuffer(1,ext_arrow_dn);
SetIndexBuffer(2,ext_trend);
SetIndexBuffer(3,ext_fractal_up);
SetIndexBuffer(4,ext_fractal_dn);
SetIndexArrow(0,217);
SetIndexArrow(1,218);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]) {
int limit = prev_calculated > 0 ?
rates_total - prev_calculated - inp_size :
rates_total - inp_size - 1;
for(int i=limit; i>=inp_size; i--) {
// find new fractals
bool is_new_up = i == iHighest(NULL, PERIOD_CURRENT, MODE_HIGH, inp_size*2+1, i-inp_size);
bool is_new_dn = i == iLowest(NULL, PERIOD_CURRENT, MODE_LOW, inp_size*2+1, i-inp_size);
// update fractals data
ext_fractal_up[i] = ext_fractal_up[i+1];
if(is_new_up)
ext_fractal_up[i] = high[i];
ext_fractal_dn[i] = ext_fractal_dn[i+1];
if(is_new_dn)
ext_fractal_dn[i] = low[i];
// check trend
bool trend_changed = false;
ext_trend[i] = ext_trend[i+1];
if(ext_trend[i] != 1 && low[i] <= ext_fractal_dn[i+1]) {
ext_trend[i] = 1;
trend_changed = true;
}
if(ext_trend[i] != 0 && high[i] >= ext_fractal_up[i+1]) {
ext_trend[i] = 0;
trend_changed = true;
}
// draw fractal
if(ext_trend[i] == 0 && (trend_changed || ( is_new_dn && ext_fractal_dn[i] > ext_fractal_dn[i+1] )) )
ext_arrow_dn[i] = ext_fractal_dn[i] - iATR(NULL, PERIOD_CURRENT, 14, i) / 3.0;
if(ext_trend[i] == 1 && (trend_changed || ( is_new_up && ext_fractal_up[i] < ext_fractal_up[i+1] )) )
ext_arrow_up[i] = ext_fractal_up[i] + iATR(NULL, PERIOD_CURRENT, 14, i) / 3.0;
}
return(rates_total);
}
//+------------------------------------------------------------------+
Comments