plot vertical and horizontal line

 
//+------------------------------------------------------------------+
//|                                                    ErlyBird6.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"



int    Sommerzeit     =   87;  // DayOfYear Beginn Sommerzeit
int    Winterzeit     =  297;  // DayOfYear Beginn Winterzeit
int  TimeSelect;

double hg[]={0},lw[]={0};

double High[],  Low[];

MqlRates rates[];
MqlDateTime Time;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


int OnInit()
  {

 //if(data.day_of_year>=Sommerzeit && data.day_of_year<=Winterzeit) TimeSelect=11; else TimeSelect=10;       

   return(0);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    ArraySetAsSeries(rates,true);
   
  int copied=CopyRates(_Symbol,0,0,100,rates);


if(copied>0)
  {
    
     TimeToStruct (rates[0].time, Time);
     if(  Time.day_of_year>=Sommerzeit &&   Time.day_of_year<=Winterzeit) TimeSelect=11; else TimeSelect=10;  
     
     if(  Time.hour==TimeSelect &&  Time.min==0)  //draw vertical line at TimeSelect
          {
            ObjectCreate(0,"VerticalStart",OBJ_VLINE,0,rates[0].time,0); 
            ObjectSetInteger(0,"VerticalStart",OBJPROP_COLOR,clrRed);
                        
          }
      
    
         if(  Time.hour==TimeSelect+5 &&  Time.min==0)   //draw vertical line at TimeSelect+5
           {
            ObjectCreate(0,"VerticalEnd",OBJ_VLINE,0,rates[0].time,0);
            ObjectSetInteger(0,"VerticalEnd",OBJPROP_COLOR,clrDarkViolet);
       
             CopyHigh(_Symbol,0,rates[0].time,5,hg);
             CopyLow(_Symbol,0,rates[0].time,5,lw);
       
             
           double   Top = rates[ArrayMaximum(hg,0,WHOLE_ARRAY)].high;  
           double   Bottom = rates[ ArrayMinimum(lw,0,WHOLE_ARRAY)].low;


           // draw horizontal line at the top of  5 last  candles 
         
          ObjectCreate(0,"HorizontalTop",OBJ_HLINE,0,rates[ArrayMaximum(hg,0,WHOLE_ARRAY)].time,Top);
          ObjectSetInteger(0,"HorizontalTop",OBJPROP_COLOR,clrGreenYellow);
         
          // draw horizontal line at the bottom of  5 last  candles 
        
         ObjectCreate(0,"HorizontalBottom",OBJ_HLINE,0,rates[ArrayMinimum(lw,0,WHOLE_ARRAY)].time,Bottom);
         ObjectSetInteger(0,"HorizontalBottom",OBJPROP_COLOR,clrCrimson);

         
           }

   
        
       }
    
   
    }
   
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//+------------------------------------------------------------------+
 

i want  to plot vertical lines  at  timeSelsect (10 or 11h ) and timeSelcet+5 but it draws only one time why?

thank you 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Documentation on MQL5
 
dan5:

<CODE REMOVED>

Please edit your post . . . 

 

Use SRC 

 
dan5:

i want  to plot vertical lines  at  timeSelsect (10 or 11h ) and timeSelcet+5 but it draws only one time why?

thank you 

Why don't you right click the chart and select Object List and then select click "List All" button. You will see there that you probably already have 2 vertical lines of Red "VerticalStart" and Dark Violet "VerticalEnd".

The problem that the second vertical line is not displayed is because it was created on same time-coordinate like the first vertical line and you have to wait for 5 hours to get this second vertical line displayed.

EDIT : The code is correct . 

