Author: Copyright � 2011, MetaQuotes Software Corp.
UpDownBars

This tool is designed to analyze price action by measuring the momentum of "up" candles versus "down" candles over a specific timeframe. Instead of simply looking at whether the price went up or down, it calculates a weighted intensity score to show you which direction the market is leaning more strongly.

How the Logic Works

1. Looking Back at History The tool examines a specific number of past candles (defined by a user-selected period, such as 20). It scans through these bars to identify every instance where the price closed higher than it opened (bullish) and every instance where it closed lower than it opened (bearish).

2. Calculating Individual Strength Rather than treating all price movements as equal, the script puts more importance on the most recent candles. It takes the magnitude of each move and applies a mathematical weight based on its position in time; movements that happened just now carry more "weight" in the final calculation than movements that happened further back in the past.

3. Averaging the Trends The script separates all the upward moves into one group and all the downward moves into another. It then calculates the average strength for both groups independently. This ensures that a single massive spike doesn't completely distort the data, providing a balanced view of the overall trend.

4. The Final Result Finally, the tool subtracts the average "down" strength from the average "up" strength.

  • If the result is positive, it indicates that upward pressure is currently dominating the price action.
  • If the result is negative, it shows that downward pressure is more significant.

The final output is displayed as a histogram, allowing you to visually track the tug-of-war between buyers and sellers in real-time.

12 Views
0 Downloads
0 Favorites
UpDownBars
//+------------------------------------------------------------------+
//|                                                   UpDownBars.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window

#property indicator_buffers 1               // Number of buffers
#property indicator_color1 Red

extern int period = 20;

double UpDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    SetIndexBuffer(0,UpDown);
    SetIndexStyle (0,DRAW_HISTOGRAM);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if(Bars<=period) return(0);
   
   int i;
   int    counted_bars=IndicatorCounted();
   
   double bar, ups, downs, upsDivide, downsDivide;
   int upsCount, downsCount;
   
   int limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
   {
      ups = 0;
      downs = 0;
      bar = 0;
      upsCount = 0;
      downsCount = 0;
      upsDivide=0;
      downsDivide=0;
      for(int j=period;j>=0;j--)
      {
         bar=(Close[i+j]-Open[i+j])*100000;
         if(bar>0)
         {
            ups+=(MathSqrt(bar)*((period+1-j)));
            upsCount++;
         }
         if(bar<0)
         {
            downs+=(MathSqrt(-bar)*((period+1-j)));
            downsCount++;
         }
      }
      if(upsCount!=0)
         upsDivide = ups/upsCount;
         
      if(downsCount!=0)
         downsDivide = downs/downsCount;
         
      UpDown[i]=NormalizeDouble(((upsDivide)-(downsDivide)),3);
   }
   return(0);
}
//+------------------------------------------------------------------+

Comments