arrow for breakout asian session

Dany William
46

hello all,

can you help me for my code please?

I placed an ARROW in this code(the code shows an ARROW when price break the highest(object named "BoxBreakOut_High") or the lowest(object named "BoxBreakOut_Low")),the problem   is it does not work well because it saved all the previous day HIGHEST and the LOWEST of asian session,so it places many arrows(it should save the  HIGHEST and the LOWEST of asian session in the day)

This is my code and the screenshot:

#property copyright "test"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
 
extern int    NumberOfDays = 1;        
extern string periodBegin    = "00:00"; 
extern string periodEnd      = "08:00";   
extern string BoxEnd         = "22:00"; 
extern int    BoxBreakOut_Offset = 10; 
extern color  BoxHLColor         = MidnightBlue; 
extern color  BoxBreakOutColor   = LimeGreen;
extern color  BoxPeriodColor     = OrangeRed;
extern int Text_size=8;
extern string Text_font = "Courier New";
extern color Text_color = White;
extern int zone_label_shift=4;
//--- buffers
double CrossUp[];
double CrossDown[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
   SetIndexStyle(0, DRAW_ARROW,EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
  DeleteObjects();
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() {
  DeleteObjects();
return(0);
}

//+------------------------------------------------------------------+
//| Remove all Rectangles                                            |
//+------------------------------------------------------------------+
void DeleteObjects() {
    ObjectsDeleteAll(0,OBJ_RECTANGLE);     
 return(0); 
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start() {
  datetime dtTradeDate=TimeCurrent();


  for (int i=0; i<NumberOfDays; i++) {
  
    DrawObjects(dtTradeDate, "BoxHL  " + TimeToStr(dtTradeDate,TIME_DATE), periodBegin, periodEnd, BoxEnd, BoxHLColor, 0, 1);
    DrawObjects(dtTradeDate, "BoxBreakOut_High  " + TimeToStr(dtTradeDate,TIME_DATE), periodBegin, periodEnd, BoxEnd, BoxBreakOutColor, BoxBreakOut_Offset,2);
    DrawObjects(dtTradeDate, "BoxBreakOut_Low  " + TimeToStr(dtTradeDate,TIME_DATE), periodBegin, periodEnd, BoxEnd, BoxBreakOutColor, BoxBreakOut_Offset,3);
    DrawObjects(dtTradeDate, "BoxPeriod  " + TimeToStr(dtTradeDate,TIME_DATE), periodBegin, periodEnd, periodEnd, BoxPeriodColor, BoxBreakOut_Offset,4);
    
         
    dtTradeDate=decrementTradeDate(dtTradeDate);
    while (TimeDayOfWeek(dtTradeDate) > 5) dtTradeDate = decrementTradeDate(dtTradeDate);
  }
}

//+------------------------------------------------------------------+ 
//| Create Rectangles                                                |
//+------------------------------------------------------------------+

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)];
  if(Open[1]>dPriceLow && dPriceLow>Close[1]){CrossDown[1]=High[1];}
  if(Open[1]<dPriceHigh && dPriceHigh<Close[1]){CrossUp[1]=Low[1];}
 
  ObjectCreate(sObjName, OBJ_RECTANGLE, 0, 0, 0, 0, 0);
  
  ObjectSet(sObjName, OBJPROP_TIME1 , dtTimeBegin);
  ObjectSet(sObjName, OBJPROP_TIME2 , dtTimeObjEnd);
  
//---- High-Low Rectangle
   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, False);
   }
   
//---- Upper Rectangle
  if(iForm==2){
      ObjectSet(sObjName, OBJPROP_PRICE1, dPriceHigh);
      ObjectSet(sObjName, OBJPROP_PRICE2, dPriceHigh + iOffSet*Point);
      ObjectSet(sObjName, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(sObjName, OBJPROP_COLOR, cObjColor);
      ObjectSet(sObjName, OBJPROP_BACK, False);
   }
 
 //---- Lower Rectangle 
  if(iForm==3){
      ObjectSet(sObjName, OBJPROP_PRICE1, dPriceLow - iOffSet*Point);
      ObjectSet(sObjName, OBJPROP_PRICE2, dPriceLow);
      ObjectSet(sObjName, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(sObjName, OBJPROP_COLOR, cObjColor);
      ObjectSet(sObjName, OBJPROP_BACK, False);
      
   }

//---- Period Rectangle
  if(iForm==4){
      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, 2);
      ObjectSet(sObjName, OBJPROP_BACK, False);
   }   
      string sObjDesc = StringConcatenate("High: ",dPriceHigh,"  Low: ", dPriceLow, " OffSet: ",iOffSet);  
      ObjectSetText(sObjName, sObjDesc,10,"Times New Roman",Black);
}

//+------------------------------------------------------------------+
//| Decrement Date to draw objects in the past                       |
//+------------------------------------------------------------------+

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));
}
Files:
Capture22.PNG  27 kb
Carl Schreiber
Moderator
12269
Carl Schreiber  
Dany William:

hello all,

can you help me for my code please?

I placed an ARROW in this code(the code shows an ARROW when price break the highest(object named "BoxBreakOut_High") or the lowest(object named "BoxBreakOut_Low")),the problem   is it does not work well because it saved all the previous day HIGHEST and the LOWEST of asian session,so it places many arrows(it should save the  HIGHEST and the LOWEST of asian session in the day)

This is my code and the screenshot:

If your EA doesn't do what it should use the debugger to check the variables at each moment.

Here: https://www.mql5.com/en/articles/654 you can read how it works.

Debugging MQL5 Programs
Debugging MQL5 Programs
  • www.mql5.com
This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
Dany William
46
Dany William  
Carl Schreiber #:

If your EA doesn't do what it should use the debugger to check the variables at each moment.

Here: https://www.mql5.com/en/articles/654 you can read how it works.

thanks so much, I will check your link

Dany William
46
Dany William  
Carl Schreiber #:

If your EA doesn't do what it should use the debugger to check the variables at each moment.

Here: https://www.mql5.com/en/articles/654 you can read how it works.

I have read the topic in the link,   all the variable in the code work well, but the problem is the fucntion I think or the algo is not ok, because I do not know wihch fucntion  should I use to avoid the code save the previous value(previous day),  that problem makes the codeto put many arrow

Eg: yesterday, the highest price of asian session was 1.45600 and the lowest was 1.44000,and for  today, the highest is 1.47000 and the lowest is 1.43000,so the robot should take the value for today( the highest is 1.47000 and the lowest is 1.43000 ), it should not take the yesterday value also,it should take 2 value everyday(it makes the code to show many arrows because there are many previous values)

and that is the problem of my code, it place many arrows

Dany William
46
Dany William  

can you please heolp me?

Dany William
46
Dany William  

i think that this group is nothing now, there is no help anymore, that's the problem of the group like this, the people who know something very well do not help a people lie me anymore(beginner)

KEEP YOUR KNOWLEDGE!!!!!!! this group becomes worst and worst