The code that the average does not give incorrect last two bars on the (lime) average
line
#propertyindicator_separate_window#propertyindicator_buffers3#propertyindicator_color1Lime#propertyindicator_color2Magenta#propertyindicator_color3Orange#propertyindicator_level175#propertyindicator_level2120#propertyindicator_levelcolorWhiteexternintAtrPeriod=10;
//---- buffersdoubleAtrBuffer[];
doubleAtrBufferSPIKE[];
doubleAtrBufferAVE[];
doubleTempBuffer1[];
doubleTempBuffer2[];
doubleTempBuffer3[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intinit(){stringshort_name;
IndicatorBuffers(5);
IndicatorDigits(0);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,AtrBufferAVE);
short_name="Ians_HLR("+ AtrPeriod +") ";
IndicatorShortName(short_name + " Days Pip Range: Average / Last Day");
SetIndexLabel(0,"HLR_Ave");
SetIndexDrawBegin(0,AtrPeriod);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,AtrBuffer);
SetIndexDrawBegin(1,AtrPeriod);
SetIndexLabel(1,"HLR_Day");
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,AtrBufferSPIKE);
SetIndexDrawBegin(2,AtrPeriod);
SetIndexLabel(2,"HLR_Spike");
SetIndexBuffer(2,TempBuffer1);
SetIndexBuffer(3,TempBuffer2);
SetIndexBuffer(4,TempBuffer3);
return(0);
}//+------------------------------------------------------------------+//| Average True Range |//+------------------------------------------------------------------+intstart(){if(Period() != PERIOD_D1){Comment(" CAUTION : Ians_HLR only works on Daily Charts !!");
return(0);
}inti,k,counted_bars=IndicatorCounted();
if(Bars<=AtrPeriod)return(0);
if(counted_bars<1)for(i=1;i<=AtrPeriod;i++){AtrBufferAVE[Bars-i]=0;
AtrBufferSPIKE[Bars-i]=0;
AtrBuffer[Bars-i]=0;
}i=Bars-counted_bars-1;
while(i>=0){doublehigh=High[i];
doublelow =Low[i];
doublerange = NormalizeDouble((high-low)/Point,0);
TempBuffer1[i]=range;
TempBuffer2[i]=range;
if(range >= 120)TempBuffer3[i]=range; elseTempBuffer3[i]=0;
i--;
}if(counted_bars>0)counted_bars--;
intlimit=Bars-counted_bars;
for(i=0; i<limit; i++){//AtrBuffer[i]=TempBuffer2[i]; //I take these two arrays out and iMAOnArray works ok//AtrBufferSPIKE[i]=TempBuffer3[i];AtrBufferAVE[i]=iMAOnArray(TempBuffer1,Bars,AtrPeriod,0,MODE_SMA,i);
}return(0);
}
very weird, My computer has plenty of grunt.
//AtrBuffer[i]=TempBuffer2[i]; //I take these two arrays out and iMAOnArray works
ok
//AtrBufferSPIKE[i]=TempBuffer3[i];
Reducing demans on the loop when iMAOnArray is calculated sems to fix the average,
but limits what I want the inidcator to do, I tried separating them into two loops
loading the final buffers, this made no difference.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
This indicator plots days range, with a 10 day average.
The code that misbehaves
The code that the average does not give incorrect last two bars on the (lime) average line
very weird, My computer has plenty of grunt.
//AtrBuffer[i]=TempBuffer2[i]; //I take these two arrays out and iMAOnArray works ok
//AtrBufferSPIKE[i]=TempBuffer3[i];
Reducing demans on the loop when iMAOnArray is calculated sems to fix the average, but limits what I want the inidcator to do, I tried separating them into two loops loading the final buffers, this made no difference.
Any ideas . Thanks in Advance...