AwesomeBars

Download script
AwesomeBars

This custom indicator is designed to provide traders with a visual representation of specific price momentum and trend sustainability by measuring the length of continuous movement. Instead of simply showing standard price action, it analyzes the behavior of an underlying "Awesome" data source to determine how many consecutive bars have moved in a single direction without retreating.

How the Logic Works

The indicator operates by monitoring the price trends provided by an auxiliary tool (referenced as "Awesome"). It seeks to identify and count "streaks"—periods where the price values are consistently rising or consistently falling. Here is the step-by-step breakdown of its internal logic:

  • Trend Detection: The script constantly scans the historical data to determine if the current movement is upward or downward. It looks at the relationship between the current value and the value immediately preceding it.
  • Streak Counting: Once a direction is established (e.g., a series of rising bars), the logic enters a counting phase. It begins "counting" how many consecutive bars have maintained that specific direction.
  • Exhaustion Limits: The script is designed to look back significantly deep into the history (up to 200 bars) to ensure it captures the full extent of a trend. As soon as the price fails to continue its previous direction—meaning it hits a "peak" or a "trough"—the counting stops.
  • Data Visualization: The final result of this calculation is plotted as a line in a separate window on your chart. The height of the line represents the strength or duration of the trend: a higher value indicates a longer, more sustained movement in one direction, while a lower value suggests a shorter move or a recent change in market sentiment.

Summary for the Trader

In practical terms, this tool acts as a "momentum tracker." It helps you visualize how far a trend has traveled without a significant pullback. By observing the peaks and valleys of the indicator line, you can better understand the persistence of current market moves and potentially identify when a trend is becoming overextended.

Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
AwesomeBars
//+------------------------------------------------------------------+
//|                                                  AwesomeBars.mq4 |
//|                                     http://www.lightsites.co.za/ |
//+------------------------------------------------------------------+
#property link      "http://www.lightsites.co.za/"


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int aBarsPeriod=14;
//---- buffers
double aBarsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,aBarsBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="aBars("+aBarsPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,aBarsPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| aBarsentum                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   if(Bars<=aBarsPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=aBarsPeriod;i++) aBarsBuffer[Bars-i]=0.0;
//----
   i=Bars-aBarsPeriod-1;
   if(counted_bars>=aBarsPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
               static int pbars = 0;      
          
               double hh1 = 0, hh2 = 0;                 
                  
               if (iCustom(Symbol(),Period(),"Awesome",0,i) < iCustom(Symbol(),Period(),"Awesome",0,i+1) )
               {    
                  pbars = 0;
                  int n=0;
                  while(n<200)
                  {

                    hh1 = iCustom(Symbol(),Period(),"Awesome",0,i+n); 
                    hh2 = iCustom(Symbol(),Period(),"Awesome",0,i+n+1); 
                    n++;                    

                    if (hh1 > hh2)break; 
                    pbars++;
                 }               
               }  

                if (iCustom(Symbol(),Period(),"Awesome",0,i) > iCustom(Symbol(),Period(),"Awesome",0,i+1) )
               {    
                  pbars = 0;
                  n=0;
                  while(n<200)
                  {

                    hh1 = iCustom(Symbol(),Period(),"Awesome",0,i+n); 
                    hh2 = iCustom(Symbol(),Period(),"Awesome",0,i+n+1); 
                    n++;                    

                    if (hh1 < hh2)break; 
                    pbars++;
                 }               
               }   
      aBarsBuffer[i]=pbars;
      i--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments