IndicatorBuffers() ? Huh?

 

Everybody learns differently. I have access to YouTube and these forums and I even have the "Expert Advisor Programming for MT4" book that I refer to. It seems like nonsense that I would still struggle to understand such a basic concept. I know that. But that's all this is, is my lack of understanding. This isn't a scam to get someone to write code for me... despite the fact that I'm about to ask you to write a little code for me.

I'm struggling to understand IndicatorBuffers().  As I understand it, I use IndicatorBuffers(1) to say that I want 1 array of data in this indicator. I just want to use the buffer so that when I hover my mouse over a candle it will show me the local time in the data window. I'm not trying to draw anything on the chart or anything like that. I just want it to exist in a buffer so I can see it in the data window. I read that I have to use TimeLocal() but obviously not totally clear on how to use that either. I use MQL Docs and I see the different examples of its use and despite all that I keep getting errors. The error for the code below is:

" 'SetIndexBuffer' - no one of the overloads can be applied to the function call"


I would really appreciate if someone could just provide the code that accomplishes what I'm aiming to do. Seeing a clear example this way is an immeasurable help to me. And if you choose to write a few useful comments in there, I wouldn't complain. Thanks in advance!

//+------------------------------------------------------------------+
//|                                                   Time_Local.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
datetime time = TimeLocal();

int OnInit()
  {
IndicatorBuffers(1);
SetIndexBuffer(0,time);
SetIndexStyle (1, DRAW_NONE);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
dasilvja: I just want to use the buffer so that when I hover my mouse over a candle it will show me the local time in the data window.

Will not be possible with buffers, because all Indicator buffers are of the "double" data-type and cannot take a "datetime" data-type. So you can only "pop-up" floating point values, and not dates & times.

The only alternative would be use Chart Events and Graphic Objects, which I am sure is not quite what you want to learn.

 
Indicator buffers only show as doubles in the data window. You cant' have them display a time.
 
  1. You use the buffer property to state how many visual buffers you want.
  2. You use indicatorBuffers to state how many additional (non-visual) buffers you want.
  3. You use SetIndicatorBuffer to display a price (double) array.