Center of Gravity1

Download script
Author: Copyright 2002, Finware.ru Ltd.
Center of Gravity1

This tool, known as the Center of Gravity (COG) indicator, is designed to help traders visualize the "balance point" of price action over a specific period. Instead of looking at raw price fluctuations, it calculates where the weight of the market movement actually sits, providing a smoother interpretation of trends.

How It Works

The logic behind this script can be broken down into three main components:

1. The Calculation Window The indicator looks back at a specific number of candles (defined by the "Per" setting). Rather than reacting to every tiny flicker in price, it gathers data from this entire block of time to determine a single average value for each point on your chart.

2. Weighted Averaging Unlike a simple moving average that treats every candle equally, this logic applies a weighted approach. It looks at the "midpoint" of each candle (the average between the highest and lowest price reached during that timeframe) and factors in its position within the window. This allows the indicator to give more significance to certain data points, helping it identify where the "mass" of the price movement is concentrated.

3. Visual Representation The script processes these calculations and plots two distinct lines on a separate window below your main chart:

  • Primary Line: Represents the calculated Center of Gravity.
  • Secondary Line: Provides a slightly offset companion line to help traders better identify the direction and momentum of the balance point.

Practical Use for Traders

By observing these lines, you can see whether the market is "heavy" on the upper side (bullish sentiment) or the lower side (bearish sentiment). When the Center of Gravity shifts significantly, it often signals a change in the prevailing trend. Because it smooths out minor noise, it serves as a useful guide for identifying the core trend of the market without getting distracted by short-term price spikes.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Center of Gravity1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+

//| Center of Gravity.mq4

//|

//+------------------------------------------------------------------+

#property copyright "Copyright 2002, Finware.ru Ltd."

#property link "http://www.finware.ru/"


#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red


//Inputs : Per(10);

//Variable : shift(0),StartBar(600);

//Variable : value1(0), sum(0),sum1(0), cnt(0);


extern int Per=10;

extern int CountBars=300;

//---- buffers

double val1[];

double val2[];


//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

string short_name;

//---- indicator line

IndicatorBuffers(2);

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,val1);

SetIndexStyle(1,DRAW_LINE);

SetIndexBuffer(1,val2);

//----

return(0);

}

//+------------------------------------------------------------------+

//| Center of Gravity |

//+------------------------------------------------------------------+

int start()

{

if (CountBars>=Bars) CountBars=Bars;

SetIndexDrawBegin(0,Bars-CountBars+Per+1);

SetIndexDrawBegin(1,Bars-CountBars+Per+1);

int i,cnt,counted_bars=IndicatorCounted();

double value1,sum,sum1;

//----

if(Bars<=38) return(0);

//---- initial zero

if(counted_bars<Per)

{

for(i=1;i<=0;i++) val1[CountBars-i]=0.0;

for(i=1;i<=0;i++) val2[CountBars-i]=0.0;

}

//----

i=CountBars-Per-1;

// if(counted_bars>=39) i=Bars-counted_bars-1;

while(i>=0)

{


sum = 0.0;

for (cnt=0; cnt<=Per-1; cnt++)

{

sum = sum + (High[i+cnt]+Low[i+cnt])/2;

}


sum1=0.0;

for (cnt=0; cnt<=Per-1; cnt++)

{

sum1=sum1+((High[i+cnt]+Low[i+cnt])*(cnt+1)/2);

}


value1=sum/sum1;

//SetIndexValue(i,value1);

//SetIndexValue2(i-1,value1);


val1[i]=value1;

if (i>0) val2[i-1]=value1;


i--;

}

return(0);

} //+------------------------------------------------------------------+

Comments