olyakish_fractals_06_v1

Download script
Author: by olyakish

This script is a specialized technical analysis tool designed for the MetaTrader platform. Its primary purpose is to identify, filter, and visualize specific types of "fractals"—which are peaks and valleys in price action—based on their relationship with trading volume and price movement.

Core Logic Overview

The script works by scanning historical price data to find significant turning points. Instead of simply marking every peak or valley, it categorizes these points into four distinct types based on two main criteria: Volume Intensity and Movement Fluidity (MFI).

How the Analysis Works

  1. Fractal Identification: The script looks back over a user-defined number of bars to find high points (peaks) and low points (valleys).
  2. Comparative Analysis: When it finds a current fractal point, it searches backward through history to find the previous one. It then compares two metrics between these two points:
    • Volume: The total amount of trading activity during that period.
    • Movement Fluidity (MFI): A calculation that measures the range of price movement relative to the volume traded.
  3. Categorization Logic: Based on whether the current point has higher/lower volume and higher/lower fluidity compared to the previous point, it assigns the fractal one of four categories:
    • Green Fractal: High Volume + High Fluidity (Strong momentum).
    • Red Fractal: High Volume + Low Fluidity (High effort, low result / "Struggling").
    • Blue Fractal: Low Volume + High Fluidity (Easy movement).
    • Saddle Brown Fractal: Low Volume + Low Fluidity (Weak/Dying movement).

Visual Features and Customization

To make this data actionable for a trader, the script includes several visual and behavioral features:

  • Dynamic Filtering: Users can set a percentage threshold to determine how much "stronger" or "weaker" the volume of one fractal must be compared to another to trigger a specific category.
  • Trend Lines: The script can automatically draw trend lines based on these filtered fractals. You can choose which specific category (e.g., only "Green" or only "Red") should be used to generate these lines.
  • Visual History: There is an option to display "previous" lines as dashed marks. This allows traders to see where the previous trend originated while focusing on the current active price level.
  • Automated Updates: The script constantly updates the positions of the trend lines as new price data arrives, ensuring that the visual indicators move in real-time with the market.

Summary for the User

In simple terms, this tool helps you ignore "noisy" price movements. By analyzing the effort (volume) vs. the result (price movement), it filters out insignificant price fluctuations and highlights specific types of market behavior, allowing you to draw trend lines based only on the most meaningful structural shifts in the market.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Fractals
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
14 Views
1 Downloads
0 Favorites
olyakish_fractals_06_v1
//+------------------------------------------------------------------+
//|                                                        v04       |
//|                                                                  |
//| v02                                                              |
//| Äîáàâëåí ïðîöåíò äëÿ îòñåèâàíèÿ ôðàêòàëîâ                        |
//| v03                                                              |
//| Ðèñóåò ëèíèè                                                     |
//| v04                                                              |
//| Ôèëüòð äëÿ ëèíèé ïî àëëèãàòîðó                                   |
//| v05                                                              |
//| âûáîð âàðèàíòà ïîñòðîåíèÿ ëèíèé                                  |
//| v06                                                              |
//| âûáîð êîëè÷åñòâà áàðîâ â ôðàêòàëå                               |
//+------------------------------------------------------------------+

#property copyright "by olyakish"
#property link      ""
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime //Çåëåíûé ôðàêòàë
#property indicator_color2 Red // Ïðèñåäàþùèé
#property indicator_color3 SaddleBrown //Óâÿäàþùèé
#property indicator_color4 Blue // Ôàëüøèâûé
//----
extern int			Pips		= 15;
extern int			ShiftBars	= 1000;
extern string rem0="Êîëè÷åñòâî áàðîâ â ôðàêòàëå";
extern int			BarsInFractal	= 11;
extern string rem1="Ïðîöåíò äëÿ îòñåèâàíèÿ ïî îáúåìó";
extern int Percent=110;
extern string rem2="Ðèñîâàòü ïðåäûäóùèå ëèíèè?";
extern bool UseOldLine=true;
extern string rem3="Ïî êàêèì ôðàêòàëàì ðèñóåì ëèíèè";
extern string rem4="0-çåëåíûå,1-ïðèñåäàþùèå";
extern string rem5="2-óâÿäàþùèå,3-ôàëüøèâûå";
extern int FractalLines=1;

