New_Fractals_Lines

Download script
Author: olyakish
New_Fractals_Lines

This script is designed to identify and visualize specific structural shifts in market price action by filtering traditional "fractal" patterns through volume and price intensity analysis. Instead of simply showing every fractal point, it evaluates the relationship between successive price movements to highlight significant trend changes.

Core Logic Overview

1. Fractal Detection and Filtering The script scans historical price data to identify upward and downward fractals. To ensure accuracy, it applies a strict filtering rule: if a single candle contains both an upward and a downward fractal simultaneously, the script ignores that occurrence entirely. This prevents "noisy" data from creating false signals during periods of extreme indecision.

2. Dynamic Intensity Calculation (MFI) Rather than relying solely on price direction, the tool calculates a custom "Market Force Index" (MFI) for both upward and downward movements. It does this by:

  • Summing the total range (High minus Low) over a 5-candle window.
  • Summing the total trading volume over that same 5-candle window.
  • Dividing the price range by the volume to determine the "strength" of the move relative to the liquidity involved.

3. Comparative Signal Validation The script creates visual markers (arrows) based on a comparison between consecutive opposite fractals. A signal is only triggered if specific conditions are met:

  • For Upward Signals: It looks for a transition from a downward fractal to an upward fractal. The signal is confirmed only if the upward movement shows lower relative price intensity compared to the previous downward move, while simultaneously exhibiting higher trading volume.
  • For Downward Signals: It looks for a transition from an upward fractal to a downward fractal. The signal is confirmed only if the downward move shows lower relative price intensity than the previous upward move, while exhibiting higher trading volume.

4. Automated Trend Lines Once the script identifies these validated signals, it automatically draws and updates trend lines on the chart:

  • Upward Trend Lines: These connect the most recent confirmed "Up" signals.
  • Downward Trend Lines: These connect the most recent confirmed "Down" signals.

As new price data arrives, the script dynamically moves the endpoints of these lines to the latest validated coordinates, providing a real-time visual representation of the prevailing market structure based on high-volume momentum shifts.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Fractals
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
New_Fractals_Lines
//+------------------------------------------------------------------+
//|                                           New_Fractals_Lines.mq4 |
//|                                      Copyright © -2007, olyakish |
//|                                           plutonia-dmb#yandex.ru |
//+------------------------------------------------------------------+
#property copyright "olyakish"
#property link "plutonia-dmb#yandex.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green // Ïðèñåäàþùèé
#property indicator_color2 Red   // Ïðèñåäàþùèé
//----
extern int			Pips		= 5;
double ExtGreenBuffer[];
double ExtRedBuffer[];
double AllHLDown, AllVolDown, AllHLUp, AllVolUp, AllMFIDown, AllMFIUp;
int OldFractal = 2;
bool Up = false, Down = false;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexShift(0, 0);
   SetIndexShift(1, 0);
//----
   SetIndexBuffer(0, ExtGreenBuffer);
   SetIndexBuffer(1, ExtRedBuffer);
//----
   SetIndexStyle(0, DRAW_ARROW, 0, 1);
   SetIndexStyle(1, DRAW_ARROW, 0, 1);
//----
   SetIndexArrow(0, 177);
   SetIndexArrow(1, 177);
//----
   ObjectCreate("Up", OBJ_TREND, 0, iTime(NULL, 0, 2), High[2], 
                iTime(NULL, 0, 1), High[1],0,0);
   ObjectSet("Up", OBJPROP_COLOR, Blue);
   ObjectSet("Up", OBJPROP_RAY, true);
//----   
   ObjectCreate("Down", OBJ_TREND, 0, iTime(NULL, 0, 2), Low[2], 
                iTime(NULL, 0, 1), Low[1],0,0);
   ObjectSet("Down", OBJPROP_COLOR, Brown);
   ObjectSet("Down", OBJPROP_RAY, true);             
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("Up");
   ObjectDelete("Down");
   return(0);
  }        
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {  
   ArrayInitialize(ExtGreenBuffer, NULL);
   ArrayInitialize(ExtRedBuffer, NULL);
   for(int i = 100; i >= 3; i--)
     {
       // íàñ èíòåðåñóåò òîëüêî ñèòóàöèÿ êîãäà íà áàðå îäèí ôðàêòàë 
       // (â ëþáóþ ñòîðîíó)
       // åñëè äâà ôðàêòàëà íà îäíîì áàðå òî îòñåèâàåì òàêèå ñèòóàöèè
       if(iFractals(NULL, 0, MODE_UPPER, i) != 0)
         {
           Up = true;
           Down = false;   
         }
       if(iFractals(NULL, 0, MODE_LOWER, i) != 0)
         {
           Up = false;
           Down = true;
         }
       // äâà ôðàêòàëà ñðàçó - èãíîðèðóåì
       if(iFractals(NULL, 0, MODE_UPPER, i) != 0 &&
          iFractals(NULL, 0, MODE_LOWER,i) != 0) 
         {
           Up = false;   
           Down = false;    
         }
       // íà òåêóùåì áàðå åñòü ôðàêòàë âíèç 
       if(Up == false && Down ==true)   
         {
           AllHLDown = 0;
           AllVolDown = 0;
           AllHLDown = High[i+2] - Low[i+2] + High[i+1] - Low[i+1] + 
                       High[i] - Low[i] + High[i-1] - Low[i-1] + 
                       High[i-2] - Low[i-2];
           AllVolDown = Volume[i+2] + Volume[i+1] + Volume[i] + 
                        Volume[i-1] + Volume[i-2];
           AllMFIDown = AllHLDown / AllVolDown;
           // ïðåäûäóùèé ôðàêòàë áûë ââåðõ - ñðàâíèâàåì äâà ôðàêòàëà 
           // (ââåðõ è òåêóùèé âíèç)
           if(OldFractal ==1 ) 
             {
               // èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
               if(AllMFIDown < AllMFIUp && AllVolDown > AllVolUp) 
                 {
                   // çàïîëíÿåì áóôåðû
                   ExtGreenBuffer[i] = NULL;
                   ExtRedBuffer[i] = Low[i]; // - Pips*Point;

                 }
             }
           OldFractal = 0;
         }
       // íà òåêóùåì áàðå åñòü ôðàêòàë ââåðõ 
       if(Up == true && Down == false)  
         {
           AllHLUp = 0;
           AllVolUp = 0;
           AllHLUp = High[i+2] - Low[i+2] + High[i+1] - Low[i+1] + 
                     High[i] - Low[i] + High[i-1] - Low[i-1] + 
                     High[i-2] - Low[i-2];
           AllVolUp = Volume[i+2] + Volume[i+1] + Volume[i] + 
                      Volume[i-1] + Volume[i-2];
           AllMFIUp = AllHLUp / AllVolUp;
           // ïðåäûäóùèé ôðàêòàë áûë âíèç - ñðàâíèâàåì äâà ôðàêòàëà 
           // (ââåðõ è òåêóùèé âíèç)
           if(OldFractal == 0) 
             {
               // èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
               if(AllMFIUp < AllMFIDown && AllVolUp > AllVolDown) 
                 {
                   // çàïîëíÿåì áóôåðû
                   ExtGreenBuffer[i] = High[i]; // + Pips*Point;
                   ExtRedBuffer[i] = NULL;

                 }
             }
           OldFractal=1;
         }    
     } 
   double _Price[2,2];
   int  _Time[2,2];
   ArrayInitialize(_Price, -1);
   ArrayInitialize(_Time, -1);
//----
   for(i = 3; i <= 100; i++)
     {
       //up
       if(ExtGreenBuffer[i] != NULL && _Price[0,0] != -1 && _Price[1,0] == -1)
         {
           _Price[1,0] = ExtGreenBuffer[i];
           _Time[1,0] = iTime(NULL, 0, i);         
         }
       if(ExtGreenBuffer[i] != NULL && _Price[0,0] == -1)
         {
           _Price[0,0] = ExtGreenBuffer[i];
           _Time[0,0] = iTime(NULL, 0, i);
         }
       // down 
       if(ExtRedBuffer[i] != NULL && _Price[0,1] != -1 && _Price[1,1] == -1)
         {
           _Price[1,1]=ExtRedBuffer[i];_Time[1,1]=iTime(NULL, 0, i);         
         } 
       if (ExtRedBuffer[i]!=NULL && _Price[0,1]==-1)
          {
          _Price[0,1]=ExtRedBuffer[i];_Time[0,1]=iTime(NULL, 0, i);
           }        
     }
   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]);
   return(0);
  }
//+------------------------------------------------------------------+



Comments