olyakish_fractals_06a

Download script
Author: by olyakish
olyakish_fractals_06a

This script is a specialized technical analysis tool designed for the MetaTrader platform. Its primary purpose is to identify and categorize specific price patterns—known as "fractals"—by analyzing three distinct market factors: price peaks/valleys, trading volume, and volatility (price movement range).

Core Logic Overview

The script scans historical price data to find "Fractal" points (local highs or lows). Unlike standard fractal indicators that simply mark these points, this tool evaluates the relationship between a current fractal point and the one preceding it. It classifies these points into four distinct categories based on how volume and volatility change from one point to the next.

Data Analysis Criteria

To determine which category a price point belongs to, the script performs the following calculations:

  • Volume Comparison: It measures the total trading volume over a user-defined number of bars surrounding the fractal point.
  • Volatility (MFI) Calculation: It calculates a custom "Mean Force Index" style value by taking the range of price movement (High minus Low) and dividing it by the volume. This helps determine if the price move was "heavy" or "light" relative to the amount of trading activity.
  • Categorization Logic:
    • Green Fractals: High volume accompanied by increasing volatility.
    • Red Fractals: High volume accompanied by decreasing volatility.
    • Fading Fractals: Lower volume accompanied by increasing volatility.
    • Fading (Blue) Fractals: Lower volume accompanied by decreasing volatility.

Visual Elements and Customization

The script provides several interactive layers for the user:

  • Dynamic Line Drawing: Based on your settings, the tool can draw trend lines connecting these specific fractal types. You can choose which of the four categories (Green, Red, Fading, or Blue) to use for these lines.
  • Historical Tracking: It includes an option to display "Old Lines," which allows you to see previous price levels in a dashed format while the current active levels remain solid.
  • Visual Markers: The tool places specific arrow markers on the chart to represent each of the four fractal types, making it easy to identify different market behaviors at a glance.

User Controls

The script is highly customizable through several input parameters:

  • Sensitivity: You can define how many bars are used to calculate a fractal and set a percentage threshold for volume comparison.
  • Visual Filters: Users can choose to show or hide previous lines and select specific colors/types of fractals to be utilized for trendline construction.
  • Offsetting: It includes a "Pips" setting to shift the visual markers slightly away from the actual price candles for better clarity on the chart.
Price Data Components
Series array that contains open time of each bar
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
11 Views
0 Downloads
0 Favorites
olyakish_fractals_06a
//+------------------------------------------------------------------+
//|                                                        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-ïðåäûäóùèé




//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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, "Ôàëüøèâûé ôðàêòàë");  
//----

     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(0);
  }
  
int deinit()
   {
      ObjectDelete("Up");
      ObjectDelete("Down");
      if (UseOldLine)
         {
            ObjectDelete("Up_Prev");
            ObjectDelete("Down_Prev");
         }
   return(0);
  }   
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {  
   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=BarsInFractal/2; 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 && High[i]<=ExtLimeBuffer[i] && up<=2) 
                 // && 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 &&  down<=2 && Low[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 &&  up<=2 && High[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 &&  down<=2 && Low[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  && up<=2 && High[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  && down<=2 && Low[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 && up<=2 && High[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 && down<=2 && Low[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