SergeyGukach

Download script
Author: � Maloma
SergeyGukach

The Signal Bars indicator is designed to identify key price turning points by detecting specific structural patterns in the market, commonly known as "Fractals." Instead of relying on simple moving averages or high-volume spikes, this tool looks for peaks and valleys where the price reverses its direction over a defined sequence of candles.

Core Logic and Mechanism

The script scans historical price data to identify significant high and low points. It evaluates a cluster of surrounding candles to determine if a specific candle represents a "Fractal"—a point where the price reached a local maximum or minimum relative to its immediate neighbors.

To ensure accuracy, the logic does not just look for a single high or low; it validates these points across several different structural configurations:

  • Standard Patterns: It identifies simple 5-bar structures where one candle is clearly higher or lower than the four candles surrounding it.
  • Complex Variations: The script also accounts for more sophisticated formations involving 6, 7, 8, and 9-bar sequences. These variations allow the indicator to recognize "flat" tops or bottoms (where multiple candles share the same high/low price) as well as stepped movements.

How it Identifies Signals

When the logic confirms a valid Fractal (a peak or a valley), it performs three specific actions:

  1. Signal Generation: It identifies a specific signal point based on the opening price of the candle following the fractal. This serves as a visual cue for potential trend shifts.
  2. Fractal Marking: It pinpoints the exact high or low of the peak/valley to help define the boundaries of the current price movement.
  3. Range Mapping (Diapazon): It captures the "range" between the current opening price and the identified fractal point, providing a clearer picture of the price distance traveled during that specific structural shift.

Summary for the User

Essentially, this script acts as a sophisticated "trend hunter." By scanning for these multi-bar patterns, it filters out minor market noise and highlights significant structural reversals. It provides you with visual markers that indicate where the market has historically turned, helping you identify areas of potential support or resistance based on confirmed price geometry.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
SergeyGukach
//+------------------------------------------------------------------+
//|                                                  Signal Bars.mq4 |
//+------------------------------------------------------------------+
#property copyright "© Maloma"
//----
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 OrangeRed
#property indicator_color4 CornflowerBlue
#property indicator_color5 Magenta
#property indicator_color6 Teal
//---- input parameters
//---- buffers
double dUpFractalsBuffer[];
double dDownFractalsBuffer[];
double dUpSignalBuffer[];
double dDownSignalBuffer[];
double UpDiapazonBuffer[];
double DnDiapazonBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
   SetIndexBuffer(0,dUpFractalsBuffer);
   SetIndexBuffer(1,dDownFractalsBuffer);
   SetIndexBuffer(2,dUpSignalBuffer);
   SetIndexBuffer(3,dDownSignalBuffer);
   SetIndexBuffer(4,UpDiapazonBuffer);
   SetIndexBuffer(5,DnDiapazonBuffer);
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE,EMPTY,2);
   SetIndexArrow(0,119);
   SetIndexStyle(1,DRAW_NONE,EMPTY,2);
   SetIndexArrow(1,119);
   SetIndexStyle(2,DRAW_ARROW,EMPTY,3);
   SetIndexArrow(2,119);
   SetIndexStyle(3,DRAW_ARROW,EMPTY,3);
   SetIndexArrow(3,119);
   SetIndexStyle(4,DRAW_NONE,EMPTY,2);
   SetIndexStyle(5,DRAW_NONE,EMPTY,2);
//----
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexEmptyValue(5,0.0);
//---- name for DataWindow
   SetIndexLabel(0,"Fractal Up");
   SetIndexLabel(1,"Fractal Down");
   SetIndexLabel(2,"Signal Up");
   SetIndexLabel(3,"Signal Down");
   SetIndexLabel(4,"Diapazon Up");
   SetIndexLabel(5,"Diapazon Down");
//---- initialization done   
   IndicatorShortName("F5S");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,nCountedBars;
   nCountedBars=IndicatorCounted();
//---- check for possible errors
   if(nCountedBars<0 || Bars<5) return(-1);
//----
   i=Bars-nCountedBars-1;
   while(i>=0)
     {
      //----Up and Down Fractals
      //----5 bars Fractal
      if(High[i+3]>High[i+3+1] && High[i+3]>High[i+3+2] && High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
        {
         dUpSignalBuffer[i]= Open[i+1];
         dUpFractalsBuffer[i+3]= High[i+3];
         UpDiapazonBuffer[i]= Open[i];
         UpDiapazonBuffer[i+3]= High[i+3];
        }
      if(Low[i+3]<Low[i+3+1] && Low[i+3]<Low[i+3+2] && Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
        {
         dDownSignalBuffer[i]= Open[i+1];
         dDownFractalsBuffer[i+3]= Low[i+3];
         DnDiapazonBuffer[i]= Open[i];
         DnDiapazonBuffer[i+3]= Low[i+3];
         i--;
         continue;
        }
      //----6 bars Fractal
      if(High[i+3]==High[i+3+1] && High[i+3]>High[i+3+2] && High[i+3]>High[i+3+3] && High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
        {
         dUpSignalBuffer[i]= Open[i+1];
         dUpFractalsBuffer[i+3]= High[i+3];
         UpDiapazonBuffer[i]= Open[i];
         UpDiapazonBuffer[i+3]= High[i+3];
        }
      if(Low[i+3]==Low[i+3+1] && Low[i+3]<Low[i+3+2] && Low[i+3]<Low[i+3+3] && Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
        {
         dDownSignalBuffer[i]= Open[i+1];
         dDownFractalsBuffer[i+3]= Low[i+3];
         DnDiapazonBuffer[i]= Open[i];
         DnDiapazonBuffer[i+3]= Low[i+3];
         i--;
         continue;
        }
      //----7 bars Fractal
      if(High[i+3]>=High[i+3+1] && High[i+3]==High[i+3+2] && High[i+3]>High[i+3+3] && High[i+3]>High[i+3+4] && High[i+3]>High[i+3-1] &&
         High[i+3]>High[i+3-2])
        {
         dUpSignalBuffer[i]= Open[i+1];
         dUpFractalsBuffer[i+3]= High[i+3];
         UpDiapazonBuffer[i]= Open[i];
         UpDiapazonBuffer[i+3]= High[i+3];
        }
      if(Low[i+3]<=Low[i+3+1] && Low[i+3]==Low[i+3+2] && Low[i+3]<Low[i+3+3] && Low[i+3]<Low[i+3+4] && Low[i+3]<Low[i+3-1] &&
         Low[i+3]<Low[i+3-2])
        {
         dDownSignalBuffer[i]= Open[i+1];
         dDownFractalsBuffer[i+3]= Low[i+3];
         DnDiapazonBuffer[i]= Open[i];
         DnDiapazonBuffer[i+3]= Low[i+3];
         i--;
         continue;
        }
      //----8 bars Fractal                          
      if(High[i+3]>=High[i+3+1] && High[i+3]==High[i+3+2] && High[i+3]==High[i+3+3] && High[i+3]>High[i+3+4] && High[i+3]>High[i+3+5] &&
         High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
        {
         dUpSignalBuffer[i]= Open[i+1];
         dUpFractalsBuffer[i+3]= High[i+3];
         UpDiapazonBuffer[i]= Open[i];
         UpDiapazonBuffer[i+3]= High[i+3];
        }
      if(Low[i+3]<=Low[i+3+1] && Low[i+3]==Low[i+3+2] && Low[i+3]==Low[i+3+3] && Low[i+3]<Low[i+3+4] && Low[i+3]<Low[i+3+5] &&
         Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
        {
         dDownSignalBuffer[i]= Open[i+1];
         dDownFractalsBuffer[i+3]= Low[i+3];
         DnDiapazonBuffer[i]= Open[i];
         DnDiapazonBuffer[i+3]= Low[i+3];
         i--;
         continue;
        }
      //----9 bars Fractal                                        
      if(High[i+3]>=High[i+3+1] && High[i+3]==High[i+3+2] && High[i+3]>=High[i+3+3] && High[i+3]==High[i+3+4] && High[i+3]>High[i+3+5] &&
         High[i+3]>High[i+3+6] && High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
        {
         dUpSignalBuffer[i]= Open[i+1];
         dUpFractalsBuffer[i+3]= High[i+3];
         UpDiapazonBuffer[i]= Open[i];
         UpDiapazonBuffer[i+3]= High[i+3];
        }
      if(Low[i+3]<=Low[i+3+1] && Low[i+3]==Low[i+3+2] && Low[i+3]<=Low[i+3+3] && Low[i+3]==Low[i+3+4] && Low[i+3]<Low[i+3+5] &&
         Low[i+3]<Low[i+3+6] && Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
        {
         dDownSignalBuffer[i]= Open[i+1];
         dDownFractalsBuffer[i+3]= Low[i+3];
         DnDiapazonBuffer[i]= Open[i];
         DnDiapazonBuffer[i+3]= Low[i+3];
         i--;
         continue;
        }
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments