/
Code: Select all
/////////////////////////////////////////////////////////////
// Calculate simple moving average value
__declspec( dllexport ) float f_GetAverage(IEasyLanguageObject * pELObj, int iAvgLength )
{
float dMovAvg = 0 ;
IEasyLanguagePricePtr price = pELObj->GetCloseMD(data1);
// verify that sufficient bars have passed before back-referencing historical prices
if( price->Getbarsback() > iAvgLength && iAvgLength > 0 )
{
float dSum = 0.0 ;
for (int i = 1; i < iAvgLength; i++)
{
dSum += (float)price->GetAsDouble(i);
}
dMovAvg = dSum / iAvgLength;
}
return dMovAvg ;
}