Vertical lines

To add comments, please log in or register
redahussien
38
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.
whroeder1
17942
whroeder1  
  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.

nicholi shen
1895
nicholi shen  
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);
}
mrluck012
261
mrluck012  

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

redahussien
38
redahussien  

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.

whroeder1
17942
whroeder1  
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.

redahussien
38
redahussien  

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


please check the attached.

Files:
redahussien
38
redahussien  
mrluck012:

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


exactly mrluck012 , I use it to apply some of Michael Jenkins theories.
To add comments, please log in or register