How to display an advance Bar on the graph to measure something

 

Hi, i need help. I would to display a bar, cloured, to indicate a status.

What i have to do ? Is it possible to have an example of code ?


thank you

 

You can place graphical objects on the chart based on the 4 corners and then they aren't bound to any time stamp.

The normal search for Dashboard here: https://www.mql5.com/en/search#!keyword=Dashboard
returns ~ 10,000 links, filter them for:
Article (code and explanation)
CodeBase (just the code)

 
Alessandro Furlani:

Hi, i need help. I would to display a bar, cloured, to indicate a status.

What i have to do ? Is it possible to have an example of code ?


thank you

Hi consult the following indicator code

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1
input color ConditionColor=clrRoyalBlue;//the color for your condition
/*
to draw over a bar you need 4 prices open high low and close
*/
double myOpen[],myHigh[],myLow[],myClose[];
/*
and we will also need a way to tell the terminal
which color to draw the bar with 
here we will have 2 colors , none and your condition's
*/
double color_of_bar[];
int OnInit()
  {
  //instruct the terminal of the type of display you want
    //in this case we want colored candles which uses 5 arrays
  SetIndexBuffer(0,myOpen,INDICATOR_DATA);
  SetIndexBuffer(1,myHigh,INDICATOR_DATA);
  SetIndexBuffer(2,myLow,INDICATOR_DATA);
  SetIndexBuffer(3,myClose,INDICATOR_DATA);
  SetIndexBuffer(4,color_of_bar,INDICATOR_COLOR_INDEX);
  //we specify the display
  PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_CANDLES);
  //we specify the colors
  PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
  PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrNONE);//Color 1 : nothing
  PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,ConditionColor);//Color 2 : the condition coloration
  //badaboom
  //onwards to the oncalculate function 
  return(INIT_SUCCEEDED);
  }

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[])
  {
  /* everything you see in [] is a list
     if we have a list of 10 things 
     then the first item is LIST[0]
     and the last item is LIST[9]
     
     Similarly over here we are given by the kind terminal
     lists of prices . Neat 
     the open[0] is , yeah the first open price of this chart
     
     the total # of prices is : rates_total
     so the last open price (the most recent) resides
     in open[rates_total-1] at all times
     
     when a new candle forms the list expands and we can detect that with
     prev_calculated which counts how many candles (items in the list) we have 
     processed 
     so if we see that there is 1 candle more than the one we have processed 
     we process it
     
     easy
  */
  //we define the starting point of our processing of the lists 
    int start_from=prev_calculated,end_to=rates_total;
  //if we have calculated nothing we process it all , normally as
  //                              prev calculated is 0 at first
    //go into the lists one item at a time 
    //the lists are in parallel so open and close refer to the same candle
    for(int i=start_from;i<end_to;i++){
       //we fill up the candle prices we created on top
         myOpen[i]=open[i];
         myClose[i]=close[i];
         myHigh[i]=high[i];
         myLow[i]=low[i];
       //and your condition comes in here 
         //set the default color as nothing
         color_of_bar[i]=0;//this reflects to that : PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrNONE);
                           //where we set color 0 to be nothing 
         //if your condition is true , here we will do the following check :
         /*
         if we are in a candle that has 2 candles before it
         and it is higher than both 
         then paint it
         */
         //if theres 2 candles behind it so 2+
         if(i>=2){//because theres 0 and 1 (2 candles)
           //and this high is higher than previous high
             if(myHigh[i]>myHigh[i-1]){
               //and this high is higher than 2 highs ago
                 if(myHigh[i]>myHigh[i-2]){
                   //then set the color to the condition color
                     color_of_bar[i]=1.0;//this reflects to that : PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,ConditionColor);
                                         //where we set color 1 to be our condition color 
                   }
               }
         }
       }
  return(rates_total);
  }