Using extern variables to set MA method into an EA

To add comments, please log in or register
Fernando Jose Velasco Borea
662
Fernando Jose Velasco Borea  

Hello, I'm trying to make the trader able to set MA type on an EA, I tried this coding:

enum MA_Method
 {
   Simple = 0,
   Exponential = 1,
   Smoothed = 2,
   LinearWeighted = 3
};

input MA_Method Mode = Simple;
double SlowMA = 200;


//...
//Some Coding
//...

double SlowMA = iMA(Symbol(),Period(),SlowMA,0,Mode,PRICE_CLOSE,1);

//...
//Rest of the EA
//...

But when I compile it it says "improper enumerator cannot be used" 

How can I fix this? I tried to add the mode id on "" (Simple = "0",...) but then it says "Constant expresion is not intergal" and "MA_Method declatation without type" and "Mode" undeclared identifier.

Any ideas?

Christopher Fernandez Ledon
993
Christopher Fernandez Ledon  
FernandoBorea:

Hello, I'm trying to make the trader able to set MA type on an EA, I tried this coding:

But when I compile it it says "improper enumerator cannot be used" 

How can I fix this? I tried to add the mode id on "" (Simple = "0",...) but then it says "Constant expresion is not intergal" and "MA_Method declatation without type" and "Mode" undeclared identifier.

Any ideas?

input ENUM_MA_METHOD Mode = MODE_SMA;

Victor Ian Torres
439
Victor Ian Torres  
FernandoBorea:

Hello, I'm trying to make the trader able to set MA type on an EA, I tried this coding:

But when I compile it it says "improper enumerator cannot be used" 

How can I fix this? I tried to add the mode id on "" (Simple = "0",...) but then it says "Constant expresion is not intergal" and "MA_Method declatation without type" and "Mode" undeclared identifier.

Any ideas?

Instead of putting the word "Simple", use the number you assign in the enum. Example: Mode = 0; (Simple),

William Roeder
20207
William Roeder  
FernandoBorea: Hello, I'm trying to make the trader able to set MA type on an EA, I tried this coding:
Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
          General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.

Victor Ian Torres: Instead of putting the word "Simple", use the number you assign in the enum. Example: Mode = 0; (Simple),
You missed the point. OP doesn't want numbers in the input, he want words in the properties box. Zero is meaningless to the code user, Simple is not. Write self-documenting code, don't hard code numbers.Inputs

But iMA takes a ENUM_MA_METHOD not a MA_Method. So

  1. Either use the proper enumeration (ENUM_MA_METHOD) to support all methods
  2. or if the values are the same cast the value to the proper type. It should be declared as
    enum MA_Method // Same as ENUM_MA_METHOD except no SMMA
     {
       Simple = MODE_SMA,
       Exponential = MODE_EMA,
       // Never any reason to use the SMMA(n) it's equivalent to the EMA(2n-1).
       // futures.io/ninjatrader-programming/8358-smoothed-moving-average-smma-how-avoid.html"
       // The Smoothed Moving Average or SMMA - How to Avoid It - NinjaTrader Programming | futures.io
       LinearWeighted = MODE_LWMA
    };
    input MA_Method Mode = Simple;
    :
    double SlowMA = iMA(Symbol(),Period(),SlowMA,0,ENUM_MA_METHOD(Mode),PRICE_CLOSE,1);

To add comments, please log in or register