Question: I ' m currently working on developing an MQL 5 Expert Advisor script. In this script, I ' m implementing a functionality where I initially

I'm currently working on developing an MQL 5 Expert Advisor script. In this script, I'm implementing a functionality where I initially set the end time for a graphical object, specifically a rectangle, to the current time (TimeCurrent()). Later, I need to dynamically update this end time based on certain conditions.
In a 'Gap up' scenario, if any subsequent bar closes below the lower boundary (price_dn) of the rectangle, I must adjust the end time of the rectangle to the time of that bar.
Similarly, in a 'Gap down' scenario, if any subsequent bar closes above the upper boundary (price_up) of the rectangle, I need to update the end time of the rectangle to the time of that bar.
Provide the updated complete code to incorporate these functionalities? Ensure all components of my current code are retained during the update process.
Donot use Chatgpt. Accuracy of the code will determine the rating. Take note of this.
My current MQL5 EA Script is "
#property indicator_chart_window
#property indicator_plots 0
//--- Expert Advisor input parameters
input color InpColorToUP = clrLime; // Color of the gap up
input color InpColorToDN = clrDeepPink; // Color of the gap down
input int maxbars =5555;// how many bars to Look back
string prefix;
double price;
//+------------------------------------------------------------------+
//| Expert Advisor initialization function |
//+------------------------------------------------------------------+
int OnInit(){
//--- Expert Advisor buffers mapping
prefix=MQLInfoString(MQL_PROGRAM_NAME)+"_";
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert Advisor deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
ObjectsDeleteAll(0,prefix);
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Expert Advisor 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[]){
//---
if(rates_total<4) return 0;
price = close[0];
ArraySetAsSeries(open,true);
ArraySetAsSeries(high,true);
ArraySetAsSeries(low,true);
ArraySetAsSeries(close,true);
ArraySetAsSeries(time,true);
int limit=rates_total-prev_calculated;
if(limit>1){
limit=rates_total-5;
}
for(int i=maxbars; i>=0 && !IsStopped(); i--){
if(low[i]>high[i+2]){
double up=fmin(high[i],low[i]);
double dn=fmax(high[i+2],low[i+2]);
DrawArea(i,up,dn,time,InpColorToUP,1);
}
if(low[i]high[i]){
double up=fmin(high[i+2],low[i+2]);
double dn=fmax(high[i],low[i]);
DrawArea(i,up,dn,time,InpColorToDN,0);
}
if(low[i+2]0?"up_" : "dn_")+TimeToString(time[index]);
if(ObjectFind(0,name)<0)
ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_FILL,true);
ObjectSetInteger(0,name,OBJPROP_BACK,true);
ObjectSetString(0,name,OBJPROP_TOOLTIP,"
");
//---
ObjectSetInteger(0, name, OBJPROP_TIME, 0, time[index +2]);
ObjectSetInteger(0, name, OBJPROP_TIME, 1, TimeCurrent()); // Set end time to current time
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, price_up);
ObjectSetDouble(0, name, OBJPROP_PRICE, 1, price_dn);
ObjectSetInteger(0, name, OBJPROP_COLOR, color_area);
}
//+------------------------------------------------------------------+
".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!