double ExtLimeBuffer[];
double ExtRedBuffer[];
double ExtSaddleBrownBuffer[];
double ExtBlueBuffer[];
int i,j,z;
double a_Fractal[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
double a_MFI[2];     // 0- ïîñëåäíèé 1-ïðåäûäóùèé
double a_Volume[2];  // 0- ïîñëåäíèé 1-ïðåäûäóùèé
bool objects_initialized=false;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   int test;
   test=BarsInFractal/2;
   if (test*2==BarsInFractal){Alert("Çíà÷åíèå BarsInFractal äîëæíî áûòü íå÷åòíûì");deinit();}
   if (BarsInFractal<3){Alert("Çíà÷åíèå BarsInFractal äîëæíî áûòü >=3");deinit();}
   SetIndexShift(0,0);
   SetIndexShift(1,0);
   SetIndexShift(2,0);
   SetIndexShift(3,0);
//----
   SetIndexBuffer(0, ExtLimeBuffer);
   SetIndexBuffer(1, ExtRedBuffer);
   SetIndexBuffer(2, ExtSaddleBrownBuffer);
   SetIndexBuffer(3, ExtBlueBuffer);
//----
   SetIndexStyle(0, DRAW_ARROW );
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexStyle(3, DRAW_ARROW);
   
   SetIndexArrow(0,177);
   SetIndexArrow(1,177);
   SetIndexArrow(2,177);
   SetIndexArrow(3,177);               
   
///----
   SetIndexLabel(0, "Çåëåíûé ôðàêòàë");
   SetIndexLabel(1, "Ïðèñåäàþùèé ôðàêòàë");
   SetIndexLabel(2, "Óâÿäàþùèé ôðàêòàë");
   SetIndexLabel(3, "Ôàëüøèâûé ôðàêòàë");  
   //----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ObjectsInit()
  {
//---- check if we have enough bars
   if(ArraySize(High)<3)
     {
      Print("Timeseries is not ready yet - exit");
      return(false);
     }
//----

     ObjectCreate("Up",OBJ_TREND,0,iTime(NULL, 0, 2),High[2],iTime(NULL, 0, 1),High[1],0,0);
     ObjectSet("Up",OBJPROP_COLOR,Aqua);
     ObjectSet("Up",OBJPROP_RAY,true);
     ObjectSet("Up",OBJPROP_BACK,1);
     
     ObjectCreate("Down",OBJ_TREND,0,iTime(NULL, 0, 2),Low[2],iTime(NULL, 0, 1),Low[1],0,0);
     ObjectSet("Down",OBJPROP_COLOR,Tomato);
     ObjectSet("Down",OBJPROP_RAY,true);
     ObjectSet("Down",OBJPROP_BACK,1);
     if (UseOldLine)
      {
         ObjectCreate("Up_Prev",OBJ_TREND,0,iTime(NULL, 0, 2),High[2],iTime(NULL, 0, 1),High[1],0,0);
         ObjectSet("Up_Prev",OBJPROP_COLOR,Aqua);
         ObjectSet("Up_Prev",OBJPROP_RAY,true);
         ObjectSet("Up_Prev",OBJPROP_STYLE,STYLE_DASH);
         ObjectSet("Up_Prev",OBJPROP_BACK,1);
     
         ObjectCreate("Down_Prev",OBJ_TREND,0,iTime(NULL, 0, 2),Low[2],iTime(NULL, 0, 1),Low[1],0,0);
         ObjectSet("Down_Prev",OBJPROP_COLOR,Tomato);
         ObjectSet("Down_Prev",OBJPROP_RAY,true);         
         ObjectSet("Down_Prev",OBJPROP_STYLE,STYLE_DASH);
         ObjectSet("Down_Prev",OBJPROP_BACK,1);
      }
//----
   return(true);
  }   
int deinit()
   {
      ObjectDelete("Up");
      ObjectDelete("Down");
      if (UseOldLine)
         {
            ObjectDelete("Up_Prev");
            ObjectDelete("Down_Prev");
         }
   return(0);
  }   
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {  
   if(!objects_initialized)
     {
      objects_initialized=ObjectsInit();
     }    
   int n=BarsInFractal;
   while (ExtLimeBuffer[n]!=NULL || ExtRedBuffer[n]!=NULL || ExtSaddleBrownBuffer[n]!=NULL || ExtBlueBuffer[n]!=NULL)
      {
         if (n>ShiftBars) {n=ShiftBars;break;}
         n++;
      }
   for(int i=n+20; i>=(BarsInFractal/2+1); i--)
     {
         //-- âåðõíèå ôðàêòàëû
         ArrayInitialize(a_Fractal,0);
         ArrayInitialize(a_MFI,0);
         ArrayInitialize(a_Volume,0);         
         if (High[i]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,i-BarsInFractal/2)]) // íà i áàðå åñòü ôðàêòàë ââåðõ
            {               
               a_Fractal[0]=High[i];   // öåíà íà ôðàêòàëå               
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_Volume[0]+=Volume[z];} // îáúåì
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_MFI[0]+=High[z]-Low[z];}
               a_MFI[0]=a_MFI[0]/a_Volume[0];               
               // ïîøëè èñêàòü ôðàêòàë íà âíèç ïî èñòîðèè
               j=i+1;
               while (a_Fractal[1]==0 && j<Bars)
                  {
                     if (High[j]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,j-BarsInFractal/2)]) {break;} // íàøëè íî íå òîò (òîæå ââåðõ)
                     if (Low[j]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,j-BarsInFractal/2)]) //-- Íàøëè ôðàêòàë  âíèç
                        {
                           a_Fractal[1]=Low[j];
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_Volume[1]+=Volume[z];} // îáúåì
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_MFI[1]+=High[z]-Low[z];}
                           a_MFI[1]=a_MFI[1]/a_Volume[1];                              

                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]<a_MFI[1]){ExtRedBuffer[i]=High[i]+Pips*Point;break;}       // èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]>a_MFI[1]){ExtLimeBuffer[i]=High[i]+Pips*Point;break;}      // èìååì çåëåíûé ôðàêòàë (MFI + îáúåì +)
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]>a_MFI[1]){ExtBlueBuffer[i]=High[i]+Pips*Point;break;}      // èìååì ôàëüøèâûé ôðàêòàë (MFI + îáúåì -)
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]<a_MFI[1]){ExtSaddleBrownBuffer[i]=High[i]+Pips*Point;break;}    // èìååì óâÿäàþùèé ôðàêòàë (MFI - îáúåì -)
                        }                          
                        j++;                                         
                  }
            }
         //--- íèæíèå ôðàêòàëû
         ArrayInitialize(a_Fractal,0);
         ArrayInitialize(a_MFI,0);
         ArrayInitialize(a_Volume,0);
         if (Low[i]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,i-BarsInFractal/2)]) // íà i áàðå åñòü ôðàêòàë âíèç
            {
               a_Fractal[0]=Low[i];   // öåíà íà ôðàêòàëå               
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_Volume[0]+=Volume[z];} // îáúåì
               for (z=i-BarsInFractal/2;z<=i-BarsInFractal/2+BarsInFractal;z++){a_MFI[0]+=High[z]-Low[z];}
               a_MFI[0]=a_MFI[0]/a_Volume[0];   
               // ïîøëè èñêàòü ôðàêòàë íà ââåðõ ïî èñòîðèè
               j=i+1;
               while (a_Fractal[1]==0 && j<Bars)
                  {
                     if (Low[j]==Low[iLowest(Symbol(),0,MODE_LOW,BarsInFractal,j-BarsInFractal/2)]) {break;}
                     if (High[j]==High[iHighest(Symbol(),0,MODE_HIGH,BarsInFractal,j-BarsInFractal/2)]) //-- Íàøëè ôðàêòàë  ââåðõ
                        {
                           a_Fractal[1]=High[j];
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_Volume[1]+=Volume[z];} // îáúåì
                           for (z=j-BarsInFractal/2;z<=j-BarsInFractal/2+BarsInFractal;z++){a_MFI[1]+=High[z]-Low[z];}
                           a_MFI[1]=a_MFI[1]/a_Volume[1];                              
                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]<a_MFI[1]){ExtRedBuffer[i]=Low[i]-Pips*Point;break;}           // èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
                           if (a_Volume[0]>a_Volume[1]*Percent/100 && a_MFI[0]>a_MFI[1]){ExtLimeBuffer[i]=Low[i]-Pips*Point;break;}          // èìååì çåëåíûé ôðàêòàë (MFI + îáúåì +)
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]>a_MFI[1]){ExtBlueBuffer[i]=Low[i]-Pips*Point;break;}          // èìååì ôàëüøèâûé ôðàêòàë (MFI + îáúåì -)
                           if (a_Volume[0]*Percent/100<a_Volume[1] && a_MFI[0]<a_MFI[1]){ExtSaddleBrownBuffer[i]=Low[i]-Pips*Point;break;}   // èìååì óâÿäàþùèé ôðàêòàë (MFI - îáúåì -)
                        }
                        j++;                                         
                  }
            }
      }
   
   /// îòðèñîâêà ëèíèé
    double _Price[3,2];
    int  _Time[3,2];
    ArrayInitialize(_Price,-1);
    ArrayInitialize(_Time,-1);
    int up=0,down=0;
    for(i=3; i<=ShiftBars; i++)
      {
      //up
      //   double  iLips=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, i);
      //   double  iTeeth=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, i);
      //   double  iJaw=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, i);                                                    
      // ïî çåëåíûì
         if (FractalLines==0)
            {
               if (ExtLimeBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtLimeBuffer[i]) 
                 // && iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
                  {
                     _Price[up,0]=ExtLimeBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtLimeBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtLimeBuffer[i])
                  //&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
                  {
                     _Price[down,1]=ExtLimeBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }
        // ïî ïðèñåäàþùèì                                                      
         if (FractalLines==1)
            {
               if (ExtRedBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtRedBuffer[i]) 
                  //&& iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
                  {
                     _Price[up,0]=ExtRedBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtRedBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtRedBuffer[i])
                  //&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
                  {
                     _Price[down,1]=ExtRedBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }
         // ïî ôàëüøèâûì   
         if (FractalLines==2)
            {
               if (ExtSaddleBrownBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtSaddleBrownBuffer[i]) 
                  //&& iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
                  {
                     _Price[up,0]=ExtSaddleBrownBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtSaddleBrownBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtSaddleBrownBuffer[i])
                  //&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
                  {
                     _Price[down,1]=ExtSaddleBrownBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }
         // ïî óâÿäàþùèì 
         if (FractalLines==3)
            {
               if (ExtBlueBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_UPPER,i)!=NULL && up<=2 && iFractals(NULL,0,MODE_UPPER,i)<=ExtBlueBuffer[i]) 
                  //&& iFractals(NULL,0,MODE_UPPER,i)>iLips && iFractals(NULL,0,MODE_UPPER,i)>iTeeth && iFractals(NULL,0,MODE_UPPER,i)>iJaw)
                  {
                     _Price[up,0]=ExtBlueBuffer[i];_Time[up,0]=iTime(NULL, 0, i);up++;
                  }
               if (ExtBlueBuffer[i]!=2147483647 && iFractals(NULL,0,MODE_LOWER,i)!=NULL && down<=2 && iFractals(NULL,0,MODE_LOWER,i)>=ExtBlueBuffer[i])
                  //&& iFractals(NULL,0,MODE_LOWER,i)<iLips && iFractals(NULL,0,MODE_LOWER,i)<iTeeth && iFractals(NULL,0,MODE_LOWER,i)<iJaw)
                  {
                     _Price[down,1]=ExtBlueBuffer[i];_Time[down,1]=iTime(NULL, 0, i);down++;         
                  } 
            }                                   
      }   
   ObjectMove("Up",1,_Time[0,0],_Price[0,0]);
   ObjectMove("Up",0,_Time[1,0],_Price[1,0]);
    
   ObjectMove("Down",1,_Time[0,1],_Price[0,1]);
   ObjectMove("Down",0,_Time[1,1],_Price[1,1]);
   if (UseOldLine)
      {
         ObjectMove("Up_Prev",1,_Time[1,0],_Price[1,0]);
         ObjectMove("Up_Prev",0,_Time[2,0],_Price[2,0]);
    
         ObjectMove("Down_Prev",1,_Time[1,1],_Price[1,1]);
         ObjectMove("Down_Prev",0,_Time[2,1],_Price[2,1]);         
      }
   return(0);
  }
//+------------------------------------------------------------------+



Comments