Candles are not shown properly.

 

Hi All, 

I wrote the simple indicator. I want this indicator in the separated windows. the first run in OnCalculated function is working correct. But the updated the value is not proper as shown in the picture. It seems it just show the closed value in green. 

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
//--- plot Bars
#property indicator_label1  "DRAW_CANDLES1"
#property indicator_type1   DRAW_CANDLES
#property indicator_color1  Green,Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

static int index_calc = 0;

//--- Indicator buffers
double         Candle1Buffer1[];
double         Candle1Buffer2[];
double         Candle1Buffer3[];
double         Candle1Buffer4[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

//--- indicator buffers mapping
   SetIndexBuffer(0,Candle1Buffer1,INDICATOR_DATA);
   SetIndexBuffer(1,Candle1Buffer2,INDICATOR_DATA);
   SetIndexBuffer(2,Candle1Buffer3,INDICATOR_DATA);
   SetIndexBuffer(3,Candle1Buffer4,INDICATOR_DATA);
   
   //PlotIndexSetInteger(0,PLOT_SHIFT,0);
   //PlotIndexSetInteger(1,PLOT_SHIFT,0);
   //PlotIndexSetInteger(2,PLOT_SHIFT,0);
   //PlotIndexSetInteger(3,PLOT_SHIFT,0);
   
//--- An empty value
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//--- The name of the symbol, for which the bars are drawn
   symbol=_Symbol;
//--- Set the display of the symbol
   PlotIndexSetString(0,PLOT_LABEL,symbol+" Open;"+symbol+" High;"+symbol+" Low;"+symbol+" Close");
   IndicatorSetString(INDICATOR_SHORTNAME,"DRAW_CANDLES("+symbol+")");
//---
   return(INIT_SUCCEEDED);
  }
  
  void DrawLine()
  {
   ObjectDelete(_Symbol, "VLine");
   ObjectCreate(_Symbol, "VLine", OBJ_VLINE, 0,TimeCurrent(), 0);
   
   ObjectSetInteger(0, "VLine", OBJPROP_COLOR, clrMagenta);
   ObjectSetInteger(0, "VLine", OBJPROP_WIDTH, 1);
  }
//+------------------------------------------------------------------+
//| Custom indicator 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[])
  {
   static int ticks=INT_MAX-100;
//--- Calculate ticks to change the style, color and width of the line
   ticks++;
   
      if(rates_total==prev_calculated)
     {
      return(rates_total);
     }
     
     
//--- If a sufficient number of ticks has been accumulated
   //CopyFromSymbolToBuffers(symbol,rates_total,0,
   //         Candle1Buffer1,Candle1Buffer2,Candle1Buffer3,Candle1Buffer4);
   int start = 0;
   if(prev_calculated==0)
      start=0;
   else
      start=prev_calculated;
      
//--- main loop
   for(int i=start; i<rates_total && !IsStopped(); i++)
     {
        Candle1Buffer1[index_calc] = open[index_calc]; 
        Candle1Buffer2[index_calc] = high[index_calc]; 
        Candle1Buffer3[index_calc] = low[index_calc]; 
        Candle1Buffer4[index_calc] = close[index_calc]; 
        index_calc++;
     }
            

   DrawLine();

   return(rates_total);
  }
 
zavataafnan:

Hi All, 

I wrote the simple indicator. I want this indicator in the separated windows. the first run in OnCalculated function is working correct. But the updated the value is not proper as shown in the picture. It seems it just show the closed value in green. 

        Candle1Buffer1[index_calc] = open[index_calc]; 
        Candle1Buffer2[index_calc] = high[index_calc]; 
        Candle1Buffer3[index_calc] = low[index_calc]; 
        Candle1Buffer4[index_calc] = close[index_calc]; 
        Candle1Buffer1[i] = open[i]; 
        Candle1Buffer2[i] = high[i]; 
        Candle1Buffer3[i] = low[i]; 
        Candle1Buffer4[i] = close[i]; 
 
Le Minh Duc #:

Hi Le, 

there is no difference in the behaviour. both of them show a small green line for further calling of OnCalculated.


Best Regards,

Mostafa

 
You may check documentation for ObjectDelete and ObjectCreate. The first input parameter is chart id.
 

Yashar Seyyedin #:
You may check documentation for ObjectDelete and ObjectCreate. The first input parameter is chart id.

My problem is the candles that I showed in circle. I do not know why those have one value of candle. 

Files:
 
zavataafnan #:

Hi Le, 

there is no difference in the behaviour. both of them show a small green line for further calling of OnCalculated.


Best Regards,

Mostafa

Dont use static variable like that, you will get array out of range if you want you indicator repaint every tick

   int start = 0;
   if(prev_calculated==0)
      start=0;
   else
      start=prev_calculated-1;

...
        Candle1Buffer1[i] = open[i]; 
        Candle1Buffer2[i] = high[i]; 
        Candle1Buffer3[i] = low[i]; 
        Candle1Buffer4[i] = close[i]; 
 

Here's how you can adjust your OnCalculatefunction to address these issues:

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[])
{
   int start;
   if(prev_calculated > 1)
      start = prev_calculated - 1; // Start from the last known point to update it
   else
      start = 0; // Start from scratch if no previous calculations

   for(int i = start; i < rates_total && !IsStopped(); i++)
   {
      // Directly use 'i' to index into your buffers
      Candle1Buffer1[i] = open[i]; 
      Candle1Buffer2[i] = high[i]; 
      Candle1Buffer3[i] = low[i]; 
      Candle1Buffer4[i] = close[i]; 
   }

   DrawLine();

   return(rates_total);
}
 
Hello, please I'm having an issue with the mt5 update. 
All the indicators I'm putting on my chart windows are appearing as boxes. I have tired different indicators on them, please what's the issue
Files:
 
Kelvin Odum #:
Hello, please I'm having an issue with the mt5 update. 
All the indicators I'm putting on my chart windows are appearing as boxes. I have tired different indicators on them, please what's the issue
Probably wingding font is not installed on your system.
 
Kelvin Odum #:
Hello, please I'm having an issue with the mt5 update. 
All the indicators I'm putting on my chart windows are appearing as boxes. I have tired different indicators on them, please what's the issue

Read this: https://www.mql5.com/en/forum/462316

Wingding Arrow Error, Displaying Square Instead
Wingding Arrow Error, Displaying Square Instead
  • 2024.02.12
  • Le Minh Duc
  • www.mql5.com
I realized there are some characters in the wingding code that cannot be displayed properly, it always displays as a square...