i-Fractals-3172552-sig

Download script
Author: 3172552 & KimIV
i-Fractals-3172552-sig

This script is a specialized technical analysis tool designed for the MetaTrader 4 platform. Its primary purpose is to identify specific structural patterns in price action—specifically "fractals" and "double tops/bottoms"—to provide visual signals on a trading chart. Rather than relying on complex mathematical formulas like moving averages, this tool focuses on the physical geometry of the candles (the highs, lows, and bodies).

Core Logic and Detection Mechanisms

The script scans historical price data to identify three distinct types of bullish and bearish formations:

  • Unconfirmed Fractals: The tool looks for instances where a low or high point is significantly "deeper" or "higher" than the candles immediately surrounding it. It specifically checks if the price action has moved away from these points by a minimum distance, ensuring that the signal isn't triggered by minor market noise but by genuine structural turns.
  • Double Top/Bottom Fractals: The logic identifies instances where two consecutive price points reach nearly the same level. By comparing the difference between these peaks (or valleys) against a specific threshold, it recognizes "double" formations where the market hesitates at a specific price level before potentially reversing.
  • Long Bar Formations: The script includes logic to detect significant momentum shifts. It looks for large candle bodies that appear in sequence, suggesting a strong move into a structural area. It identifies these by measuring the distance between the open and close prices over several bars.

Visual Signals

Once the script identifies one of the patterns mentioned above, it places visual markers on your chart to alert you:

  1. Buy Signals: These appear as arrows below the price candles when the logic detects a "double bottom" or a bullish fractal structure, suggesting that price may be finding support and moving upward.
  2. Sell Signals: These appear as arrows above the price candles when a "double top" or a bearish fractal is detected, suggesting that price may be hitting resistance and moving downward.
  3. Exit Suggestions: The script also includes logic to provide exit markers based on the completion of these movements.

Dynamic Adjustments

To ensure the tool remains useful across different trading styles, it features an automated "Arrow Interval." The script detects which timeframe you are currently viewing (e.g., 1-minute charts vs. daily charts) and automatically adjusts the distance between the price candle and the signal arrow. This ensures that the markers remain clearly visible and do not overlap with the candles regardless of your zoom level or timeframe.

Summary for the User

In essence, this script acts as an automated "pattern spotter." It filters through the constant movement of the market to highlight specific geometric shapes where the price has historically shown signs of reversing or stalling. It translates these complex price-action rules into simple visual arrows, helping traders identify potential entry and exit points based on structural market behavior.

14 Views
0 Downloads
0 Favorites
i-Fractals-3172552-sig
//+------------------------------------------------------------------+
//|                                                        i-sig.mq4 |
//|                                                  3172552 & KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//| 23.10.2005  Èíäèêàòîð ñèãíàëîâ                                   |
//+------------------------------------------------------------------+
#property copyright "3172552 & KimIV"
#property link      "http://www.kimiv.ru"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 LightBlue
#property indicator_color2 Salmon
#property indicator_color3 LightBlue
#property indicator_color4 Salmon

//------- Âíåøíèå ïàðàìåòðû èíäèêàòîðà -------------------------------
extern int NumberOfBars = 2000;  // Êîëè÷åñòâî áàðîâ îáñ÷¸òà (0-âñå)
extern int bd  = 7;  //last bar body lenght 
extern int bdd = 40; //body lenght for double top/buttom bars 
extern int sd  = 11; //shadow difference for fractal bars 
extern int sdd = 6;  //shadow difference for double tops/buttoms bars 

//------- Ãëîáàëüíûå ïåðåìåííûå --------------------------------------
int ArrowInterval;

//------- Áóôåðû èíäèêàòîðà ------------------------------------------
double SigBuy[];
double SigSell[];
double SigExitBuy[];
double SigExitSell[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  SetIndexBuffer(0, SigBuy);
  SetIndexStyle (0, DRAW_ARROW);
  SetIndexArrow (0, 233);
  SetIndexEmptyValue(0, EMPTY_VALUE);

  SetIndexBuffer(1, SigSell);
  SetIndexStyle (1, DRAW_ARROW);
  SetIndexArrow (1, 234);
  SetIndexEmptyValue(1, EMPTY_VALUE);

  SetIndexBuffer(2, SigExitBuy);
  SetIndexStyle (2, DRAW_ARROW);
  SetIndexArrow (2, 251);
  SetIndexEmptyValue(2, EMPTY_VALUE);

  SetIndexBuffer(3, SigExitSell);
  SetIndexStyle (3, DRAW_ARROW);
  SetIndexArrow (3, 251);
  SetIndexEmptyValue(3, EMPTY_VALUE);

  ArrowInterval = GetArrowInterval();
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start() {
  double ms[4];
  int    loopbegin, shift;

 	if (NumberOfBars==0) loopbegin = Bars - 1;
  else loopbegin = NumberOfBars - 1;

  for (shift=loopbegin; shift>=0; shift--) {
    ms[0] = EMPTY_VALUE;
    ms[1] = EMPTY_VALUE;
    ms[2] = EMPTY_VALUE;
    ms[3] = EMPTY_VALUE;
    GetSignals(shift, ms);
    SigBuy[shift] = ms[0];
    SigSell[shift] = ms[1];
    SigExitBuy[shift+1] = ms[2];
    SigExitSell[shift+1] = ms[3];
  }
}

//+------------------------------------------------------------------+
//| Âîçâðàùàåò ñèãíàëû                                               |
//+------------------------------------------------------------------+
void GetSignals(int nb, double& ms[]) {
  bool bc1=False, bc2=False, bc3=False;
  bool sc1=False, sc2=False, sc3=False;

  //just unconfirmed fractal with last bar White
  bc1=( (Low[nb+3]-Low[nb+2])>(sd*Point)
     && (Low[nb+4]-Low[nb+2])>(sd*Point)
     && (Low[nb+1]-Low[nb+2])>(sd*Point)
     && (Close[nb+1]-Open[nb+1])>(bd*Point)
  );
  //just unconfirmed frsctal with last bar Black
  sc1=( (High[nb+2]-High[nb+3])>(sd*Point)
     && (High[nb+2]-High[nb+4])>(sd*Point)
     && (High[nb+2]-High[nb+1])>(sd*Point)
     && (Open[nb+1]-Close[nb+1])>(bd*Point)
  );
  //double buttom fractal
  bc2=( (Low[nb+4]-Low[nb+2])>(sd*Point)
     && (Low[nb+5]-Low[nb+2])>(sd*Point)
     && (Low[nb+1]-Low[nb+2])>(sd*Point)
     && (Close[nb+1]-Open[nb+1])>(bd*Point)
     && (MathAbs(Low[nb+3]-Low[nb+2]))<(sdd*Point)
  );
  //double top fractal
  sc2=( (High[nb+2]-High[nb+4])>(sd*Point)
     && (High[nb+2]-High[nb+5])>(sd*Point)
     && (High[nb+2]-High[nb+1])>(sd*Point)
     && (Open[nb+1]-Close[nb+1])>(bd*Point)
     && (MathAbs(High[nb+3]-High[nb+2]))<(sdd*Point)
  );
  //long bars double buttom fractal
  bc3=( (Low[nb+3]-Low[nb+2])>(sd*Point)
     && (Low[nb+4]-Low[nb+2])>(sd*Point)
     && (MathAbs(Low[nb+1]-Low[nb+2]))<(sdd*Point)
     && (Close[nb+1]-Open[nb+1])>(bdd*Point)
     && (Open[nb+2]-Close[nb+2])>(bdd*Point)
  );
  //long bars double top fractal
  sc3=( (High[nb+2]-High[nb+3])>(sd*Point)
     && (High[nb+2]-High[nb+4])>(sd*Point)
     && (MathAbs(High[nb+2]-High[nb+1]))<(sdd*Point)
     && (Open[nb+1]-Close[nb+1])>(bdd*Point)
     && (Close[nb+2]-Open[nb+2])>(bdd*Point)
  );

  if (bc1 || bc2 || bc3) ms[0]=Low[nb]-ArrowInterval*Point;
  if (sc1 || sc2 || sc3) ms[1]=High[nb]+ArrowInterval*Point;
}

//+------------------------------------------------------------------+
//| Âîçâðàùàåò èíòåðâàë óñòàíîâêè ñèãíàëüíûõ óêàçàòåëåé              |
//+------------------------------------------------------------------+
int GetArrowInterval() {
  int p = Period();

  switch (p) {
    case 1:     return(5);
    case 5:     return(7);
    case 15:    return(10);
    case 30:    return(15);
    case 60:    return(20);
    case 240:   return(30);
    case 1440:  return(80);
    case 10080: return(150);
    case 43200: return(250);
  }
}
//+------------------------------------------------------------------+

Comments