Download MetaTrader 5

How to change color of label based on different time frames

To add comments, please log in or register
lifz
25
lifz  

I have 4 labels (just a squares in wingdings) that represent the 1, 5, 15, and 60 minute time frames. I want those to change between green/red when the corresponding time frame's EMAs (doesn't matter which ones) cross up/down. I made a per-bar arrow indicator for crosses before but I'm not sure how to go about setting the color on static labels.

Here is an idea of what I'm trying to do (it does nothing yet, I just have the labels placed)

EMA Cross Indicator

Marco vd Heijden
Moderator
6138
Marco vd Heijden  
if(Period()==PERIOD_H1)
 {
  // color is this
 }

if(Period()==PERIOD_D1)
 {
  // color is that
 }

etc..
lifz
25
lifz  

Thank you but I want all 4 of those boxes (in the picture I showed) on the screen at all times, no matter what time frame I'm viewing. I want them to change color if an EMA cross (let's say 3 and 9) happens on any of those time frames on each one's bar close. For example, if you're viewing the 4H time frame, and EMA3 crosses EMA9 up on the 1M time frame, I want the "1" box to change to green and all the other 3 to stay red (unless a cross up happens on those as well). I hope this makes sense.

Marco vd Heijden
Moderator
6138
Marco vd Heijden  
Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Orders for the development of automated trading programs
lifz
25
lifz  
Marco vd Heijden:

https://www.mql5.com/en/job


Wow thanks for all the help...

Anyone around who is helpful and doesn't mind taking a minute to explain a couple things to a newer (only new to MQL, not programming in general) programmer?

Marco vd Heijden
Moderator
6138
Marco vd Heijden  
lifz:

Thank you but

I just did.

So apparently it can not be done in a minute.
lifz
25
lifz  
Marco vd Heijden:

I just did.

So apparently it can not be done in a minute.

"explain a couple things" - No, you didn't.

I thank you for your initial response but you can stop responding now as it's not helpful for you or me. You're purposefully trying to frustrate a newbie looking for help on help forums and wasting your time on top of it. So it's not worth it for you either. I thank you anyway mate, hopefully someone else responds who can shed light on the actual issue. In the meanntime, I've made some headway so if not, I'll hopefully get it anyway!

Marco vd Heijden
Moderator
6138
Marco vd Heijden  
lifz:

I have 4 labels (just a squares in wingdings) that represent the 1, 5, 15, and 60 minute time frames. I want those to change between green/red when the corresponding time frame's

This is what i initially read and so that is why the response.

You did not post ANY line of code and therefore we are unable to help you.

lifz:

You're purposefully trying to frustrate a newbie looking for help on help forums and wasting your time on top of it.

Actually your the one asking for help without showing the code, what do you want us to so? spoon feed you ? write it from scratch for you ?

That's not gonna take a minute, but a lifetime.

nicholishen
1547
nicholishen  
lifz:

I have 4 labels (just a squares in wingdings) that represent the 1, 5, 15, and 60 minute time frames. I want those to change between green/red when the corresponding time frame's EMAs (doesn't matter which ones) cross up/down. I made a per-bar arrow indicator for crosses before but I'm not sure how to go about setting the color on static labels.

Here is an idea of what I'm trying to do (it does nothing yet, I just have the labels placed)



You can use the standard library to make things a lot easier.

//|                                                 color change.mq4 |
//|                                                      nicholishen |
//|                                   www.reddit.com/u/nicholishenFX |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link      "www.reddit.com/u/nicholishenFX"
#property version   "1.00"
#property strict
#include <ChartObjects\ChartObjectsArrows.mqh>
#include <Arrays\ArrayObj.mqh>

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   CopyRates(Symbol(),Period(),0,100,rates);
   
   color colors[] = {clrRed,clrLime,clrPink,clrYellow};
   CArrayObj arrow_array;
   for(int i=0;i<100;i++)
   {
      string name = "Arrow_"+(string)i;
      CChartObjectArrow *arrow = new CChartObjectArrow;
      arrow.Create(0,name,0,rates[i].time,rates[i].low,(char)233);
      arrow.Anchor(ANCHOR_TOP);
      arrow_array.Add(arrow);
   }
   
   for(int i=0,j=0; i<100 && !IsStopped(); i++,j= j+1 >= ArraySize(colors) ? 0 : j+1)
   {
      for(int k=0;k<arrow_array.Total();k++)
      { 
         CChartObjectArrow *arrow = arrow_array.At(k);
         arrow.Color(colors[j]);
         arrow.Width(j);
         ChartRedraw();  
      }
      Sleep(100);
   }
}
//+------------------------------------------------------------------+


lifz
25
lifz  
Marco vd Heijden:

You did not post ANY line of code and therefore we are unable to help you.

Actually your the one asking for help without showing the code, what do you want us to so? spoon feed you ? write it from scratch for you ?

That's not gonna take a minute, but a lifetime.


To get help from you, someone needs to post code they're asking how to write? Interesting perspective.

For the benefit of those who were kind and helped or cared to go deeper than "go pay someone to do it", all it took was an EMA cross indicator and iCustom() to lookup its value. Look at that, just "a minute" for someone who knows what they're talking about! That is why I asked a forum of people who know what they're talking about. And in response to the prior gentleman's rant, I can't post the code because it's proprietary. But if anyone needs help on this in the future, let me know. I'll be glad to help you and not just post a link to a job site.

Marco vd Heijden
Moderator
6138
Marco vd Heijden  

No just the part where you made the attempt so that we can spot the error.

Isn't that usually the case? or you want to be spoonfed?

We must write it for you from scratch?

We have seen the "just a minute" time and time again.

It's just that you don't know how much time it takes to write some REAL good piece of code.

If you can't post the code we can not help you.

I am sorry.

This is not a place for proprietary code discussion.

12
To add comments, please log in or register