Author: Copyright � 2008, TradeForexFx
Un Dn Bar

This tool is designed to help traders visually identify specific types of price action by highlighting "Up" and "Down" price bars on a trading chart. Instead of relying on simple price direction (like just looking at whether a candle closed higher or lower than it opened), this script analyzes the relationship between a candle's body size and its total range relative to recent market volatility.

How the Logic Works

The script functions by performing three main calculations for every candle on your chart:

1. Volatility Measurement The tool first looks at the 10 most recent candles to determine the average "range" (the distance between the highest and lowest points) of the market. This creates a baseline of how much the price is currently moving.

2. Identifying Significant Movement The script then calculates a "band"—a specific percentage of the current candle's total range (which you can customize via the settings). It uses this band to determine if a candle has a "strong" body.

3. Signal Detection The logic identifies two specific types of high-momentum candles:

  • Up Signals: The script looks for candles where the price opens near the bottom and closes near the top, with very little "wick" or hesitation. If the candle's body occupies enough space to satisfy the required percentage, it places a blue arrow below the bar.
  • Down Signals: Conversely, it looks for candles that open near the top and close near the bottom. When these high-momentum downward moves are detected, it places a red arrow above the bar.

Key Features for the User

  • Visual Clarity: By using arrows placed at a specific distance from the candle (calculated based on the average range), the signals remain clear and do not clutter the actual price bars.
  • Customizable Sensitivity: The "Percent" input allows you to decide how "strong" a candle must be to trigger a signal. A lower percentage will result in more frequent arrows, while a higher percentage will filter out smaller moves to only show the most aggressive price action.
  • Contextual Awareness: Because the tool calculates the average range of previous bars, it adapts to different market conditions (e.g., it recognizes that a "large" move during a quiet period is different from a "large" move during high-volatility news events).
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Un Dn Bar
//+------------------------------------------------------------------+
//|                                               Up Down Bar.mq4 |
//|                         Copyright © 2008, TradeForexFx |
//|                                 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, TradeForexFx"
#property link      "http://"

//#property indicator_separate_window

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

//---- input parameters
extern int       Percent = 33;

//---- buffers
double up[];
double dn[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexBuffer(0, up);
   SetIndexArrow(0, 233);

   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexBuffer(1, dn);
   SetIndexArrow(1, 234);
   

   
   
   
   
//----
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
//int start()
//{
 //  int    counted_bars = IndicatorCounted();
 //  double spread;
 //  double band;
 //  int limit = Bars - counted_bars;
 //  if(counted_bars == 0)
 //  {
 //     limit = Bars - 1;
 //  }
     
   
 int start() {

   int limit, i, counter;
   int counted_bars=IndicatorCounted();
   double spread;
   double band;
   double Range, AvgRange;
 
   
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   
//----
//   for(int i = 0; i < limit; i++)
//   {
   
     for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;  
    
   
   
   
   
   
   
      spread = High[i] - Low[i];
      band = spread * Percent * 0.01;
      
      up[i] = 0;
      dn[i] = 0;
      
      if(Open[i] < Low[i] + band && Close[i] > High[i] - band)
      {
      //   dn[i] = Low[i];
         up[i] = Low[i] - Range*0.5;
      }
      else if(Close[i] < Low[i] + band && Open[i] > High[i] - band)
      {
    //     up[i] = Low[i];
         dn[i] = High[i] + Range*0.5;
      }
   }
//----
   return(0);
}
//+------------------------------------------------------------------+

Comments