What am I missing with ENUM variables for MT5?
-
I created this easy EA for MT5 in which I need to select between two types of MA: simple or smoothed.
https://fxdreema.com/shared/1m0hts8W
I visited mql5.com's intruction pages and I found I had to create an ENUM_MA_METHOD type variable. However, when I try it here it doesn't work. No arrow is plotted no matter what method I select. Can someone please tell me what am I missing?
-
@l-andorrà said in What am I missing with ENUM variables for MT5?:
ENUM_MA_METHOD
If you add to a constant/variable what's in this picture:

Then you get these options in inputs:

Ignore MT4, MT5 is busy optimising.
-
@jstap Thank you for the info. However, can that Constant/Variable be optimized? What if I want to test all MA methods in the optimization? Shouldn't I use numbers instead as step a stop values on MT5?
-
@l-andorrà Although this is a good question when time frames are selected using the enum method the EA can optimise all, I have never used the number method except for start/finish time but if you use this as custom code I think it would work:
if((Ma_Method = 1) {Value = "MODE_SMA";}
if((Ma_Method = 2) {Value = "MODE_SMMA";}
if((Ma_Method = 3) {Value = "MODE_EMA";}
if((Ma_Method = 4) {Value = "MODE_LWMA";} -
@l-andorrà
You can optimize the SMA_MODE the first way jstap showed you.
Set -> start value : Simple
stop value : Linear weighted
And the optimizer will go through all SMA_MODE. Just the optimization will be a bit messy as it isn't a quantitative parameter. -

as jstap pointed out, that method is 100% effective.
the simplest approach is to use whats built into Dreema. As on the screenshot, you must select the box next to the drop down. Then when optimizing, 0=Simple, 1= Exponential, etc.
to test for all on mt5, it would be 0 start, with 1 step, 4 end.
-
@jstap Very interesting. Should I type that custom code 'as is' in a custom code block?
-
@seb-0 Thank you. And what option should be selected on the 'step' column?
-
@tipsywisdom Thanks for the info. That I know but I need to choose the name of the Constant. That name offered by default is too ugly.
-
@jstap I tried your code but I get several errors. Are you sure it is correct? I'm not a coder, sadly.

-
-
@l-andorrà I am not a coder, all self tort but I see where I went wrong though:
if((Ma_Method = 1) {Value = "MODE_SMA"};
if((Ma_Method = 2) {Value = "MODE_SMMA"};
if((Ma_Method = 3) {Value = "MODE_EMA"};
if((Ma_Method = 4) {Value = "MODE_LWMA"};
I put the semi colon the wrong side : )You can also make the = == some code needs this, not sure what the deference is and don't think you will need.
Add the code like this:

Step by 1, start at 1 end at 2, if they are the MA's you want to test.
-
@l-andorrà said in What am I missing with ENUM variables for MT5?:
hahha ugly it is, but I say...if it aint broke, dont fix it.
-
@bk7 Thank you but I'm afraid not. I need the user to select a number that is then transformed into each Ma method.
-
@jstap Thanks again but it doesn't work. No matter what value for MA_method is selected, only MODE SMA is depicted.

-
@l-andorrà
it will be transformed into the mode, you just need to put in the correct number thats why i put the comment that you can see the changes done by changing the number. -
@l-andorrà Just change ENUM_MA_METHOD variable to a string variable have tested and works: link
-
@l-andorrà Have tested the code idea again, unfortunately this seems to have the same MA regardless of number put on input, looks like the only option you have is enum going through all. I do find sometimes code that worked on MT4 doesn't do the same on MT5.
-
just do it the ugly way my friend. Ugly but efficient, like a 1969 El Camino. Business up front, party in the rear.

-
I finaly got it! Thank you very much to all for your help.
