How to set a "-5" in MA shift?

 

Hello,



i like to set a "-5" into an moving average shift.


extern int    MA1_Shift=0;


it works with normal numbers and "-1" but not with "-5". On "-5" no trades are done.


First i thought, that MQL doesn´t support "- numbers" but why does "-1" work?

Any advice?


Thanks!!

 
6578466543:

Hello,

i like to set a "-5" into an moving average shift.

extern int    MA1_Shift=0;

it works with normal numbers and "-1" but not with "-5". On "-5" no trades are done.

First i thought, that MQL doesn´t support "- numbers" but why does "-1" work?

-5 will work but don't try to get values for bars 0 to 4

This may help:  https://www.mql5.com/en/forum/145529 

 
RaptorUK :

-5 will work but don't try to get values for bars 0 to 4

This may help: https://www.mql5.com/en/forum/145529


Hello Raptor,



thanks for your answer. English isn´t my motherlanguage so it´s a bit heavy for me.


I use 2 moving averages on different periodes to see a trend. What i like to do is, shift the faster ma -5 backwards. The problem on the 2 moving averages is, that they are very slow. So if they reach a "cross" the price i have to pay is higher or lower. So i like to get a better price by shifting it back. It looks great with the -5 in a chart. I can set the MA1_Shift=-5, but if i try it in the strategy tester it doesen´t make even 1 trade. So i don´t know where the problem is.

 
6578466543 : So i don´t know where the problem is.
And we do? You haven't posted any code.
 
6578466543 :

Hello Raptor,

thanks for your answer. English isn´t my motherlanguage so it´s a bit heavy for me.

I use 2 moving averages on different periodes to see a trend. What i like to do is, shift the faster ma -5 backwards. The problem on the 2 moving averages is, that they are very slow. So if they reach a "cross" the price i have to pay is higher or lower. So i like to get a better price by shifting it back. It looks great with the -5 in a chart. I can set the MA1_Shift=-5, but if i try it in the strategy tester it doesen´t make even 1 trade. So i don´t know where the problem is.

Post your code, at least you iMA() calls . . . and make sure you use the SRC button
 
extern int MA1_Shift=0; // Âðåìåííîé ñäâèã ÌÀ1
extern int MA2_Shift=0; // Âðåìåííîé ñäâèã ÌÀ2

MA1_0=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 0); // Òåêóùåå çíà÷åíèå 1-é ÌÀ
MA1_1=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 1); // Ïðåäûäóùåå çíà÷åíèå 1-é ÌÀ
MA2_0=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 0); // Òåêóùåå çíà÷åíèå 2-é ÌÀ
MA2_1=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 1); // Ïðåäûäóùåå çíà÷åíèå 2-é ÌÀ



This is the whole code. I like to add or change the MA shift.


Thanks!

 
6578466543:
extern int MA1_Shift=0; // Âðåìåííîé ñäâèã ÌÀ1

MA1_0=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 0); // Òåêóùåå çíà÷åíèå 1-é ÌÀ

This is the whole code. I like to add or change the MA shift.

So change your external.

What i like to do is, shift the faster ma -5 backwards. So i like to get a better price by shifting it back.

Do you even understand was the ma_shift is? It won't change the lag at all. If you shift it backwards, you can NOT look at bars 4-0 because they don't exist.

This image is the SMA(10) white and Gold is shift -5MA_Shift = -5

 

Hello,

thanks for your fast answer.


If i change it in the Meta Trader menu to -5 no trades where done. I can set it to -1 this works, trades are done. But starting at -2 and higher into the "-" no trades are done.

I want to test this setting with -5 in the backtest to see if it makes sense.



Thanks.

 
6578466543:

Hello,

thanks for your fast answer.


If i change it in the Meta Trader menu to -5 no trades where done. I can set it to -1 this works, trades are done. But starting at -2 and higher into the "-" no trades are done.

I want to test this setting with -5 in the backtest to see if it makes sense.



Thanks.


Raptor has already explained.

Most EAs work mainly with the last closed bar and/or the current bar for opening positions

If you have the MA shift at -2, there is no information in the last closed bar or the current bar for the EA to work with. If the EA does not have sufficient information, it is unlikely to open a trade.

 
RaptorUK:
Post your code, at least you iMA() calls . . . and make sure you use the SRC button


6578466543:
extern int MA1_Shift=0; // Âðåìåííîé ñäâèã ÌÀ1
extern int MA2_Shift=0; // Âðåìåííîé ñäâèã ÌÀ2

MA1_0=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 0); // Òåêóùåå çíà÷åíèå 1-é ÌÀ
MA1_1=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 1); // Ïðåäûäóùåå çíà÷åíèå 1-é ÌÀ
MA2_0=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 0); // Òåêóùåå çíà÷åíèå 2-é ÌÀ
MA2_1=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 1); // Ïðåäûäóùåå çíà÷åíèå 2-é ÌÀ


This is the whole code. I like to add or change the MA shift.

Why didn't you use the SRC button as requested ?

I suggest you do this and then you will understand what is going on:

Add 2 MAs to any chart, just the standard Moving Average indicator, add one with a MA shift of 0 and one with a MA shift of -5, the use the Data Window (Ctrl + D) and look at bars to the left of bar 10 by placing your mouse pointer on the bar and looking at the Data Window, you will see two values, one for each of the 2 MAs, now look at bars 0 to 4 . . . you will see only one value, the other MA does not have a value.

 

Hello,


thanks for you answers.



What SRC button? I use the german version of Meta Editor, i also turned it to english but what SRC button?


A friend had the same problem that the moving average shift to -5 didn´t work. He got a update from the broker to his account so it work now. So i don´t know if i have the same problem here.


How can i use the shift to -5 so that it will work and the EA makes trades?


Thanks.

Reason: