Is it possbile to set a different color for all (trend)lines in the chart at once (maybe a script)? - page 2

 
mar:

Hi ubzen,

I don't wanted to open a new thread for that because we were just "talking" about objects.. I would like to color the distance between two moving averages.

For example, I use the EMA20 and the EMA50. When the EMA20 is above the EMA50 I want the space between them colored in green, other wise in red.

Do I have to do this with objects or with buffers? I have no idea what to use now. I am pretty sure that I find an indicator like this but I would like to program it myself.

Therefore I would appreciate it, if you tell me what to use. Then I know in which "direction" I have to think.

Thank you!!

You add another two buffers and draw histogram bars between the EMAs.
 
Thanks Raptor, I will try my best! :)
 

Hey Raptor, hey ubzen,

I have a new project! :)

Just a simple thing, I want to make an indicator which displays the spread. Nothing special, I already have one of them. But I saw that it is made by using an object. This seemed unnecessary to me. I tried it with a simple comment and it also works. But now I wanted to use another font and I would like to place it somewhere else in the window. Is that possible with a comment? If not, that might be the reason why other coders do it with an object..

Edit: Found an answer. It is not possible...

 
mar:

Hey Raptor, hey ubzen,

I have a new project! :)

Just a simple thing, I want to make an indicator which displays the spread. Nothing special, I already have one of them. But I saw that it is made by using an object. This seemed unnecessary to me. I tried it with a simple comment and it also works. But now I wanted to use another font and I would like to place it somewhere else in the window. Is that possible with a comment? If not, that might be the reason why other coders do it with an object..


The comment is always positioned top left of the chart, you can move it down by inserting blank lines at the start of the comment. You can't change the font, you can change the color but that also changes all other chart items of the same color (F8, Foreground) . . . use an Object, or something like my function CommentLab(): https://www.mql5.com/en/forum/138327
 
Ok, thanks! Obviously I have to learn more about Objects right now..
 

Hey guys,

I hope you don't mind if I sometimes ask you for a little help. I think you also agree that I don't open a new thread for each question.. ;)

I try to do some things with objects right now. For the beginning I just draw two horizontal lines. The high and low of the previous day.

No problem so far. But just for educational purposes I want to use an OBJ_TREND instead of a horizontal line. It should start where the high and low are and should end at the current bar.

But now my problem is that I don't know how to find out the time (and bar) where the Trendline should begin. I tried it with iTime() and iBarShift() but I don't see the logic. I have the exact high and low of the previous day by using iHigh() and iLow(). But now I am looking for a possibility to check when this high or low appeared. But I have no senseful idea. Maybe you can give me an advice?

This is my code so far using the OBJ_HLINE:

int start()
  {
//----
   double YHi = iHigh(NULL, PERIOD_D1, 1);
   ObjectCreate("YHi",OBJ_HLINE,0,0,YHi,0,0);
   double YLo = iLow(NULL, PERIOD_D1, 1);
   ObjectCreate("YLo",OBJ_HLINE,0,0,YLo,0,0);
//----
   return(0);
  }
 
mar: my problem is that I don't know how to find out the time (and bar)
How to get a time of High/Low of previous day? - MQL4 forum
 

Thanks!

 

Hello guys,

it's me again with another question.. At the weekend it seemed that I completed my indicator. Everything worked fine, all lines were correct and had the correct starting point. But I absolutely don't understand why it does not work right now when the data feed is running. Obviously there is something wrong with the "TimeHigh" and "TimeLow" but I have no idea why it worked in the offline-mode and not now anymore.

Another thing is that I print the Trendline until TimeCurrent() but the line doesn't stop at the current bar. Instead the line is expanding to the very right of my chart. Is there another expression for the second time when it should stop at the current bar?

Thanks guys. Every help is welcome. I hope my questions doesn't bother you too much.

//+------------------------------------------------------------------+
//|                                                   DailyLines.mq4 |
//|                                               Copyright 2013, MR |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MR"
#property link      ""
extern int Days = 2;
extern bool DrawZones = false;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int iObj = ObjectsTotal() - 1; iObj >= 0; iObj--)
   {
      string name = ObjectName(iObj);
      ObjectDelete(name);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   for (int i = Days-1; i>=0; i--)
   {
      double YHi = iHigh(NULL, PERIOD_D1, i);                                                               // last days high
      double YLo = iLow(NULL, PERIOD_D1, i);                                                                // last days low
      datetime Midnight = TimeCurrent() - i*(TimeCurrent()%(PERIOD_D1 * 60));                               // last midnight
      datetime Midnight2 = Midnight - (24 * PERIOD_H1 * 60);                                                // midnight before last midnight
      int BarsToMidnight = iBarShift(NULL, 0, Midnight);                                                    // bars to last midnight
      int BarsToMidnight2 = iBarShift(NULL, 0, Midnight2);                                                  // bars to the midnight before
      
      int BarsToHigh = iHighest(NULL, 0, MODE_HIGH, BarsToMidnight2-BarsToMidnight, BarsToMidnight);        // bars to the high
      int BarsToHighOpen = iHighest(NULL, 0, MODE_OPEN, BarsToMidnight2-BarsToMidnight, BarsToMidnight);    // bars to the highest open
      int BarsToHighClose = iHighest(NULL, 0, MODE_CLOSE, BarsToMidnight2-BarsToMidnight, BarsToMidnight);  // bars to the highest close 
      double BodyHigh = MathMax(Open[BarsToHighOpen], Close[BarsToHighClose]);                              // highest high of the candle body
      
      int BarsToLow = iLowest(NULL, 0, MODE_LOW, BarsToMidnight2-BarsToMidnight, BarsToMidnight);           // bars to the low 
      int BarsToLowOpen = iLowest(NULL, 0, MODE_OPEN, BarsToMidnight2-BarsToMidnight, BarsToMidnight);      // bars to the lowest open
      int BarsToLowClose = iLowest(NULL, 0, MODE_CLOSE, BarsToMidnight2-BarsToMidnight, BarsToMidnight);    // bars to the lowest close
      double BodyLow = MathMin(Open[BarsToLowOpen], Close[BarsToLowClose]);                                 // lowest low of the candle body
      
      datetime TimeHigh = iTime(NULL, 0, BarsToHigh);
      datetime TimeLow = iTime(NULL, 0, BarsToLow);
      if (DrawZones)
      {
         ObjectCreate("YHi"+i, OBJ_RECTANGLE, 0, TimeHigh, YHi, TimeCurrent(),BodyHigh);
         ObjectCreate("YLo"+i, OBJ_RECTANGLE, 0, TimeLow, YLo, TimeCurrent(),BodyLow);   
      }
      else
      {
         ObjectCreate("YHi"+i, OBJ_TREND, 0, TimeHigh, YHi, TimeCurrent(), YHi);
         ObjectCreate("YLo"+i, OBJ_TREND, 0, TimeLow, YLo, TimeCurrent(), YLo);
      }

   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
mar:


Another thing is that I print the Trendline until TimeCurrent() but the line doesn't stop at the current bar. Instead the line is expanding to the very right of my chart. Is there another expression for the second time when it should stop at the current bar?

ObjectSet(name, OBJPROP_RAY, false) to disable Ray of the trend lines.

Also, your code will create lots of errors, you can't create an Object when that Object already exists . . . you are trying to create the objects on each tick . . .

Reason: