(MQL4) Two Horizontal Lines - how to draw

 

I would like to draw automatically two horizontal lines everyday on 00:30 and on 14:45.

After the end of day two horizontal lines should be deleted and draw new lines on new day at above times.

Has anybody any idea, how to do it?

 
Just draw 2 Horizontal lines . . . . ObjectCreate() type OBJ_HLINE you just need one price coordinate. When the time is at the end of the day (by your definition) just move the lines to the new positions . . . use ObjectSet() with OBJPROP_PRICE1
 
You can use HLINE and move them each day or create a new horizontal TLINE one day long. (from my code)
    #define T0030  1800 //            30  * 60
    #define T1445 53100 // (14 * 60 + 45) * 60
    #define T2400 86400 //  24 * 60       * 60
    datetime    now = Time[0],
                tod = now % T2400;
    if (tod == T0300 ){
        // HLine("open-0300", Open[0]);
        TLine("open-"+TimeToStr(now, TIME_MINUTES), now,        Open[0], 
                                                    now+T2400,  Open[0]);
    }
:
void TLine( string name, datetime T0, double P0, datetime T1, double P1,
            color clr, bool ray=false){
    if (!Show.Objects)  return;                 #define WINDOW_MAIN 0
    if      (ObjectMove( name, 0, T0, P0 ))     ObjectMove(name, 1, T1, P1);
    else if (!ObjectCreate( name, OBJ_TREND, WINDOW_MAIN, T0, P0, T1, P1 ))
        Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() );
    else if (!ObjectSet( name, OBJPROP_RAY, ray ))
        Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError());
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [4] failed: ", GetLastError());
    string  P0t = PriceToStr(P0);           if (MathAbs(P0 - P1) >= Point)
            P0t = StringConcatenate(P0t, " to ", PriceToStr(P1));       }
    if (!ObjectSetText(name, P0t, 10))
        Alert("ObjectSetText(",name,") [2] failed: ", GetLastError());
}
void HLine(string name, double P0, color clr){  //      #define WINDOW_MAIN 0
    if (!Show.Objects)  return;
    if      (ObjectMove( name, 0, Time[0], P0 )){}
    else if (!ObjectCreate( name, OBJ_HLINE, WINDOW_MAIN, Time[0], P0 ))
        Alert("ObjectCreate(",name,",HLINE) failed: ", GetLastError() );
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() );
    if (!ObjectSetText(name, PriceToStr(P0), 10))
        Alert("ObjectSetText(",name,") [3] failed: ", GetLastError());
}
string  PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }
 

This EA draws horizontal lines at the price levels at 00:30 and on 14:45 and deletes them when daily bar is closed.

//+------------------------------------------------------------------+
//|                                                    DrawLines.mq4 |
//|                                     Copyright © 2012,CyberFX.org |
//|                                           http://www.cyberfx.org |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, CyberFX.org"
#property link      "http://www.cyberfx.org"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(TimeCurrent() >= StrToTime("00:30") && ObjectFind("Line1")<0 )
   {
      ObjectCreate("Line1",OBJ_HLINE,0,StrToTime("00:30"),iOpen(NULL,PERIOD_M1,iBarShift(NULL,0,StrToTime("00:30"),true)));
      ObjectSet("Line1",OBJPROP_COLOR,Yellow);
   }
   
   if(TimeCurrent() >= StrToTime("14:45") && ObjectFind("Line2")<0 )
   {
      ObjectCreate("Line2",OBJ_HLINE,0,StrToTime("14:45"),iOpen(NULL,PERIOD_M1,iBarShift(NULL,0,StrToTime("14:45"),true)));
      ObjectSet("Line2",OBJPROP_COLOR,Orange);
   }
   
   if(ObjectGet("Line1",OBJPROP_TIME1) < iTime(NULL,PERIOD_D1,0)) ObjectDelete("Line1");
   if(ObjectGet("Line2",OBJPROP_TIME1) < iTime(NULL,PERIOD_D1,0)) ObjectDelete("Line2");
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
cyberfx.org:

This EA draws horizontal lines at the price levels at 00:30 and on 14:45 and deletes them when daily bar is closed.


Thank you - I will check it soon.

 
WHRoeder:
You can use HLINE and move them each day or create a new horizontal TLINE one day long. (from my code)


Thank you - I will check it soon.
 
RaptorUK:
Just draw 2 Horizontal lines . . . . ObjectCreate() type OBJ_HLINE you just need one price coordinate. When the time is at the end of the day (by your definition) just move the lines to the new positions . . . use ObjectSet() with OBJPROP_PRICE1

Ok, thx.