I think there's an error with this code. Basically it's supposed to find the average of the candle's body range. But I tried a few periods, and it seems to be incorrect at period 4 and above...
for example these are the numbers for USDJPY (O-C) for the past 5 days
day 1: 13
day 2: 78
day 3: 18
day 4: 21
day 5: 6
but the average it gives me at day 4 is 22 instead of 32.5
here's the code
for example these are the numbers for USDJPY (O-C) for the past 5 days
day 1: 13
day 2: 78
day 3: 18
day 4: 21
day 5: 6
but the average it gives me at day 4 is 22 instead of 32.5
here's the code
PHP Code
#property indicator_buffers 6 #property indicator_separate_window #property indicator_color1 Lime #property indicator_color2 DarkOrange #property indicator_color3 Blue double dRange5[]; double dRange10[]; double dRange20[]; double dBodysize5[]; double dBodysize10[]; double dBodysize20[]; extern int MoveAvgPeriod5 = 4; extern int MoveAvgPeriod10 =10; extern int MoveAvgPeriod20 =20; extern int MoveAvgMethod = MODE_SMA; int init() { SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1); SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,dRange5); SetIndexBuffer(1,dRange10); SetIndexBuffer(2,dRange20); SetIndexBuffer(3,dBodysize5); SetIndexBuffer(4,dBodysize10); SetIndexBuffer(5,dBodysize20); SetIndexLabel(0, "Range(5)"); SetIndexLabel(1, "Range(10)"); SetIndexLabel(2, "Range(20)"); SetIndexLabel(3, "Bodysize(5)"); SetIndexLabel(4, "Bodysize(10)"); SetIndexLabel(5, "Bodysize(20)"); return(0); } int start() { int counted_bars=IndicatorCounted(); for(int i=Bars;i>=0;i--) { double dCloseMA5 = iMA(NULL,0,MoveAvgPeriod5,0,MoveAvgMethod,PRICE_CLOSE,i); double dOpenMA5 = iMA(NULL,0,MoveAvgPeriod5,0,MoveAvgMethod,PRICE_OPEN, i); double dHighMA5 = iMA(NULL,0,MoveAvgPeriod5,0,MoveAvgMethod,PRICE_HIGH, i); double dLowMA5 = iMA(NULL,0,MoveAvgPeriod5,0,MoveAvgMethod,PRICE_LOW, i); dBodysize5[i] = MathAbs((dCloseMA5-dOpenMA5))/Point; } return(0); }