MQL4 Box Breakout Indicator | Need to set a Alert if it breaksout

 

Hey

I want to add a buy and sell alert, when the price breakouts of the box.

Thanks for the help!


Here is the Indicator(Not from me):

// THIS CODE IS POSTED SO THAT LIKE MINDED PAY IT FORWARD CODERS MAY
// IMPROVE ON IT AND REPOST IT ON THE FORUM FOR THEIR FELLOW TRADERS
//==================================================================
// [!!!-MT4 BREAKOUT BOX]            \¦/   
//                                  (ò ó)
//_____________________________o0o___(_)___o0o______________________ 
#property copyright "Welcome to the World of Forex"
#property indicator_chart_window
             int NumberOfDays=20;      
   extern string periodBegin="03:00",periodEnd="06:00",BoxEnd="18:00"; 
    extern color BoxHLColor=C'30,60,100',BoxPeriodColor=C'30,100,60';
//==========================================================================================================
   int   init() {return(0);}
//==========================================================================================================
   int deinit() {string dtTradeDate; for(int i=ObjectsTotal(); i>=0;i--) {dtTradeDate=ObjectName(i);
   if(StringFind(dtTradeDate,"Box",0)==0) {ObjectDelete(dtTradeDate);}} return(0);}
//==========================================================================================================
   int  start() {datetime dtTradeDate=TimeCurrent();
   if(Period()<=60) {for (int i=0; i<NumberOfDays; i++) {
   DrawObjects(dtTradeDate,"BoxHL  "    +TimeToStr(dtTradeDate,TIME_DATE),periodBegin,periodEnd,BoxEnd,BoxHLColor,0,1);
   DrawObjects(dtTradeDate,"BoxPeriod  "+TimeToStr(dtTradeDate,TIME_DATE),periodBegin,periodEnd,periodEnd,BoxPeriodColor,0,2);  
   dtTradeDate=decrementTradeDate(dtTradeDate);
   while (TimeDayOfWeek(dtTradeDate)>5) dtTradeDate=decrementTradeDate(dtTradeDate);}} return(0);}
//==========================================================================================================
   void DrawObjects(datetime dtTradeDate,string sObjName,string sTimeBegin,string sTimeEnd,string sTimeObjEnd,color cObjColor,int iOffSet,int iForm) {
   datetime dtTimeBegin,dtTimeEnd,dtTimeObjEnd; double dPriceHigh,dPriceLow; int iBarBegin,iBarEnd;

    dtTimeBegin=StrToTime(TimeToStr(dtTradeDate,TIME_DATE)+" "+sTimeBegin);
      dtTimeEnd=StrToTime(TimeToStr(dtTradeDate,TIME_DATE)+" "+sTimeEnd);
   dtTimeObjEnd=StrToTime(TimeToStr(dtTradeDate,TIME_DATE)+" "+sTimeObjEnd);
      
      iBarBegin=iBarShift(NULL,0,dtTimeBegin);
        iBarEnd=iBarShift(NULL,0,dtTimeEnd);
     dPriceHigh=High[Highest(NULL,0,MODE_HIGH,iBarBegin-iBarEnd,iBarEnd)];
      dPriceLow=Low [Lowest (NULL,0,MODE_LOW, iBarBegin-iBarEnd,iBarEnd)];

//==========================================================================================================  
             ObjectCreate(sObjName,OBJ_RECTANGLE,0,0,0,0,0);
                ObjectSet(sObjName,OBJPROP_TIME1,dtTimeBegin);
                ObjectSet(sObjName,OBJPROP_TIME2,dtTimeObjEnd);
   if(iForm==1){ObjectSet(sObjName,OBJPROP_PRICE1,dPriceHigh);  
                ObjectSet(sObjName,OBJPROP_PRICE2,dPriceLow);
                ObjectSet(sObjName,OBJPROP_STYLE,STYLE_SOLID);
                ObjectSet(sObjName,OBJPROP_COLOR,cObjColor);
                ObjectSet(sObjName,OBJPROP_BACK,True);}
   if(iForm==2){ObjectSet(sObjName,OBJPROP_PRICE1,dPriceHigh+iOffSet*Point);
                ObjectSet(sObjName,OBJPROP_PRICE2,dPriceLow-iOffSet*Point);
                ObjectSet(sObjName,OBJPROP_STYLE,STYLE_SOLID);
                ObjectSet(sObjName,OBJPROP_COLOR,cObjColor);
                ObjectSet(sObjName,OBJPROP_WIDTH,1);
                ObjectSet(sObjName,OBJPROP_BACK,true);}} 
                
    
//==========================================================================================================
   datetime decrementTradeDate (datetime dtTimeDate) {
   int   iTimeYear=TimeYear(dtTimeDate);
   int  iTimeMonth=TimeMonth(dtTimeDate);
   int    iTimeDay=TimeDay(dtTimeDate);
   int   iTimeHour=TimeHour(dtTimeDate);
   int iTimeMinute=TimeMinute(dtTimeDate);
   iTimeDay--; if(iTimeDay==0) {iTimeMonth--; if(iTimeMonth==0) {iTimeYear--; iTimeMonth=12;}
   // Thirty days hath September...  
   if(iTimeMonth==4||iTimeMonth==6||iTimeMonth==9||iTimeMonth==11)iTimeDay=30;
   // ...all the rest have thirty-one...
   if(iTimeMonth==1||iTimeMonth==3||iTimeMonth==5||iTimeMonth==7||iTimeMonth==8||iTimeMonth==10||iTimeMonth==12)iTimeDay=31;
   // ...except...
   if(iTimeMonth==2) if(MathMod(iTimeYear,4)==0) iTimeDay=29; else iTimeDay=28;}
   return(StrToTime(iTimeYear + "." + iTimeMonth + "." + iTimeDay + " " + iTimeHour + ":" + iTimeMinute));}
//==========================================================================================================
 
larsnicog: I want to add a buy and sell alert, when the price breakouts of the box. Thanks for the help! Here is the Indicator(Not from me):
May I suggest that you place your request in the Freelance section?
Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2022.08.24
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Your code
   datetime decrementTradeDate (datetime dtTimeDate) {
   int   iTimeYear=TimeYear(dtTimeDate);
   int  iTimeMonth=TimeMonth(dtTimeDate);
   int    iTimeDay=TimeDay(dtTimeDate);
   int   iTimeHour=TimeHour(dtTimeDate);
   int iTimeMinute=TimeMinute(dtTimeDate);
   iTimeDay--; if(iTimeDay==0) {iTimeMonth--; if(iTimeMonth==0) {iTimeYear--; iTimeMonth=12;}
   // Thirty days hath September...  
   if(iTimeMonth==4||iTimeMonth==6||iTimeMonth==9||iTimeMonth==11)iTimeDay=30;
   // ...all the rest have thirty-one...
   if(iTimeMonth==1||iTimeMonth==3||iTimeMonth==5||iTimeMonth==7||iTimeMonth==8||iTimeMonth==10||iTimeMonth==12)iTimeDay=31;
   // ...except...
   if(iTimeMonth==2) if(MathMod(iTimeYear,4)==0) iTimeDay=29; else iTimeDay=28;}
   return(StrToTime(iTimeYear + "." + iTimeMonth + "." + iTimeDay + " " + iTimeHour + ":" + iTimeMinute));}
Simplified.
datetime decrementTradeDate (datetime dtTimeDate) { return yesterday(dtTimeDate); }
          Find bar of the same time one day ago - MQL4 programming forum (2017)