Ind_VilkaFractals_v1.1

Download script
Author: lekhach � 2009
Ind_VilkaFractals_v1.1

This script is a specialized technical analysis tool designed for the MetaTrader platform to identify specific price action patterns known as "Fork" structures (based on the Vilka strategy). It automates the detection of market turning points by monitoring "fractals"—which are essentially high and low peaks in price movement.

Core Logic Overview

The script scans historical and real-time price data to locate significant highs and lows. Instead of just marking these points, it analyzes the relationship between consecutive peaks to identify a specific geometric arrangement. When three consecutive peaks appear in a descending or ascending sequence that meets the "Fork" criteria, the tool visually plots trend lines on your chart and provides active notifications.

Key Functional Components

  • Fractal Identification: The tool constantly monitors the market for upper and lower fractal points. These represent localized price extremes where the market briefly reversed direction.
  • Pattern Recognition:
    • Upper Patterns: It tracks a sequence of descending high points. If it detects three peaks where each subsequent peak is lower than the previous one, it recognizes an upward "Fork" structure.
    • Lower Patterns: Conversely, it tracks a sequence of ascending low points. If it identifies three lows where each subsequent low is higher than the last, it recognizes a downward "Fork" structure.
  • Dynamic Visual Mapping:
    • When a pattern is confirmed, the script automatically draws horizontal trend lines on the chart to highlight the price levels involved.
    • The tool manages these lines dynamically; it can display a specific number of recent lines (customizable by the user) and will automatically remove older lines as new ones appear to keep your chart clean.
  • Real-Time Alerts: The script includes an automated notification system. When a new "Fork" structure is formed in real-time, the tool triggers a pop-up alert on your screen, allowing you to react immediately to potential market shifts without constantly watching the screen.

User Customization

The logic allows for several visual and functional adjustments:

  • Visibility: You can toggle the fractal markers on or off.
  • Alerts: You can enable or disable the pop-up notifications.
  • Visual Styling: The script allows you to choose different colors for the upper and lower trend lines (defaulting to Blue for upward structures and Red for downward ones).
  • Density Control: You can set exactly how many historical lines remain visible on your chart at one time.
Indicators Used
Fractals
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
Ind_VilkaFractals_v1.1
//+------------------------------------------------------------------+
//|                                       Ind_VilkaFractals_v1.1.mq4 |
//|                      Copyright © 2009, Alexey Sleptsov (lekhach) |
//|                                             lekhach18@rambler.ru |
//+------------------------------------------------------------------+
// Èíäèêàòîð ðàáîòàåò ïî ñòðàòåãèè "Âèëêà ×óâàøîâà".
//--------------------------------------------------------------------
#property copyright "lekhach © 2009"
#property link      "lekhach18@rambler.ru"
//--------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//---- input parameters
extern int   Lines=20;           // Êîëè÷åñòâî âèäèìûõ/íåâèäèìûõ ôðàêòàëüíûõ ëèíèé
extern bool  AlertTrue=true;     // Âêë/âûêë ñèãíàëà
extern color LinesColorUp=Blue;  // Öâåò âåðõíèõ ôðàêòàëüíûõ ëèíèé
extern color LinesColorDown=Red; // Öâåò íèæíèõ ôðàêòàëüíûõ ëèíèé
extern bool  Fractals_on=true;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//--- my variables
int Up=0;
int BufUp=0;
int Down=0;
int BufDown=0;
double BufPriceUp[100000];
double BufDateUp[100000];
double BufPriceDown[100000];
double BufDateDown[100000];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Fractals");
   SetIndexLabel(0,"FractalsUp");
   SetIndexLabel(1,"FractalsDown");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

   ObjectsDeleteAll();
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit;
//---- Ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- Îñíîâíîé öèêë
   for(int i=limit; i>2; i--)
     {
     
     if (Fractals_on==true)
     {
      ExtMapBuffer1[i]=iFractals(NULL,0,MODE_UPPER,i);
      ExtMapBuffer2[i]=iFractals(NULL,0,MODE_LOWER,i);
      }
//---- Áëîê Up-ôðàêòàëîâ
      BufPriceUp[i]=iFractals(NULL,0,MODE_UPPER,i);
      BufDateUp[i]=Time[i];
      if (iFractals(NULL,0,MODE_UPPER,i)!=0)
        {
         Up++;
         BufPriceUp[Up]=iFractals(NULL,0,MODE_UPPER,i);
         BufDateUp[Up]=Time[i];
         if (Up>2 && Up-BufUp>1 && BufPriceUp[Up]<BufPriceUp[Up-1] && BufPriceUp[Up-1]<BufPriceUp[Up-2])
           {
            BufUp=Up;
            ObjectCreate("LineUp"+(Up-1),OBJ_TREND,0,BufDateUp[Up-1],BufPriceUp[Up-1],BufDateUp[Up],BufPriceUp[Up]);
            ObjectCreate("LineUp"+Up,OBJ_TREND,0,BufDateUp[Up-2],BufPriceUp[Up-2],BufDateUp[Up-1],BufPriceUp[Up-1]);
            if (ObjectGetValueByShift("LineUp"+Up,i-1)>ObjectGetValueByShift("LineUp"+(Up-1),i-1))
              {
               ObjectDelete("LineUp"+Up);
               ObjectDelete("LineUp"+(Up-1));
              }
              else if (AlertTrue==true) Alert("Íèçõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
           } 
         ObjectSet("LineUp"+(Up-1),OBJPROP_COLOR,LinesColorUp);
         ObjectSet("LineUp"+(Up-1),OBJPROP_WIDTH,2);
         ObjectSet("LineUp"+(Up-1),OBJPROP_RAY,True);
         ObjectSet("LineUp"+Up,OBJPROP_COLOR,LinesColorUp);
         ObjectSet("LineUp"+Up,OBJPROP_WIDTH,2);
         ObjectSet("LineUp"+Up,OBJPROP_RAY,True);         
         if (Up>Lines+1) ObjectDelete("LineUp"+(Up-Lines-1));
        }
//---- Áëîê Down-ôðàêòàëîâ
      BufPriceDown[i]=iFractals(NULL,0,MODE_LOWER,i);
      BufDateDown[i]=Time[i];
      if (iFractals(NULL,0,MODE_LOWER,i)!=0)
        {
         Down++;
         BufPriceDown[Down]=iFractals(NULL,0,MODE_LOWER,i);
         BufDateDown[Down]=Time[i];
         if (Down>2 && Down-BufDown>1 && BufPriceDown[Down]>BufPriceDown[Down-1] && BufPriceDown[Down-1]>BufPriceDown[Down-2])
           {
            BufDown=Down;
            ObjectCreate("LineDown"+(Down-1),OBJ_TREND,0,BufDateDown[Down-1],BufPriceDown[Down-1],BufDateDown[Down],BufPriceDown[Down]);
            ObjectCreate("LineDown"+Down,OBJ_TREND,0,BufDateDown[Down-2],BufPriceDown[Down-2],BufDateDown[Down-1],BufPriceDown[Down-1]);
            if (ObjectGetValueByShift("LineDown"+Down,i-1)<ObjectGetValueByShift("LineDown"+(Down-1),i-1))
              {
               ObjectDelete("LineDown"+Down);
               ObjectDelete("LineDown"+(Down-1));
              } 
              else if (AlertTrue==true) Alert("Âîñõîäÿùàÿ âèëêà! ",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));
           } 
         ObjectSet("LineDown"+(Down-1),OBJPROP_COLOR,LinesColorDown);
         ObjectSet("LineDown"+(Down-1),OBJPROP_WIDTH,2);
         ObjectSet("LineDown"+(Down-1),OBJPROP_RAY,True);
         ObjectSet("LineDown"+Down,OBJPROP_COLOR,LinesColorDown);
         ObjectSet("LineDown"+Down,OBJPROP_WIDTH,2);
         ObjectSet("LineDown"+Down,OBJPROP_RAY,True);
         if (Down>Lines+1) ObjectDelete("LineDown"+(Down-Lines-1));
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments