Download MetaTrader 5

ima Shift -40 possible? CopyBuffer Error...?

To add comments, please log in or register
MQL5 Cloud Network speeds up calculations. Try it!
ismirnix
36
ismirnix 2011.07.29 17:28 

Hello, i'am using a Moving Average;


 MA1_HANDLE = iMA(Symbol(), Period(), 50, -40, MODE_SMA, PRICE_HIGH); // Gelb
 if(!MA1_HANDLE){
  Print("MA1_HANDLE = ",MA1_HANDLE,"  error = ",GetLastError()); ResetLastError();
 } else {
  ResetLastError();
  if(CopyBuffer(MA1_HANDLE,0,0,101,MA_GELB)<101){Print("MA_GELB CopyBuffer Error "+string(GetLastError())); return(0);}
  if(!ArraySetAsSeries(MA_GELB,true)) {Print("MA_GELB ArraySetAsSeries Error "+string(GetLastError())); return(0);}
 }

the shift is -40

in strategy tester, i get copyBuffer Error, if shift is 0 or positive there is no error...?

any idea?

dmanuge
5
dmanuge 2011.08.19 20:28  
ismirnix:

Hello, i'am using a Moving Average;


the shift is -40

in strategy tester, i get copyBuffer Error, if shift is 0 or positive there is no error...?

any idea?




Current time is 0. Previous times are positive.


This would imply future times are negative? You can't get values of iMA from the future -would be nice though.

Documentation on MQL5: Date and Time / TimeCurrent
  • www.mql5.com
Date and Time / TimeCurrent - Documentation on MQL5
Samuel Olowoyo
2241
Samuel Olowoyo 2011.08.20 00:23  
ismirnix:

Hello, i'am using a Moving Average;


the shift is -40

in strategy tester, i get copyBuffer Error, if shift is 0 or positive there is no error...?

MA1_HANDLE = iMA(Symbol(), Period(), 50, -40, MODE_SMA, PRICE_HIGH);

 

Hello,

If you look closely at the Moving Average Indicator Function, the shift (Shift of indicator relative to the price chart) value you indicated shows that you have shifted the value of the indicator by 40 bars behind. 

This means it will not have a value on the current bar (Bar 0). And in your code:

if(CopyBuffer(MA1_HANDLE,0,0,101,MA_GELB)<101)

You want to copy indicator buffer values from THE CURRENT BAR (Bar 0)  to the past 100 bars (Bar 100). You will only be able to copy from Bar 40  BACKWARDS. Their is no values for indicator buffer until Bar 40.

To understand my explanation, Open the Metatrader 5 terminal  and place your MA on any chart with buffer set to -20. You can use the Data Window to monitor this if you wish.

 

One you have placed the Moving Average on the chart, you  will see from the chart window that MA values will not be available from Bar 0 to Bar 19. (See the BOXED area in the chart below.

 

 

The MA will only have a value on Bar 20 down. This is why CopyBuffer will give error during testing since no value is available for the MA on Bars 0 - 19

Hope this explanation is clearer. 

  

 

Samuel Olowoyo
2241
Samuel Olowoyo 2011.08.20 00:25  
dmanuge:

Current time is 0. Previous times are positive.


This would imply future times are negative? You can't get values of iMA from the future -would be nice though.

Hello,

Using a -ve shift value in Indicator Functions does not necessarily refers to future. See my explanation above.

Amir Yacoby
1195
Amir Yacoby 2011.08.20 02:06  
olowsam:

Hello,

Using a -ve shift value in Indicator Functions does not necessarily refers to future. See my explanation above.

The 0 shift is the normal.

1 shift means each bar gets the indicator value of the previous bar.

-1 shift means each bar gets the indicator value of the next bar, which means future looking. This is why you don't get the first 19 bars indicator values.

put a 0 MA next to a -1 MA and then next to a +1 MA and see for yourself. 

To add comments, please log in or register