A very strange question!

 

MQL5 简介:如何编写简单的EA 交易和自定义指标 - MQL5文章

Write it according to the article. It was found that the two lines of code in red swapped positions, resulting in the curve not being displayed. It's really strange.


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

//|                                                     study001.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property description "本指标使用平均市场波动"
#property description "计算获利水平,它使用的数据是"
#property description "平均真实波动范围(ATR)指标,根据"
#property description "每日价格数据计算。指标数值的计算是"
#property description "使用每日价格的最大和最小值"
#property version   "1.00"
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_plots   2
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  C'121,191,127'
#property  indicator_style1  STYLE_SOLID
#property  indicator_label1  "Buy TP"
#property  indicator_type2   DRAW_LINE
#property  indicator_color2  C'191,127,127'
#property  indicator_style2  STYLE_SOLID
#property  indicator_label2  "SELL TP"



input int ATRper= 5; //ATR周期数
input ENUM_TIMEFRAMES ATRtimeframe = PERIOD_D1;

double bu[],bd[];
int hATR;




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

    SetIndexBuffer(0, bu, INDICATOR_DATA);
    SetIndexBuffer(1, bd, INDICATOR_DATA);
    hATR = iATR(NULL,ATRtimeframe,ATRper);
   
//---
   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[])
  {
//---

   int i, day_n, day_t;
   double atr[], h_day, l_day;

   CopyBuffer(hATR, 0, 0, 2, atr);

   ArraySetAsSeries(atr, true);

   for(i = prev_calculated; i < rates_total; i++)
   {
      day_t = time[i] / PeriodSeconds(ATRtimeframe);
      if(day_n < day_t)
      {
         day_n = day_t;

         h_day = high[i];

         l_day = low[i];

      }
      else
      {
         if(high[1] > h_day) h_day = high[i];
         if(low[1] < l_day)  l_day = low[i];
      }
      
      bu[i] = l_day + atr[1];
      bd[i] = h_day - atr[1];
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   IndicatorRelease(hATR);
}
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.07.01
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

So much errors in a so small code, I can see at least 4 major issues : wrong indexing direction combination, variable uninitialized, no error checking when using functions, wrong data synchronisation. Without even talking about the minor issues.

There is no "2 lines of code in red" in what you posted.

 
Alain Verleyen #:
There is no "2 lines of code in red" in what you posted
Lol
 
William210 #:
Lol
What is funny ?
 
because when I pasted his code in metaeditor to try to help him, I saw way more than 2 lines in trouble, like you
 
William210 #:
because when I pasted his code in metaeditor to try to help him, I saw way more than 2 lines in trouble, like you
 
Reason: