putting server time in an indicator - page 2

 
Marco vd Heijden:
Please see: https://docs.mql4.com/dateandtime/timehour
thank you marco
 
Arad016: its functioning as intended as you can see there are total of 6 lines , 3 above and 3 below the candle 

the only problem remaining now is the time issue 

Just because it seems like it is working correctly does not mean that it is properly coded in order to build on more functionality on top of it. Show some pride in your work and first correct the issues identified.
 
Fernando Carreiro:
Just because it seems like it is working correctly does not mean that it is properly coded in order to build on more functionality on top of it. Show some pride in your work and first correct the issues identified.

yes you are right about that 
i was planning to correct it after the time issue is resolved 
because once every thing is working then i can focus on formatting the code correctly 

anyways here is the recent copy of the code along with the comments


//+------------------------------------------------------------------+
//|                                                 Indicator: a.mq4 |
//|                                          Created by Arad Sanders |
//+------------------------------------------------------------------+
#property copyright "Created by Arad Sanders"
#property version   "1.00"
#property description "open for modifications"

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 6

#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"

#property indicator_type3 DRAW_LINE
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
#property indicator_color3 0x00FF0D
#property indicator_label3 "Buy"

#property indicator_type4 DRAW_LINE
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
#property indicator_color4 0xD900FF
#property indicator_label4 "Sell"

#property indicator_type5 DRAW_LINE
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
#property indicator_color5 0x00F2FF
#property indicator_label5 "Buy"

#property indicator_type6 DRAW_LINE
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
#property indicator_color6 0xFF00A6
#property indicator_label6 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];

extern double DEM_Values = 0.3;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | a @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(6);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexBuffer(2, Buffer3);
   SetIndexEmptyValue(2, 0);
   SetIndexBuffer(3, Buffer4);
   SetIndexEmptyValue(3, 0);
   SetIndexBuffer(4, Buffer5);
   SetIndexEmptyValue(4, 0);
   SetIndexBuffer(5, Buffer6);
   SetIndexEmptyValue(5, 0);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   ArraySetAsSeries(Buffer5, true);
   ArraySetAsSeries(Buffer6, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
      ArrayInitialize(Buffer3, 0);
      ArrayInitialize(Buffer4, 0);
      ArrayInitialize(Buffer5, 0);
      ArrayInitialize(Buffer6, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(true //no conditions!
      )
        {
         Buffer1[i] = Open[i] + 10 * myPoint; //Set indicator value at Candlestick Open + fixed value
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(true //no conditions!
      )
        {
         Buffer2[i] = Open[i] - 10 * myPoint; //Set indicator value at Candlestick Open - fixed value
        }
      else
        {
         Buffer2[i] = 0;
        }
      //Indicator Buffer 3
      if(true //no conditions!
      )
        {
         Buffer3[i] = Open[i] + 20 * myPoint; //Set indicator value at Candlestick Open + fixed value
        }
      else
        {
         Buffer3[i] = 0;
        }
      //Indicator Buffer 4
      if(true //no conditions!
      )
        {
         Buffer4[i] = Open[i] - 20 * myPoint; //Set indicator value at Candlestick Open - fixed value
        }
      else
        {
         Buffer4[i] = 0;
        }
      //Indicator Buffer 5
      if(true //no conditions!
      )
        {
         Buffer5[i] = Open[i] + 25 * myPoint; //Set indicator value at Candlestick Open + fixed value
        }
      else
        {
         Buffer5[i] = 0;
        }
      //Indicator Buffer 6
      if(true //no conditions!
      )
        {
         Buffer6[i] = Open[i] - 25 * myPoint; //Set indicator value at Candlestick Open - fixed value
        }
      else
        {
         Buffer6[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+


 

 
Arad016:

yes you are right about that 
i was planning to correct it after the time issue is resolved 
because once every thing is working then i can focus on formatting the code correctly 

anyways here is the recent copy of the code along with the comments

You have not changed anything in your code and you have not corrected any of the points that I mentioned. Well, if you are not willing to put in the effort, then I am not going to bother explaining my answer. I will just provide a quick answer and leave it up to you to figure it out.

// Code is untested and serves only as an example

int OpenHour = ( time[ i ] / 3600 ) % 24;

if( ( OpenHour >= StartHour ) && ( OpenHour < StopHour ) )
{
   // Do something ...
}
Reason: