Whats wrong with this

To add comments, please log in or register
pete42
45
pete42  

Hi,


I am trying to put together a simple EA to give me the price in relation to the EMAs on multiple timeframes.

I dont seem to get the color right. it is always coming out as clrBlack

//// Start function

double   ema5m1, ema5m5, ema5m15, ema5m30,
         ema8m1, ema8m5, ema8m15, ema8m30;
         
color   stm1, stm5, stm15, stm30;

void OnDeinit(const int reason)
  {
//---
   ObjectDelete(0, "M1"); ObjectDelete(0, "M5"); ObjectDelete(0, "M15"); ObjectDelete(0, "M30");
  }

int start()
        {
        //Variables

   ema5m1  = iMA(NULL, PERIOD_M1, 5, 0, MODE_EMA, 0, 0);
   ema5m5  = iMA(NULL, PERIOD_M5, 5, 0, MODE_EMA, 0, 0);
   ema5m15 = iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, 0, 0);
   ema5m30 = iMA(NULL, PERIOD_M30, 5, 0, MODE_EMA, 0, 0);
   
   ema8m1  = iMA(NULL, PERIOD_M1, 5, 0, MODE_EMA, 0, 0);
   ema8m5  = iMA(NULL, PERIOD_M5, 5, 0, MODE_EMA, 0, 0);
   ema8m15 = iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, 0, 0);
   ema8m30 = iMA(NULL, PERIOD_M30, 5, 0, MODE_EMA, 0, 0);
   
 //-- Downtrend
   //-- Red M1
   if (ema5m1<ema8m1 && Close[0]<ema5m1)
        stm1 = Red;
   //-- Red M5
   if (ema5m5<ema8m5 && Close[0]<ema5m5)
        stm5 = Red;
   //-- Red M15
   if (ema5m15<ema8m15 && Close[0]<ema5m15)
        stm15 = Red;
   //-- Red M30
   if (ema5m30<ema8m30 && Close[0]<ema5m30)
        stm30 = Red;

//-- UPTREND
   //-- Green M1
   if (ema5m1>ema8m1 && Close[0]>ema5m1)
        stm1 = Green;
   //-- Green M5
   if (ema5m5>ema8m5 && Close[0]>ema5m5)
        stm5 = Green;
   //-- Green M15
   if (ema5m15>ema8m15 && Close[0]>ema5m15)
        stm15 = Green;
   //-- Green M30
   if (ema5m30>ema8m30 && Close[0]>ema5m30)
        stm30 = Green;
      
      
//-- Square M1
   ObjectCreate("M1", OBJ_RECTANGLE_LABEL, 0, 0, 0);
   ObjectSet   ("M1", OBJPROP_XSIZE, 30);
   ObjectSet   ("M1", OBJPROP_YSIZE, 10);
   ObjectSet   ("M1", OBJPROP_BGCOLOR, stm1);
   ObjectSet   ("M1", OBJPROP_XDISTANCE, 10);
   ObjectSet   ("M1", OBJPROP_YDISTANCE, 20);
//-- Square M5
   ObjectCreate("M5", OBJ_RECTANGLE_LABEL, 0, 0, 0);
   ObjectSet   ("M5", OBJPROP_XSIZE, 30);
   ObjectSet   ("M5", OBJPROP_YSIZE, 10);
   ObjectSet   ("M5", OBJPROP_BGCOLOR, stm5);
   ObjectSet   ("M5", OBJPROP_XDISTANCE, 60);
   ObjectSet   ("M5", OBJPROP_YDISTANCE, 20);
//-- Strenght Square M15
   ObjectCreate("M15", OBJ_RECTANGLE_LABEL, 0, 0, 0);
   ObjectSet   ("M15", OBJPROP_XSIZE, 30);
   ObjectSet   ("M15", OBJPROP_YSIZE, 10);
   ObjectSet   ("M15", OBJPROP_BGCOLOR, stm15);
   ObjectSet   ("M15", OBJPROP_XDISTANCE, 110);
   ObjectSet   ("M15", OBJPROP_YDISTANCE, 20);
//-- Square M30
   ObjectCreate("M30", OBJ_RECTANGLE_LABEL, 0, 0, 0);
   ObjectSet   ("M30", OBJPROP_XSIZE, 30);
   ObjectSet   ("M30", OBJPROP_YSIZE, 10);
   ObjectSet   ("M30", OBJPROP_BGCOLOR, stm30);
   ObjectSet   ("M30", OBJPROP_XDISTANCE, 160);
   ObjectSet   ("M30", OBJPROP_YDISTANCE, 20);

 return(0);
 }

Can someone help me on this please.


Cheers!

 - pete

Fernando Morales
536
Fernando Morales  
pete42:

Hi,


I am trying to put together a simple EA to give me the price in relation to the EMAs on multiple timeframes.

I dont seem to get the color right. it is always coming out as clrBlack

Can someone help me on this please.


Cheers!

 - pete

Color names start with clr


https://www.mql5.com/en/docs/constants/objectconstants/webcolors

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Web Colors
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Web Colors
  • www.mql5.com
Constants, Enumerations and Structures / Objects Constants / Web Colors - Reference on algorithmic/automated trading language for MetaTrader 5
Arash Lakzadeh
2076
Arash Lakzadeh  
pete42:

Hi,


I am trying to put together a simple EA to give me the price in relation to the EMAs on multiple timeframes.

I dont seem to get the color right. it is always coming out as clrBlack

Can someone help me on this please.


Cheers!

 - pete

Dear,

Your code is correct.

You have a little mistake. Change to 8 EMA Period:

   ema5m1  = iMA(NULL, PERIOD_M1, 5, 0, MODE_EMA, 0, 0);
   ema5m5  = iMA(NULL, PERIOD_M5, 5, 0, MODE_EMA, 0, 0);
   ema5m15 = iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, 0, 0);
   ema5m30 = iMA(NULL, PERIOD_M30, 5, 0, MODE_EMA, 0, 0);
   
   ema8m1  = iMA(NULL, PERIOD_M1, 8, 0, MODE_EMA, 0, 0);
   ema8m5  = iMA(NULL, PERIOD_M5, 8, 0, MODE_EMA, 0, 0);
   ema8m15 = iMA(NULL, PERIOD_M15, 8, 0, MODE_EMA, 0, 0);
   ema8m30 = iMA(NULL, PERIOD_M30, 8, 0, MODE_EMA, 0, 0);

Arash

pete42
45
pete42  

Copy Paste... Silly me!

Thanks a lot!

whroeder1
17987
whroeder1  
On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing prices.
          Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
To add comments, please log in or register