Vertical lines

 
Hi .
Please could any body help me out in writing mql4 code , starting from x date 
(ie 2017.09.08 00.00) i want to draw vertical lines every x period of hours excluding saturday and sunday ,this should go to the future also. 
It would be highly appreciated , im using mt4.
Thx in advance.
 
  1. Why did you post your MT4 question in the Root / MT5 Systems section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. You have only four choices: We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
              No free help
              urgent help.

 
redahussien:
Hi .
Please could any body help me out in writing mql4 code , starting from x date 
(ie 2017.09.08 00.00) i want to draw vertical lines every x period of hours excluding saturday and sunday ,this should go to the future also. 
It would be highly appreciated , im using mt4.
Thx in advance.

//+------------------------------------------------------------------+
//|                                              DrawLinesNhours.mq4 |
//|                                      Copyright 2017, nicholishen |
//|                         https://www.forexfactory.com/nicholishen |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, nicholishen"
#property link      "https://www.forexfactory.com/nicholishen"
#property version   "1.00"
#property strict
#property indicator_chart_window
#include <ChartObjects\ChartObjectsLines.mqh>
#include <Arrays\List.mqh>

//--- input parameters
input string   StartTime="2017.11.01 00:00";
input int      Hours=3;//Number of hours to increment

CList line_list;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   datetime line_time=StringToTime(StartTime);
   
   while(line_time <= TimeCurrent() &&!IsStopped())
   {
      string name = "__time_line__"+TimeToStr(line_time);
      if(ObjectFind(0,name)<0)
      {
         CChartObjectVLine *line = new CChartObjectVLine;
         line.Create(0,name,0,line_time);
         line_list.Add(line);
      }
      AddTime(line_time,Hours);
      int day = TimeDayOfWeek(line_time);
      while(!IsStopped() && (day < 1 || day > 5))
      {
         AddTime(line_time);
         day=TimeDayOfWeek(line_time);
      }
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

void AddTime(datetime &value,int hours=1)
{
   value+=(PeriodSeconds(PERIOD_H1) * hours);
}
 

great, thanks for sharing the code, this indicator is very useful

 

Many thanks to you nicholishen , really appreciated man.

but how I could make this few days into the future also as I mentioned in the main post.

 
redahussien: but how I could make this few days into the future also as I mentioned in the main post.

That can't be done reliably, market weekends, market holidays (broker dependent,) broker timezones (small Sunday bar or not,) trading hours (broker dependent,) etc.

 

also I notice that it will not give you accurate spacing in the beginning of period.


please check the attached.

Files:
 
mrluck012:

great, thanks for sharing the code, this indicator is very useful


exactly mrluck012 , I use it to apply some of Michael Jenkins theories.