FX-BAR

The FX-BAR indicator is designed to provide a visual representation of price momentum by analyzing the relationship between current market prices and their historical moving averages. It operates by identifying trends and displaying them through a distinct histogram format, helping traders distinguish between upward and downward movements.

Core Logic Overview

The indicator functions by performing three primary types of calculations:

1. Price Deviation Analysis The tool starts by calculating the distance between two key price points:

  • It looks at the high price of a candle and compares it against a Smoothed Moving Average (SMMA).
  • Simultaneously, it looks at the low price of a candle and compares it against that same moving average. This creates a raw "gap" value that represents how far the market is stretching away from its average trend.

2. Trend Directional Logic Rather than just showing raw numbers, the script processes these deviations to determine the direction of the momentum. It tracks whether the current deviation is increasing or decreasing compared to the previous candle.

  • If the value is rising, it classifies the movement as "Up."
  • If the value is falling, it classifies the movement as "Down."

3. Visual Histogram Representation The final output is organized into a series of visual bars (histograms) on a separate window below your main price chart. The logic splits the data into two distinct visual sets:

  • One set of bars represents upward momentum.
  • The other set of bars represents downward momentum.

By isolating these movements, the indicator provides a cleaner visual field where "upward" pushes and "downward" pulls are clearly separated from one another. This allows users to see the strength of the current trend at a glance, as the size and direction of the histograms change based on how aggressively the price is moving relative to its average.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
FX-BAR
//+------------------------------------------------------------------+
//|                                                      FX-BAR.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  Black
#property  indicator_color2  Gold
#property  indicator_color3  Red
#property  indicator_color4  Black
#property  indicator_color5  Gold
#property  indicator_color6  Red

//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];
double     ExtBuffer3[];
double     ExtBuffer4[];
double     ExtBuffer5[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexStyle(5,DRAW_HISTOGRAM);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,34);
   SetIndexDrawBegin(1,34);
   SetIndexDrawBegin(2,34);
   SetIndexDrawBegin(3,34);
   SetIndexDrawBegin(4,34);
   SetIndexDrawBegin(5,34);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
    SetIndexBuffer(3,ExtBuffer3);
   SetIndexBuffer(4,ExtBuffer4);
   SetIndexBuffer(5,ExtBuffer5);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("FX-BAR");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
    SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
    int    limit2;
   int    counted_bars2=IndicatorCounted();
   double prev2,current2;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars2>0) counted_bars2--;
   limit2=Bars-counted_bars2;
//---- macd
   for(int i=0; i<limit; i++)
   
    ExtBuffer0[i] = iHigh(NULL,0,i)-iMA(NULL,0,8,5,MODE_SMMA,PRICE_MEDIAN,i);
     
 
    for(int n=0; n<limit2; n++)
    
      ExtBuffer3[n]=iLow(NULL,0,n)-iMA(NULL,0,8,5,MODE_SMMA,PRICE_MEDIAN,n);
 
 
    
     
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
     if (ExtBuffer0[i]>=0){
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
      }
       if (ExtBuffer0[i]<0){
       ExtBuffer0[i]=0;
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
      }
      
      
      
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
      else
        {
         ExtBuffer1[i]=current;
         ExtBuffer2[i]=0.0;
        }
     }
     
      bool up2=true;
   for(n=limit2-1; n>=0; n--)
     
        {
     if (ExtBuffer3[n]<=0){
      current2=ExtBuffer3[n];
      prev2=ExtBuffer3[n+1];
      }
       if (ExtBuffer3[n]>0){
       ExtBuffer3[n]=0;
      current2=ExtBuffer3[n];
      prev2=ExtBuffer3[n+1];
      }
      if(current2>prev2) up2=true;
      if(current2<prev2) up2=false;
      if(!up2)
        {
         ExtBuffer5[n]=current2;
         ExtBuffer4[n]=0.0;
        }
      else
        {
         ExtBuffer4[n]=current2;
         ExtBuffer5[n]=0.0;
        }
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments