The indicator does not display in real time in visual mode if i run EA test; it only appears after pressing stop. But when i choice only indicator mydonchian. It is working!

 
//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
   iCustom(NULL,0,"mydonchian",20,1,0);  
  }
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime

extern int Period = 20;

double UpperBuffer[];
double LowerBuffer[];
double MiddleBuffer[];

int OnInit()
{
    SetIndexBuffer(0, UpperBuffer);
    SetIndexBuffer(1, LowerBuffer);
    SetIndexBuffer(2, MiddleBuffer);

    SetIndexStyle(0, DRAW_LINE);  // Vẽ đường kênh trên
    SetIndexStyle(1, DRAW_LINE);  // Vẽ đường kênh dưới
    SetIndexStyle(2, DRAW_LINE);  // Vẽ đường giữa

    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[])
{
    int limit = rates_total - prev_calculated;
    if(prev_calculated > 0) limit++;  // Đảm bảo cập nhật từ vị trí cuối cùng

    // Cập nhật các giá trị từ `limit` đến 0 để đảm bảo real-time
    for(int i = limit - 1; i >= 0; i--)
    {
        int highestIndex = iHighest(Symbol(), 0, MODE_HIGH, Period, i);
        int lowestIndex = iLowest(Symbol(), 0, MODE_LOW, Period, i);

        double highestHigh = iHigh(Symbol(), 0, highestIndex);
        double lowestLow = iLow(Symbol(), 0, lowestIndex);
        
        UpperBuffer[i] = highestHigh;
        LowerBuffer[i] = lowestLow;
        MiddleBuffer[i] = (highestHigh + lowestLow) / 2;
    }
    return(rates_total);
}


The indicator does not display in real time in visual mode; it only appears after pressing stop.  Where am I going wrong in using this indicator that it does not draw real time? Thank you so much.

 
  1. chinhbcdev: The indicator does not display in real time in visual mode; it only appears after pressing stop.  Where am I going wrong in using this indicator that it does not draw real time? 

    EAs have no eyes; they don't need to see them. If you want to see it on the chart, you must add it to the chart, either manually, of via template.

    The template ordering for new charts is «EAname».tpl, (if tester) tester.tpl, (if debugging) debug.tpl (if offline chart) offline.tpl, and then Default.tpl.


  2. void OnTick()
      {
       iCustom(NULL,0,"mydonchian",20,1,0);  
    

    Be careful with NULL.

    1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
    2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
      MT5: create them.
    5. Cloud Protector Bug? - MQL4 programming forum (2020)