improper enumerator cannot be used.

 

     I am working on compiling codes and have come to a bit of a loss when it comes to these 4 lines. am I just writing it an older way? do i need to define with an enum? 

       

double LOWWeekly = iMA(Symbol(),PERIOD_W1,1,0,MODE_LOW,PRICE_LOW,0);   // line for lower code

 ObjectSetText("Wlow",DoubleToStr(LOWWeekly,Digits), 12, "Arial Bold", Orange);


        double HIWeekly = iMA(Symbol(),PERIOD_W1,1,0,MODE_HIGH,PRICE_HIGH,0);    //line for lower code 

       ObjectSetText("Whigh",DoubleToStr(HIWeekly,Digits), 12, "Arial Bold", Orange);


 
Perhaps you should read the manual.
  1. The iMA does not return a double in MT5. Invalid smoothing method in either language. Wrong number of arguments.
    Your code
    Documentation
    double HIWeekly = iMA(
    Symbol(),
    PERIOD_W1,
    1,
    0,
    MODE_HIGH, <<< Not a smoothing method
    PRICE_HIGH,
    0          <<< invalid argument      
    );
    int  iMA(
       string             symbol,       // symbol name
       ENUM_TIMEFRAMES    period,       // period
       int                ma_period,    // averaging period
       int                ma_shift,     // horizontal shift
       ENUM_MA_METHOD     ma_method,    // smoothing type
       ENUM_APPLIED_PRICE applied_price // type of price or handle
    
       );
  2. Did you previous create those two objects?
  3. Why are you getting a moving average of length one? Just get the price you're interested in.
 
thank you i am still using mt4 perhaps this is my issue. 
 
Kyle Travis Mowery:
thank you i am still using mt4 perhaps this is my issue. 

Please post in the correct section in future.

I will move this to the MQL4 and Metatrader 4 section.

 
As William has already pointed out MODE_LOW and MODE_HIGH are not ENUM_MA_METHOD, check the documentation. This is the case for both MQL4 and 5.
 
  1. Kyle Travis Mowery: i am still using mt4 perhaps this is my issue. 
    Why did you post your MT4 question in the Root / MT5 General 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.

  2. double LOWWeekly = iMA(Symbol(),PERIOD_W1,1,0,MODE_LOW,PRICE_LOW,0)
    On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

 
i am new here and didnt realize that to be honest lol
 
input int SmallSMA = 5;
input int BigSMA = 21;

void OnTick()
   {
   
   string signal = "";
   
   
   double SmallMovingAverage1 = iMA (_Symbol, _Period, SmallSMA, MODE_EMA, PRICE_CLOSE,1,0);
   
   double BigMovingAverage1 = iMA  (_Symbol, _Period, BigSMA, MODE_EMA, PRICE_CLOSE,1,0);
   
   double SmallMovingAverage2 = iMA  (_Symbol, _Period, SmallSMA, MODE_EMA, PRICE_CLOSE,2,0);
   
   double BigMovingAverage2 = iMA  (_Symbol, _Period, BigSMA, MODE_EMA, PRICE_CLOSE,2,0);
     
   if(BigMovingAverage1 > SmallMovingAverage1)
   
   if(BigMovingAverage2 < SmallMovingAverage2)
   
   {
   
      signal="sell";
   }
   
   if (BigMovingAverage1 < SmallMovingAverage1)
   
   if (BigMovingAverage2 > SmallMovingAverage2)
   
   {
   
      signal="sell";
   }
   
   if (signal=="buy" && OrdersTotal()==0)
   OrderSend (_Symbol,OP_BUY,0.01,Ask,3,0,Ask+150*_Point,NULL,0,0,Green);
   
    if (signal=="sell" && OrdersTotal()==0)
   OrderSend (_Symbol,OP_BUY,0.01,Ask,3,0,Ask+150*_Point,NULL,0,0,Red);
   
   Comment ("The current signal is: ", signal);
   

   }


I get an error while running these codes. Where am I wrong?


 
mcaesart:
input int SmallSMA = 5;
input int BigSMA = 21;

void OnTick()
   {
   
   string signal = "";
   
   
   double SmallMovingAverage1 = iMA (_Symbol, _Period, SmallSMA, MODE_EMA, PRICE_CLOSE,1,0);
   
   double BigMovingAverage1 = iMA  (_Symbol, _Period, BigSMA, MODE_EMA, PRICE_CLOSE,1,0);
   

I get an error while running these codes. Where am I wrong?


https://www.mql5.com/en/docs/indicators/ima

int  iMA(
   string               symbol,            // symbol name
   ENUM_TIMEFRAMES      period,            // period
   int                  ma_period,         // averaging period
   int                  ma_shift,          // horizontal shift
   ENUM_MA_METHOD       ma_method,         // smoothing type
   ENUM_APPLIED_PRICE   applied_price      // type of price or handle
   );

Answer has been given above by William.

Check your parameters.

Documentation on MQL5: Technical Indicators / iMA
Documentation on MQL5: Technical Indicators / iMA
  • www.mql5.com
//|                                                     Demo_iMA.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | "The method of creation of the handle is set through the 'type' parameter (function type...
 
mcaesart: Where am I wrong?
  1. Not using SRC. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  3. Not specifying what error.

  4. Check your return codes for errors, and report them including GLE/LE, your variable values, and the market. That way we would know that at least you are calling your code.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  5.   if (BigMovingAverage1 > SmallMovingAverage1) if(BigMovingAverage2 < SmallMovingAverage2){
          signal="sell";
       }
      if (BigMovingAverage1 < SmallMovingAverage1) if (BigMovingAverage2 > SmallMovingAverage2){
          signal="sell";
       } 
    Obvious.

  6. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
 

Hi all I am having a similar problem with the following, I am trying to call the spread

double spread = SymbolInfoDouble(_Symbol, SYMBOL_SPREAD);