Any way to draw a rectangle in the onCalculate function?

 

I'm looking to edit this code to be able to draw a rectangle between the 261.8 and the 423.6 fibo levels when an arrow is clicked.




here are the final result that i want to achieve, red rectangle for the red arrow and blue rectangle for the green arrow:



and this is the code of the arrows indicator:

//+------------------------------------------------------------------+
//|                                                     absorb.mq5 |
//|                             Copyright 2000-2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_ARROW
#property indicator_type2   DRAW_ARROW
#property indicator_color1  Gray
#property indicator_color2  Gray
#property indicator_label1  "Up"
#property indicator_label2  "Down"
//--- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- 10 pixels upper from high price
int    ExtArrowShift=-10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_ARROW,217);
   PlotIndexSetInteger(1,PLOT_ARROW,218);
//--- arrow shifts when drawing
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,ExtArrowShift);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-ExtArrowShift);
//--- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
  }
//+------------------------------------------------------------------+
//|                                               |
//+------------------------------------------------------------------+
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<5)
      return(0);

   int start;
//--- clean up arrays
   if(prev_calculated<7)
     {
      start=2;
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else
      start=rates_total-2;
//--- main cycle of calculations
   for(int i=start; i<rates_total-1 && !IsStopped(); i++)
     {
      //--- Lower 
      if(open[i] < close[i] && open[i-1]>close[i-1])
      {
         if(high[i]>high[i-1] && low[i]<low[i-1] && close[i]-open[i] > open[i-1]-close[i-1])
         ExtLowerBuffer[i]=low[i];
         else
         ExtLowerBuffer[i]=EMPTY_VALUE;
      }
      else
      { 
       
       //--- Upper
       if(open[i]>close[i] && open[i-1] < close[i-1])
       {
          if(low[i]<low[i-1] && high[i]>high[i-1] && -close[i]+open[i] > -open[i-1]+close[i-1])
             ExtUpperBuffer[i]=high[i];
          else
             ExtUpperBuffer[i]=EMPTY_VALUE;
       }   
      }
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }

//+------------------------------------------------------------------+
 

Hi

I think you need to find a freelancer who will code this for you. Or show us here your own attempts of trying to code this script so we can help you with this.

I can only say that you can modify this code to create objects at the places where indicator place the arrows) and then code another script where you detect if those new objects arrows are clicked:

OnChartEvent has included detection of clicked objects (you can differentiate what was clicked by color detection)

Best Regards

 
Arrow buffers are not arrow objects, you can't click or select them.
 
William Roeder #:
Arrow buffers are not arrow objects, you can't click or select them.

Oh I see, so first, I need to "map" my arrows, using an object, and then I need to detect the click on it, thanks for the reply, will try it out