Line do not plot on graph (mql5)

 

I've been racking my brain for a few days, but so far I haven't been able to plot the line on the chart - Expert Advisor.

I will be very grateful if some kind soul can help me fix this code.

Thank you in advance for all your help.

#include <Trade/Trade.mqh>
CTrade trade;


double SMA50Array1M[];


void OnTick()
  {
   
   //define the properties of the moving average
   int SMA50Definition1M= iMA(_Symbol,PERIOD_M1,50,0,MODE_SMA, PRICE_CLOSE);
   
   
   // sort the price array from the current candle downwards
   ArraySetAsSeries(SMA50Array1M,true);
  
   
   //defined EA, one line, current candle, candle 50,100 e 200, store result
   CopyBuffer(SMA50Definition1M,0,0,10,SMA50Array1M);
   
   double SMA50Array1M = SMA50Array1M[0];
 //  ChartIndicatorAdd(0,0,SMA50Array1M);
   
    ChartIndicatorAdd(2,0 ,SMA50Array1M);
  
     Comment(  "SMA501M  :  ",DoubleToString(SMA50Array1M,2));

}
 
LuisOrtin :

I've been racking my brain for a few days, but so far I haven't been able to plot the line on the chart - Expert Advisor.

I will be very grateful if some kind soul can help me fix this code.

Thank you in advance for all your help.

1. Question about the design: there is no name, code, no code extension, no header, no OnInit.

2. A gross mistake: you create an indicator handle at every tick !!! Remember, in MQL5 the indicator handle MUST be created ONCE and it MUST be done in OnInit!

3. A gross mistake: ChartIndicatorAdd must be used in OnInit.

 
How to start with MQL5
How to start with MQL5
  • 2021.08.27
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 

Vladimir Karputov

Thank you so much for taking the time to help me, no words. I ran some tests and I believe I'm going to the wrong solution. In fact, what I needed was to plot the average of a larger time graph over the shortest period. For example, the 60-minute average on 5-minute charts. Is the solution to create objects to solve this issue? Speaking of which, thank you for sending the material, I have already started studying. It has very relevant subjects. But once again thanks for sharing knowledge. Simply unspeakable!