How can I connect close price of candles in mql5?

 
Hi
I am new to mql5. I want to write the code to connect the close prices of candles to each other in an expert advisor file.

In Pine script, it is:

plot(close)

In mql5 I can use something like this, but it creates numerous parallel lines.

int numberOfCandles = Bars(_Symbol, PERIOD_CURRENT);
ObjectCreate(0, "close" + numberOfCandles, OBJ_HLINE, 0, 0, close); 

Improperly formatted code edited by moderator. Please always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
  • Usually people who can't code don't receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Book and Documentation
  • Remember also, that you can debug your code with MetaEditor's own debugging functionality.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.
 
It would be best to use an Custom Indicator to connect the close prices, using an indicator buffer, instead of using multiple graphics objects (which will be inefficient, more difficult to implement, and slow down the chart updating).
 
A simple indicator, save it to a file, compile and enjoy.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellow
#property indicator_width1  1

double    Buffer1[];

int OnInit()
  {
   SetIndexBuffer(0,Buffer1,INDICATOR_DATA);
   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[])
  {
   if (prev_calculated>=0)
      ArrayCopy(Buffer1, close, prev_calculated, prev_calculated, rates_total);
   return(rates_total - 1);
  }
 
Fernando Carreiro #:
It would be best to use an Custom Indicator to connect the close prices, using an indicator buffer, instead of using multiple graphics objects (which will be inefficient, more difficult to implement, and slow down the chart updating).

Thanks.

 
Soewono Effendi #:
A simple indicator, save it to a file, compile and enjoy.

Thank you very much.

So, in general when I want to display something like this on chart, it is better to write a custom indicator and use iCustom() function to call it?

Sorry for these kinds of questions. I come from pine script and it seems that mql5 and Pine script are conceptually different.

 

Just use CopyClose and set it as series. Easiest approach

iCustom can slow down the EA in the strategy tester significantly

 
Alex trader #:

Thank you very much.

So, in general when I want to display something like this on chart, it is better to write a custom indicator and use iCustom() function to call it?

Sorry for these kinds of questions. I come from pine script and it seems that mql5 and Pine script are conceptually different.

it is normally done in an ea, however, there is a few threads/discussions on the forum with general agreement that using sourcing from an indicator is better. The reasons it is "better" are rather unclear -- at leas imo.

 
Conor Mcnamara #:

Just use CopyClose and set it as series. Easiest approach

iCustom can slow down the EA in the strategy tester significantly

Michael Charles Schefe #:

it is normally done in an ea, however, there is a few threads/discussions on the forum with general agreement that using sourcing from an indicator is better. The reasons it is "better" are rather unclear -- at leas imo.

Thanks

 
Conor Mcnamara #:

Just use CopyClose and set it as series. Easiest approach

iCustom can slow down the EA in the strategy tester significantly

Thanks. Ok. But with this approach I can not plot close on the chart. So I think I have to use  iCustom function.