# Automated Trading and Strategy Testing Forum

Subscribe to signal
DREAMCAPITALS
229.29%, 100.89 USD
Indicator
BollingerBands%b
Author: GODZILLA
Try product
TTMM Time To Make Money
Author: Aktiniy
Screenshot
EURUSD., H1
Real

## // Indicators: Center of Gravity J. F. Ehlers

20504

Center of Gravity actually has a zero lag and allows to define turning points precisely. This indicator is the result of Ehler's study of adaptive filters.

The indicator Center of Gravity allows to identify main pivot points almost without any lag.

The idea of calculating a center of gravity appeared from the investigation of lags of different filters with the finite impulse response (FIR) in accordance with the relative amplitude of filter coefficients. SMA (Simple Moving Average) is a FIR-filter, in which all coefficients have one and the same value. As a result the center of gravity of SMA is an exact center of the filter. WMA (Weighted Moving Average) is a FIR-filter, in which the last price change is weighted through the filter length, and so on.

The values of weighting are coefficients of filters. Coefficients of WMA filters can be presented as contours of a triangle. The center of gravity is on the 1/3 of the triangle base length. Thus WMA gravity center is shifted to the right with respect to the center of gravitation of SMA of the same length, which gives us a smaller lag. For all examples with FIR filters the sum of productions of coefficients and the price must be divided by the sum of coefficients for preservation of original prices.

Author: Nikolay Kositsin

Statistical Estimations
Estimation of statistical parameters of a sequence is very important, since most of mathematical models and methods are based on different assumptions. For example, normality of distribution law or dispersion value, or other parameters. Thus, when analyzing and forecasting of time series we need a simple and convenient tool that allows quickly and clearly estimating the main statistical parameters. The article shortly describes the simplest statistical parameters of a random sequence and several methods of its visual analysis. It offers the implementation of these methods in MQL5 and the methods of visualization of the result of calculations using the Gnuplot application.

3
InfiniteDesign 2011.08.29 20:59

Hello,

This oscillator is a great one, but I have problems with it.

The signal line's end, wich is calculated by the last candle is not shown, so it always shows red at the present time. When I reset the oscillator it shows good values for a moment with the end of the signal line, but then switches back to red, (even if it has to show green).

What should i do to eliminate this problem?

I've tried to re-debug it but it didn't help.

Greets,

InfiniteDesign

21
FForex 2011.09.15 06:05
In his opinion this indicator which works with mehor and symbol and timeframe.
What the best values ​​for the parameters of this indicator?

3
gideons 2012.07.23 13:30

Many many thanks for this great indicator.

I found the previous version as interesting and useful as the new one, or in fact even more so..

Could you please port the old one to mq5 as well ? I'd highly appreciate if it can be done.

Cheers, and thanks in advance !!

40
This indicator is non-deterministic. Ask for the same datapoints twice, at different times, and you'll get different answers. The drift is larger closer to the current time. The inconsistency can be as large as 3.7 x 10^-04.

311
BrunoPio 2012.08.10 03:35
InfiniteDesign:

Hello,

This oscillator is a great one, but I have problems with it.

The signal line's end, wich is calculated by the last candle is not shown, so it always shows red at the present time. When I reset the oscillator it shows good values for a moment with the end of the signal line, but then switches back to red, (even if it has to show green).

What should i do to eliminate this problem?

I've tried to re-debug it but it didn't help.

Greets,

InfiniteDesign

I have the same problem...

311
BrunoPio 2012.08.10 03:38

I tried to create a Signal from this indicator, but I was unable...

Any help?

//+------------------------------------------------------------------+
//|                                                          COG.mqh |
//|                                                        Bruno Pio |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property version   "1.00"
#include "..\ExpertSignal.mqh"   // CExpertSignal is in the file ExpertSignal
#property tester_indicator "CenterOfGravity.ex5"
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class                                         |
//| Title=Signals of Center of Gravity                               |
//| Name=My_COG                                                      |
//| ShortName=CG                                                     |
//| Class=COG                                                        |
//| Page=Not needed                                                  |
//| Parameter=Period_,int,10,Indicator averaging period              |
//| Parameter=SmoothPeriod,int,3,Signal line smoothing period        |
//| Parameter=MA_Method_,ENUM_MA_METHOD,MODE_EMA,Signal Method       |
//| Parameter=AppliedPrice,int,1,Price constant                      |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class COG : public CExpertSignal
{
private:
CiCustom             m_COG;               // The indicator as an object
//--- Configurable module parameters
int               m_Period_;           // Indicator averaging period
int               m_SmoothPeriod;      // Signal line smoothing period
ENUM_MA_METHOD    m_MA_Method_;        // Signal line averaging method
int               m_AppliedPrice;      // Price constant
public:
COG(void);
~COG(void);
//--- Checking correctness of input data
bool              ValidationSettings();
//--- Creating indicators and timeseries for the module of signals
bool              InitIndicators(CIndicators *indicators);
double            CG(const int index)                 const { return(m_COG.GetData(0,index)); }
double            Signal(const int index)             const { return(m_COG.GetData(1,index)); }
//--- Checking buy and sell conditions
virtual int       LongCondition();
virtual int       ShortCondition();
//--- Methods for setting
void              Period_(int value)               { m_Period_=value;        }
void              SmoothPeriod(int value)          { m_SmoothPeriod=value;   }
void              MA_Method_(ENUM_MA_METHOD value) { m_MA_Method_=value;     }
void              AppliedPrice(int value)          { m_AppliedPrice=value;   }
protected:
//--- Creating indicator
bool              CreateCOG(CIndicators *indicators);

};
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
COG::COG(void) :           m_Period_(10),                // Indicator averaging period
m_SmoothPeriod(3),            // Signal line smoothing period
m_MA_Method_(MODE_EMA),       // Signal line averaging method
m_AppliedPrice(1)             // Price constant
{
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
COG::~COG()
{
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Checks input parameters and returns true if everything is OK     |
//+------------------------------------------------------------------+
bool COG:: ValidationSettings()
{
//--- Call the base class method
if(!CExpertSignal::ValidationSettings())  return(false);
//--- Check periods, number of bars for the calculation of the MA >=1
if(m_Period_<1)
{
PrintFormat("Incorrect value set for one of the period! Period_=%d",
m_Period_);
return false;
}
//--- Check periods, number of bars for the calculation of the MA >=1
if(m_SmoothPeriod<1)
{
PrintFormat("Incorrect value set for one of the period! m_SmoothPeriod=%d",
m_SmoothPeriod);
return false;
}
//--- Fast MA smoothing type must be one of the four values of the enumeration
if(m_MA_Method_!=MODE_SMA && m_MA_Method_!=MODE_EMA && m_MA_Method_!=MODE_SMMA && m_MA_Method_!=MODE_LWMA)
{
PrintFormat("Invalid type of smoothing of the fast MA!");
return false;
}
//--- m_AppliedPrice must be validy
if(m_AppliedPrice<1 || m_AppliedPrice>11)
{
PrintFormat("Invalid type of Price!");
return false;
}
//--- All checks are completed, everything is ok
return true;
}
//+------------------------------------------------------------------+
//| Creates indicators                                               |
//| Input:  a pointer to a collection of indicators                  |
//| Output: true if successful, otherwise false                      |
//+------------------------------------------------------------------+
bool COG::InitIndicators(CIndicators *indicators)
{
//--- Standard check of the collection of indicators for NULL
if(indicators==NULL) return(false);
//--- Initializing indicators and timeseries in additional filters
if(!CExpertSignal::InitIndicators(indicators)) return(false);
//--- Creating our indicators
if(!CreateCOG(indicators))                  return(false);
//--- Reached this part, so the function was successful, return true
return(true);
}
//+------------------------------------------------------------------+
//| Creates the "COG" indicator                                      |
//+------------------------------------------------------------------+
bool COG::CreateCOG(CIndicators *indicators)
{
//--- Checking the pointer
if(indicators==NULL) return(false);
//--- Adding an object to the collection
{
printf(__FUNCTION__+": Error adding an object of the COG");
return(false);
}
//--- Setting parameters of the COG
MqlParam parameters[5];
//---
parameters[0].type=TYPE_STRING;
parameters[0].string_value="CenterOfGravity.ex5";
parameters[1].type=TYPE_INT;
parameters[1].integer_value=m_Period_;                 // Period
parameters[2].type=TYPE_INT;
parameters[2].integer_value=m_SmoothPeriod;            // Signal line smoothing period
parameters[3].type=TYPE_INT;
parameters[3].integer_value=m_MA_Method_;              // Signal line averaging method
parameters[4].type=TYPE_INT;
parameters[4].integer_value=m_AppliedPrice;            // Price constant
//--- Object initialization
if(!m_COG.Create(m_symbol.Name(),0,IND_CUSTOM,5,parameters))
{
printf(__FUNCTION__+": Error initializing the object of the COG");
return(false);
}
//--- Number of buffers
if(!m_COG.NumBuffers(2)) return(false);
//--- Reached this part, so the function was successful, return true
return(true);
}
//+------------------------------------------------------------------+
//| Returns the strength of the buy signal                           |
//+------------------------------------------------------------------+
int COG::LongCondition()
{
int signal=0;
//--- For operation with ticks idx=0, for operation with formed bars idx=1
int idx=StartIndex();
//--- Values of COGs at the last formed bar
double last_fast_value=CG(idx);
double last_slow_value=Signal(idx);
//--- Values of COGs at the last but one formed bar
double prev_fast_value=CG(idx+1);
double prev_slow_value=Signal(idx+1);
//---If CG > Signal && CG-1 < Signal-1
if((last_fast_value>last_slow_value) && (prev_fast_value<prev_slow_value))
{
signal=100; // There is a signal to buy
}
//--- Return the signal value
return(signal);
}
//+------------------------------------------------------------------+
//| Returns the strength of the sell signal                          |
//+------------------------------------------------------------------+
int COG::ShortCondition()
{
int signal=0;
//--- For operation with ticks idx=0, for operation with formed bars idx=1
int idx=StartIndex();
//--- Values of COGs at the last formed bar
double last_fast_value=CG(idx);
double last_slow_value=Signal(idx);
//--- Values of COGs at the last but one formed bar
double prev_fast_value=CG(idx+1);
double prev_slow_value=Signal(idx+1);
//---If CG < Signal && CG-1 > Signal-1
if((last_fast_value<last_slow_value) && (prev_fast_value>prev_slow_value))
{
signal=100; // There is a signal to sell
}
//--- Return the signal value
return(signal);
}
/