CandleAverage_v3

Author: Copyright � 2006, Forex-TSD.com
CandleAverage_v3

This script is a custom technical analysis tool designed to help traders visualize market momentum and price behavior by analyzing the relationship between high, low, and closing prices over specific timeframes.

Core Logic Overview

The indicator operates by measuring the "reach" of a price candle in two different directions: upwards and downwards. Instead of looking at just the raw price, it looks at the distance between the high/low points and the closing point to determine which direction had more influence during a specific period.

How It Works Step-by-Step

  1. Data Smoothing: The script begins by calculating three different moving averages based on the High, Low, and Close prices of the market. By using moving averages rather than raw data, the tool filters out "noise" and focuses on established trends.
  2. Distance Measurement: It then calculates two specific values:
    • The distance between the high price and the closing price.
    • The distance between the closing price and the low price.
  3. Directional Comparison: The script compares these two distances to determine the "strength" of the candle's movement:
    • If the distance from the high is smaller than the distance from the low, it identifies a downward bias.
    • If the distance from the high is larger than the distance from the low, it identifies an upward bias.
    • If the distances are equal, it remains neutral.
  4. Trend Smoothing: Finally, the script takes these directional values (the "biases") and applies a final smoothing average over a user-defined length. This translates the raw data into a histogram that displays on a separate window.

Purpose for the Trader

The resulting visual output helps traders see the prevailing sentiment of the market. Because it focuses on where the price actually settled relative to its extremes (the highs and lows), it provides a clearer picture of whether the current momentum is pushing toward the top or the bottom of the trading range, helping to identify potential trend shifts before they become obvious on a standard price chart.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
CandleAverage_v3
//+------------------------------------------------------------------+
//|                                             CandleAverage_v1.mq4 |
//|                                  Copyright © 2006, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue

//---- input parameters
extern int       Length=31;
extern int       H_period=25;
extern int       L_period=27;
extern int       C_period= 9;
//---- buffers
double CandleAvg[];
double BarValue[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,CandleAvg);
   SetIndexBuffer(1,BarValue);
//---- name for DataWindow and indicator subwindow label
   string short_name="CandleAverage("+Length+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"CandleAvg");
   SetIndexDrawBegin(0,Length);
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int shift, limit, counted_bars=IndicatorCounted();
   double UpDel,DnDel,H,L,C;
//---- 
   if(counted_bars<0) return(-1);
   if (counted_bars==0) limit=Bars-Length-1;
//---- last counted bar will be recounted
   if(counted_bars>0) limit=Bars-counted_bars;
   limit--;
   
   for(shift=limit; shift>=0; shift--)
   {
   H = iMA(NULL,0, H_period,0, MODE_EMA, PRICE_HIGH, shift);
   L = iMA(NULL,0, L_period,0, MODE_EMA, PRICE_LOW, shift);
   C = iMA(NULL,0, C_period,0, MODE_EMA, PRICE_CLOSE, shift);
   
   UpDel = H - C;
   DnDel = C - L;
   
   if ( UpDel < DnDel )  BarValue[shift] =  1;
   if ( UpDel > DnDel )  BarValue[shift] = -1;   
   if ( UpDel == DnDel ) BarValue[shift] =  0;
   }
   
   for(shift=limit; shift>=0; shift--)
   {
   CandleAvg[shift] = iMAOnArray(BarValue,0,Length,0,MODE_SMA,shift); 
   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments