|
Help on function call
Hi,
I would like to replace the code of this indicator :
int start()
{
int bar, limit, i;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//Hull average computation
for(i=0; i<limit; i++)
TempBuf1[i]=2*iMA(NULL,0,HalfHullPeriod,0,MODE_LWMA,PRICE_CLO SE,i)-iMA(NULL,0,HullPeriod,0,MODE_LWMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
HullBuf[i]=iMAOnArray(TempBuf1,0,SqrtHullPeriod,0,MODE_LWMA, i);
//----
return(0);
}
by a call at a function like that :
double ComputeHull(double MyArray[], int MyPeriod)
{
double MyTemp[];
double result = -1;
int i;
int HalfPeriod = MathRound(MyPeriod/2);
int SqrtPeriod = MathRound(MathSqrt(MyPeriod));
//Copy Close Values to CloseTemp
ArrayResize(MyTemp, SqrtPeriod);
ArraySetAsSeries(MyTemp, true);
//HMA value computation
for(i=0; i<SqrtPeriod; i++)
{
MyTemp[i] = 2*iMAOnArray(MyArray, 0, HalfPeriod, 0, MODE_LWMA, i) - iMAOnArray(MyArray, 0, MyPeriod, 0, MODE_LWMA, i);
}
result = iMAOnArray(MyTemp, 0, SqrtPeriod, 0, MODE_LWMA, 0);
//---- done
return(result);
}
int start()
{
double CloseTemp[];
int bar, limit, i;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
ArrayResize(CloseTemp, HullPeriod+SqrtHullPeriod);
ArraySetAsSeries(CloseTemp, true);
for(i=0; i<limit; i++)
{
ArrayCopy(CloseTemp, Close, 0, i, HullPeriod+SqrtHullPeriod);
HullAntBuf[i]=ComputeHull(CloseTemp, HullPeriod);
}
//----
return(0);
}
I don't understand why the result is not the same. It is not a spécific problem about the HMA just i'd like to ompute my indicator in a spécific function where the array is passed in argument.
I've attached source code of an indicator which display the two curves, it's seems that it is the second call to iMAOnArray which done different results.
Please help me i don't understand the problem
|