Download MetaTrader 5
To add comments, please log in or register
Do you need private account monitoring? The Signals will provide you one!
slavename
64
slavename 2014.06.30 21:50 

Learning MQL4 and trying to make a simple EMA calculator that will place a line on the chart (using OBJ_HLINE since I don't know how to do a continuous line like in the default indicator).  Everything seems fine, but I can't get the line to draw.  I've been through so many sets of code, trying to see what I'm doing wrong, and know it's something small, but I'm at a loss.  Here's what I have:

[code]

void movingAvg()

   {  

      const string h4ShortE;

      //H4 EMAS CALCULATIONS

      double h4Short = iMA(NULL,0,150,0,MODE_EMA,PRICE_CLOSE,0);

      double h4Long = iMA(NULL,0,365,0,MODE_EMA,PRICE_CLOSE,0);

      //D1 EMAS CALCULATIONS

      double d1Short = iMA(NULL,0,150,0,MODE_EMA,PRICE_CLOSE,0);

      double d1Long = iMA(NULL,0,365,0,MODE_EMA,PRICE_CLOSE,0);

      

      ObjectCreate(ChartID(),h4ShortE,OBJ_HLINE,0,0, h4Short);

      ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_COLOR,clrRed);

      ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_STYLE,STYLE_SOLID);

      ObjectSetInteger(ChartID(),h4ShortE,OBJPROP_WIDTH,1);

   } 

[/code] 

Ian Venner
2583
Ian Venner 2014.06.30 22:07  

That's because you didn't give it a name

const string h4ShortE = ?
slavename
64
slavename 2014.06.30 22:27  
SDC:

That's because you didn't give it a name


Wow, thanks!  I wouldn't have guessed that one.
qjol
3243
qjol 2014.06.30 22:47  
alyehoud:

Wow, thanks!  I wouldn't have guessed that one.

why not ?

  if (!ObjectCreate(ChartID(),h4ShortE,OBJ_HLINE,0,0, h4Short))
      Alert(GetLastError());


the last error is 4204 =

4204

ERR_NO_OBJECT_NAME

No object name


is that so hard ?
Ian Venner
2583
Ian Venner 2014.07.01 00:00  
Also be aware, if you create more than one object each one requires a unique name.
whroeder1
13607
whroeder1 2014.07.01 12:10  
alyehoud: Wow, thanks!  I wouldn't have guessed that one.
You would have, had you bothered to check. What are Function return values ? How do I use them ? - MQL4 forum
/
To add comments, please log in or register