Help requested with the "inTimeInterval"function

 

Good afternoon everyone, With the help of EA-Builder I created the code below and afterwords I adjusted the code to my preferences. I'm possibly the newest of newbies to mql4. It's an indicator that places a symbol on the chart when volume exeeds the set value in the specified period, I'm using it for gold en CFD's. Currently the indicator uses the function "inTimeInterval". I learn from the documentation that this function can only be used on a global scope. I understand that this means it effects the entire indicator. The indicator worls fine, but to cover the whole of a day I need to place it several times on one chart for a single time frame. Is there a way to change the code on a local scope so I can have 4 periods each with it's own set volume value ? (as you can see I have been preparing that)

The code is three comments below.

 

Thanks in advance,

 

 

Robert 

 

I doubt that anyone will try to understand what you are doing. The post is a total mess.

Use the SRC button to post code and arrange the code in sensible lines and blocks.

This forum is mostly coders helping coders, you will not find many willing to help you correct the awful code created by EA builders.

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

    • We hate EA builder
    • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
    • EA builder makes bad code Not adjusting for 4/5 digit brokers
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
    • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)
 

Firstly, sorry for the mess of code, it appeared Java script was not activated, so the buttons to paste the code correctly where not visible.

 

Secondly, as you can see in my text I'm not asking anyone to do the job for me, I'm simply  asking if there is a function that I can use on the local scope. I've searched for it in the documentation, but was unable to find it.

 

Below the code as it should be pasted.

 

//+------------------------------------------------------------------+
//|                              Indicator: Extreme Volume Alert.mq4 |
//|                              Made with EABuilder                 |
//|                              Version 1.0                         |
//+------------------------------------------------------------------+

#property link      "EABuilder"
#property version   "1.0"
#property description ""

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

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_label1 "Extreme Volume M5"

//--- indicator buffers
double Buffer1[];

datetime time_alert; //used when sending alert
extern string Note___1 = "Set volume values for each period";
extern int volume_Asian_session = 1150;
extern int volume_London_session = 1150;
extern int volume_NY_session = 1150;
extern int volume_During_closing_hours = 1150;

extern string Note___2 = "Set times for each period";
extern int Start_Hour1 = 6; //time of the day
extern int Start_Min1 = 00; //time of the day
extern int End_Hour1 = 14; //time of the day
extern int End_Min1 = 59; //time of the day

extern string Note___3 = "Set number of bars back in time";
extern int  Max_Number_Bars_Back = 300;

extern string ArrowTypes = "https://docs.mql4.com/constants/objectconstants/wingdings";
extern int Arrow = 251;
extern color Color = Yellow;
extern int LineWidth = 2;

extern string Note___4 = "Alert type settings";
extern bool Send_Email = false;
extern bool Audible_Alerts = true;
extern bool NotificationAlert = false;
extern string AlertWav=".wav";
double myPoint; //initialized in OnInit

bool inTimeInterval(datetime t, int Start_Hour1, int Start_Min1, int End_Hour1, int End_Min1)
  {
   string TOD = TimeToString(t, TIME_MINUTES);
   string Start1 = StringFormat("%02d", Start_Hour1)+":"+StringFormat("%02d", Start_Min1);
   string End1 = StringFormat("%02d", End_Hour1)+":"+StringFormat("%02d", End_Min1);
   return((StringCompare(TOD, Start1) >= 0 && StringCompare(TOD, End1) <= 0)
     || (StringCompare(Start1, End1) > 0
       && ((StringCompare(TOD, Start1) >= 0 && StringCompare(TOD, "23:59") <= 0)
         || (StringCompare(TOD, "00:00") >= 0 && StringCompare(TOD, End1) <= 0))));
  }


void myAlert(string type, string message)
  {
   int handle;
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Extreme Volume Alert @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      Print(type+" | Extreme Volume @ "+Symbol()+","+Period()+" | "+message);
      if(Audible_Alerts) Alert(type+" | Extreme Volume @ "+Symbol()+","+Period()+" | "+message);
      if(Send_Email) SendMail ( "Extreme Volume " +","+ Symbol()+" M"+Period(),Symbol()+" M"+Period());
      if(NotificationAlert) SendNotification(type+" | Extreme Volume @ "+Symbol()+","+Period()+" | "+message);
      handle = FileOpen("Extreme Volume.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
      if(handle != INVALID_HANDLE)
        {
         FileSeek(handle, 0, SEEK_END);
         FileWrite(handle, type+" | Extreme Volume @ "+Symbol()+","+Period()+" | "+message);
         FileClose(handle);
        }
      
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(1);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, Arrow);
   SetIndexStyle(0,DRAW_ARROW,0,LineWidth,Color);
   
   //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);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
     }
   else
      limit++;
   
   //--- main loop



   for(int i = limit-1; i >= 0; i--)
     {
      if(!inTimeInterval(Time[i], Start_Hour1, Start_Min1, End_Hour1, End_Min1)) continue; //draw indicator only at specific times of the day
      if (i >= MathMin(Max_Number_Bars_Back-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(iVolume(NULL, PERIOD_M5, i) >= volume_London_session //Volumes
      )
        {
         Buffer1[i] = Close[i]; //Set indicator value at Candlestick Low
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Extreme Volume"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: