putting server time in an indicator

 

hello 

i am working on an indicator and everything is good so far.

the indicator shows lines on the chart continuously but what i want is that it should show the lines on a specific server time let say i want the indicator to show the lines only during 23:00 to 23:59 according to the server time
can somebody help me with that

thank you and sorry for my bad english

 
Arad016: i am working on an indicator and everything is good so far. the indicator shows lines on the chart continuously but what i want is that it should show the lines on a specific server time let say i want the indicator to show the lines only during 23:00 to 23:59 according to the server time. can somebody help me with that.
The OnCalculate() event handler for Indicators, has a time[] array parameter which you can check to see if it is within the time range you specify.
 
Fernando Carreiro:
The OnCalculate() event handler for Indicators, has a time[] array parameter which you can check to see if it is within the time range you specify.

can you please give me an example about using it ?

 
Arad016: can you please give me an example about using it ?

There is already an example in the documentation in respect to using the time[] array in the OnCalculate() event handler.

I am unable to give a more specific example without knowing exactly what you are trying to achieve. Your description is much too vague.

It will be easier for you to post your code attempt and for us to point out what you are doing wrong!

 

#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"


double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];

extern double DEM_Values = 0.3;
double myPoint; 

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")
     {
     }
  }

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);
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

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;
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   ArraySetAsSeries(Buffer5, true);
   ArraySetAsSeries(Buffer6, true);
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
      ArrayInitialize(Buffer3, 0);
      ArrayInitialize(Buffer4, 0);
      ArrayInitialize(Buffer5, 0);
      ArrayInitialize(Buffer6, 0);
     }
   else
      limit++;
   
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue;   
      if(true 
      )
        {
         Buffer1[i] = Open[i] + 10 * myPoint; 
        }
      else
        {
         Buffer1[i] = 0;
        }
      
      if(true 
      )
        {
         Buffer2[i] = Open[i] - 10 * myPoint; 
        }
      else
        {
         Buffer2[i] = 0;
        }
      if(true 
      )
        {
         Buffer3[i] = Open[i] + 20 * myPoint; //Set indicator value at Candlestick Open + fixed value
        }
      else
        {
         Buffer3[i] = 0;
        }
      if(true 
      )
        {
         Buffer4[i] = Open[i] - 20 * myPoint; 
        }
      else
        {
         Buffer4[i] = 0;
        }
      if(true 
      )
        {
         Buffer5[i] = Open[i] + 25 * myPoint; 
        }
      else
        {
         Buffer5[i] = 0;
        }
      if(true 
      )
        {
         Buffer6[i] = Open[i] - 25 * myPoint; 
        }
      else
        {
         Buffer6[i] = 0;
        }
     }
   return(rates_total);
  }

here is the code can you point me to how and where to use it 
 
Fernando Carreiro:

There is already an example in the documentation in respect to using the time[] array in the OnCalculate() event handler.

I am unable to give a more specific example without knowing exactly what you are trying to achieve. Your description is much too vague.

It will be easier for you to post your code attempt and for us to point out what you are doing wrong!

alright i have posted the code and 
what i want it for the indicator to show the line only when the server time is between 23:00 to 23:59

right now the indicator is showing these lines all the time and i want it to show only during that specific time 

 
Arad016:

alright i have posted the code and 
what i want it for the indicator to show the line only when the server time is between 23:00 to 23:59

right now the indicator is showing these lines all the time and i want it to show only during that specific time 

Arad016: here is the code can you point me to how and where to use it 

Why do you have so many "if( true )" lines. They are useless. Please refactor your code!

Plus, you are using the "Open[]"  array instead of the correct "open[]" array parameter. They are different things and you should not be mixing them up.

After that you should show where you want to limit the information in your code. Place a dummy "if" condition with the time[] parameter as your attempt so that we understand what you are trying to do!

EDIT: Also remember to set the ArraySetAsSeries for the parameters as well as a good practice. As for the buffers, you only need to do it in the OnInit() event handler. You don't need to do it over and over again in the OnCalculate().

 
Fernando Carreiro:

Why do you have so many "if( true )" lines. They are useless. Please refactor your code!

Plus, you are using the "Open[]"  array instead of the correct "open[]" array parameter. They are different things and you should not be mixing them up.

After that you should show where you want to limit the information in your code. Place a dummy "if" condition with the time[] parameter as your attempt so that we understand what you are trying to do!

hahahaah sorry about the messy code 
i am new to this so i messed everything up
here is what i am trying to do

i need the indicator to show total of 6 lines on the chart 
three of them above the candle opening and three below 


here is what the indicator is doing right now 


three lines above the candle open will be like this 
1st line should be 10 pips above the candle open 
2nd should be 20 pips above
and the third should be 25 pips above the candle open 


and the lines below the candle open are like this 


1st line should be 10 pips below the candle open 
2nd should be 20 pips below
and the third should be 25 pips below the candle open 



the problem is its showing the line on all the candles and what i want it to do is to show these line only during the 23:00 to 23:59 of the server time 

 
Arad016:

hahahaah sorry about the messy code 
i am new to this so i messed everything up
here is what i am trying to do

i need the indicator to show total of 6 lines on the chart 
three of them above the candle opening and three below 

here is what the indicator is doing right now 

three lines above the candle open will be like this 
1st line should be 10 pips above the candle open 
2nd should be 20 pips above
and the third should be 25 pips above the candle open 

and the lines below the candle open are like this 

1st line should be 10 pips below the candle open 
2nd should be 20 pips below
and the third should be 25 pips below the candle open 


the problem is its showing the line on all the candles and what i want it to do is to show these line only during the 23:00 to 23:59 of the server time 

First, refactor your code by fixing the things that I have already mentioned. There is no advantage in proceeding with the time issue until your code is properly functioning with regards to the initial functionality that you have described.
 
TimeHour - Date and Time - MQL4 Reference
TimeHour - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeHour - Date and Time - MQL4 Reference
 
Fernando Carreiro:
First, refactor your code by fixing the things that I have already mentioned. There is no advantage in proceeding with the time issue until your code is properly functioning with regards to the initial functionality that you have described.

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 

 

Reason: