wlxFractals_v5

Download script
Author: Copyright � 2004, by wellx
wlxFractals_v5

This script is designed to function as a technical analysis tool that identifies specific price patterns known as "fractals" on a trading chart. In simple terms, it scans historical price data to find significant peaks and valleys, marking them with visual symbols (arrows) to help traders identify potential trend reversals or support and resistance levels.

Core Logic Overview

The script operates by examining the relationship between a specific price point (the "center" point) and the candles surrounding it on both the left and right sides. It looks for two distinct types of price movements:

1. Upward Fractals (Peaks) To identify an upward fractal, the script looks for a high point that stands out above its neighbors. Specifically:

  • It checks if the current candle's high is higher than a set number of candles to its right.
  • It simultaneously verifies that the high is also greater than or equal to a specific number of candles to its left (accounting for any identical price levels).
  • If these conditions are met, it confirms that this point is a local "peak," and the script places an upward-pointing arrow at that exact price level.

2. Downward Fractals (Valleys) Similarly, to identify a downward fractal, the script looks for a low point that stands out below its neighbors:

  • It checks if the current candle's low is lower than a set number of candles to its right.
  • It then verifies that the low is also lower than or equal to a specific number of candles to its left.
  • If confirmed, it places a downward-pointing arrow at that price level to signify a local "valley."

Customizable Parameters

The logic is flexible because it relies on user-defined "neighborhood" settings. These parameters allow you to control how "prominent" a peak or valley must be before the script recognizes it:

  • Left and Right Settings: You can define exactly how many candles to the left and right the script should inspect. Increasing these numbers will result in finding larger, more significant price swings; decreasing them will find smaller, more frequent fluctuations.
  • Equality Handling: The script includes logic to handle "flat" tops or bottoms (where multiple candles have the exact same high or low price), ensuring that these are still correctly identified as part of a fractal rather than being ignored.

Summary for the User

Instead of just showing every move in the market, this tool filters out the "noise." It only highlights moments where the price has made a definitive turn—either reaching a local ceiling (Upward Fractal) or a local floor (Downward Fractal). This allows you to see the structural skeleton of the market's movement more clearly.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
wlxFractals_v5
//+------------------------------------------------------------------+
//|                                                  wlxFractals.mq4 |
//|         Copyright © 2004, by konKop, GOODMAN, Mstera, af + wellx |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, by wellx"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int Equals = 5;
extern int nLeftUp = 2;
extern int nRightUp = 2;
extern int nLeftDown = 2;
extern int nRightDown = 2;
//---- buffers
double FractalsUp[];
double FractalsDown[];
//----
int pos = 0, cntup = 0, cntdown = 0, cnt = 0;
int r = 0, l = 0, e = 0;
int fup = 0, fdown = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0, FractalsUp);
   SetIndexBuffer(1, FractalsDown);   
//----
   SetIndexStyle(0, DRAW_ARROW, 0, 1);
   SetIndexArrow(0, 217);
//----
   SetIndexStyle(1, DRAW_ARROW, 0, 1);
   SetIndexArrow(1, 218);
//----
   cntup = nLeftUp + nRightUp + Equals + 1;
   cntdown = nLeftDown + Equals + 1;
   if(cntup >= cntdown) 
       cnt = cntup;
   if(cntup < cntdown)  
       cnt = cntdown; 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i=0, j=0;
   int cbars = IndicatorCounted();
//----
   if(cbars < 0) 
       return(-1);
//----
   if(cbars > 0) 
       cbars--;
   pos = 0;
//----
   if(cbars > (Bars - cnt - 1)) 
       pos =(Bars - cnt - 1);
   else 
       pos = Bars - (cbars + nRightUp);
//----
   while(pos >= nRightUp)
     {
       FractalsUp[pos] = NULL;
       FractalsDown[pos] = NULL;     
       //ôÐÀÊÒÀË ÂÂÅÐÕ
       r = nRightUp; //ïðîâåðÿåì ïðàâóþ ñòîðîíó ôðàêòàëà
       //----
       for(i = 1; i <= r; i++)
         {
           if(High[pos] <= High[pos-i]) 
               break;
         }
       //åñëè ñïðàâà âñå ÎÊ òî i äîëæíî áûòü ðàâíî r+1
       if(i == r + 1) //FractalsUp[pos]=High[pos];
         {
           l = nLeftUp;  //ïðîâåðÿåì ëåâóþ ñòîðîíó ôðàêòàëà
           e = Equals;
           //----
           for(j = 1; j <= l + Equals; j++)
             {     
               if(High[pos] < High[pos+j]) 
                   break;
               //----
               if(High[pos] > High[pos+j]) 
                   l--;
               //----
               if(High[pos] == High[pos+j])
                   e--;
               //----
               if(l == 0) 
                 {
                   FractalsUp[pos] = High[pos];
                   break;
                 }
               //----
               if(e < 0) 
                   break;
             }
         }
       //ÔÐÀÊÒÀË ÂÍÈÇ
       r = nRightDown; //ïðîâåðÿåì ïðàâóþ ñòîðîíó ôðàêòàëà
       //----
       for(i = 1; i <= r; i++)
         {
           if(Low[pos] >= Low[pos-i]) 
               break;
         }     
       //----
       if(i == r + 1) //FractalsUp[pos]=High[pos];
         {
           l = nLeftDown;  //ïðîâåðÿåì ëåâóþ ñòîðîíó ôðàêòàëà
           e = Equals;
           //----
           for(j = 1; j <= l + Equals; j++)
             {      
               if(Low[pos] > Low[pos+j]) 
                   break;
               //----
               if(Low[pos] < Low[pos+j]) 
                   l--;
               //----
               if(Low[pos] == Low[pos+j])
                   e--;
               //----
               if(l == 0) 
                 {
                   FractalsDown[pos] = Low[pos];
                   break;
                 }
               if(e < 0) 
                   break;
             }
         }
       pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments