What do the shift parameters of the iMA () function mean?

Can someone explain to me what is the difference between the shift parameters of the iMA function iMA an example?
According to the MQL4 documentation:

ma_shift - shift with movement. The offset of the line of indicators refers to the chart on the timeframe.

shift - pointer to the value taken from the indicator buffer (offset relative to the current bar a specified number of periods ago)

What parameters are taken by the standard MA indicator?

+4
source share
2 answers
 double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift) 

For the standard standard indicator "Moving Average" the "Shift" field changes the parameter "ma_shift".

Indicator

For a packed custom Moving Averages indicator, the MA_Shift field changes the ma_shift parameter.

Custom indicator

Nothing in any of the indicators allows you to change the last parameter "shift".

comparison


Graphically, for the standard Moving Average indicator, changing the Shift field shifts the MA line to the right (with number + ve) and to the left (with number -ve) by the number of periods determined by an integer value.

ma_shift = 0: default

ma_shift = 4: ma_shift +4

ma_shift = -4: ma_shift -4

By code, when polling iMA () and setting ma_shift to 4, for example

 double iMA("EURUSD", PERIOD_H1, 8, 4, MODE_SMA, PRICE_CLOSE, 0) 

You will get a moving average of 4 periods ago.


This is a simple text indicator showing the value of iMA () with variable parameters period, ma_shift and shift. Play with it and check the "Moving Average" indicator (display the data window):

 #property indicator_chart_window extern int period = 8; extern int ma_shift = 0; extern int shift = 0; void start(){ string A1=StringConcatenate("Stat: ", DoubleToStr(MA(),5)); Comment(A1); return (0); } double MA(){ return(iMA(NULL, 0, period, ma_shift, 0, 0, shift)); } 

The last โ€œshiftโ€ parameter in the iMA () function shifts the periods used for calculation, and can only be the number + ve. The number A -ve will request future non-existent periods. You can try to put a -ve the number in the text indicator above to find out what you are getting. (0.00000) As mentioned above, indicators do not allow editing this parameter simply because they are practically the same.

 double iMA("EURUSD", PERIOD_H1, 8, 4, MODE_SMA, PRICE_CLOSE, 0) 

same as

 double iMA("EURUSD", PERIOD_H1, 8, 0, MODE_SMA, PRICE_CLOSE, 4) 

So why is that so? Most likely, as standardization with other indicators, for example. http://docs.mql4.com/indicators/iAlligator where the "shift" parameter is a comprehensive determinant for which periods to calculate, and a separate jaw_shift, teeth_shift, lips_shift are independent parameters for the graphic shift of lines.

+11
source

" ma_shift " is the graphic shift of the "line". This only applies to displaying array values. Doesn't matter much for encoding EA s.

" shift " is the value of the element taken into account. By default, the offset value is zero (zero band (last band)). Any column shifts in MQL4 from the last bar to the back.

An example :
You are comparing two SMA . One of them is 20 periods / 0, the other is 10 periods / 4 shifts. Each comparison between SMA will be performed between the 20th SMA period in the last lane in the array and the 10th SMA period 4 returned to the array.
In numbers ...
Let's say that 20 SMA in the last bar is 1.1000 .
Assume a 10 SMA looks like this:
1.1050 at 0 bar (last line)
1.1000 per 1 bar (previous bar)
1.0950 to 2 bar (two bars back)
1.0900 at 3 bars (three bars back)

Result:
Is 20SMA( shift0 ) > 10SMA( shift0 ) => NO
Is 20SMA( shift0 ) > 10SMA( shift3 ) => Yes

Finally. ma_shift is a line shift forward / backward. shift is the shift in the value of the shift back (from 0 / last bar).

A value of 4 shifts represents an MA value of 4 bars back. This parameter is available only for coding, in order to build an algorithm. ma_shift not related to EA s because when the computer calculates the intersection of MA , it uses the values โ€‹โ€‹of the array, not the string itself.

Good luck

0
source

Source: https://habr.com/ru/post/1497759/


All Articles