if(Time.hour==TimeSelect &&  Time.min==0)  //draw vertical line at TimeSelect
  {
  ObjectCreate(0,"VerticalStart",OBJ_VLINE,0,rates[0].time,0); 
  ObjectSetInteger(0,"VerticalStart",OBJPROP_COLOR,clrRed);
  }

  if(Time.hour==TimeSelect+5 &&  Time.min==0)   //draw vertical line at TimeSelect+5
    {
    ObjectCreate(0,"VerticalEnd",OBJ_VLINE,0,rates[0].time,0);
    ObjectSetInteger(0,"VerticalEnd",OBJPROP_COLOR,clrDarkViolet);
 
phi.nuts:

Why don't you right click the chart and select Object List and then select click "List All" button. You will see there that you probably already have 2 vertical lines of Red "VerticalStart" and Dark Violet "VerticalEnd".

The problem that the second vertical line is not displayed is because it was created on same time-coordinate like the first vertical line and you have to wait for 5 hours to get this second vertical line displayed.

 

thank you for your reply

Pardon my english but the problem is not to draws lines  at time and time+5 but my problem is to draws lines at time and time+5  EVRY DAYS .

tester  draws line only one time but  i want to draw lines the 1 may ,2 may ,3 may .... at time and time+5

  thank you for your help 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles - Documentation on MQL5
 

dan5:

thank you for your reply

Pardon my english but the problem is not to draws lines  at time and time+5 but my problem is to draws lines at time and time+5  EVRY DAYS .

tester  draws line only one time but  i want to draw lines the 1 may ,2 may ,3 may .... at time and time+5

 thank you for your help 


 Yesterday, because of your indenting style, I had problem reading your code, Today I re-read your code and your code is correct in using rates[0].time.


If you want to draw several objects, then you have to name the objects differently 

string name;

name = "VerticalStart" + TimeToString (rates[0].time, TIME_DATE|TIME_SECOND);

ObjectCreate(0,name,OBJ_VLINE,0,rates[0].time,0); 
Indent style - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Indentation is not a requirement of most programming languages, where it is used as secondary notation. Rather, programmers indent to better convey the structure of their programs to human readers. In particular, indentation is used to show the relationship between control flow constructs such as conditions or loops and code contained within...
 
phi.nuts:

 Yesterday, because of your indenting style, I had problem reading your code, Today I re-read your code and your code is correct in using rates[0].time.


If you want to draw several objects, then you have to name the objects differently 

thank you very much for your help my code draws horizontal and vertical line at time .
int OnInit()
  {

 //if(data.day_of_year>=Sommerzeit && data.day_of_year<=Winterzeit) TimeSelect=11; else TimeSelect=10;       

   return(0);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    ArraySetAsSeries(rates,true);
   
  int copied=CopyRates(_Symbol,0,0,100,rates);


if(copied>0)
  {
    
     TimeToStruct (rates[0].time, Time);
     if(  Time.day_of_year>=Sommerzeit &&   Time.day_of_year<=Winterzeit) TimeSelect=11; else TimeSelect=10;  
     
     if(  Time.hour==TimeSelect &&  Time.min==0)  //draw vertical line at TimeSelect
          {
            ObjectDelete(0,oldnameVstart);  
            name = "VerticalStart" + TimeToString (rates[0].time, TIME_DATE|TIME_SECONDS);
            ObjectCreate(0,name,OBJ_VLINE,0,rates[0].time,0); 
            ObjectSetInteger(0,name,OBJPROP_COLOR,clrRed);
            oldnameVstart= name;       
          }
      
    
         if(  Time.hour==TimeSelect+5 &&  Time.min==0)   //draw vertical line at TimeSelect+5
           {
            
            ObjectDelete(0,oldnameVstop);      
            name = "VerticalEnd" + TimeToString (rates[0].time, TIME_DATE|TIME_SECONDS);
            ObjectCreate(0, name,OBJ_VLINE,0,rates[0].time,0);
            ObjectSetInteger(0, name,OBJPROP_COLOR,clrDarkViolet);
            oldnameVstop= name;   
            
            ArraySetAsSeries(hg,true);
            ArraySetAsSeries(lw,true);
           
            CopyHigh(_Symbol,_Period,TimeCurrent(),5,hg);
            CopyLow(_Symbol,_Period,TimeCurrent(),5,lw);
       
             
           double   Top = rates[ArrayMaximum(hg,0,WHOLE_ARRAY)].high;  
           double   Bottom = rates[ ArrayMinimum(lw,0,WHOLE_ARRAY)].low;
          
           
            // draw horizontal line at the top of  5 last  candles 
            ObjectDelete(0, oldnameHTop);
            name = "HorizontalTop" + TimeToString (rates[0].time, TIME_DATE|TIME_SECONDS);
        
            ObjectCreate(0,name,OBJ_HLINE,0,rates[0].time,Top);
            ObjectSetInteger(0,name ,OBJPROP_COLOR,clrGreenYellow);
            oldnameHTop= name;
         
         
            // draw horizontal line at the bottom of  5 last  candles 
            ObjectDelete(0,oldnameHBottom);
            name = "HorizontalBottom" + TimeToString (rates[0].time, TIME_DATE|TIME_SECONDS);
        
            ObjectCreate(0,name,OBJ_HLINE,0,rates[0].time,Bottom);
            ObjectSetInteger(0,name ,OBJPROP_COLOR,clrCrimson);
            oldnameHBottom= name;
 
           }

   
        
       }
    
   
    }
Reason: