Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 991

 
LuckyTrader:
The error is gone, with the same wording, now it has gone to another part. Just above I wrote to Igor

insert the prints where the error occurs, maybe you can solve your problem that way.

There is no other way, I have already explained the reason for your error

 

Hello, I decided to rewrite the indicator from MQL4 to MQL5 and got stuck in indicator buffers... I think I entered everything I needed but the indicator line is still not displayed!

Here's an example, I want to display the close price for the last 30 bars, I even put a comment on the buffer, to see if it is filled with something ...

The buffer is filling but the chart is empty and I don't see any image (((

What may be the problem? Maybe bars are backwards in MQL5?)


//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                                                . |
//|                                                                . |
//+------------------------------------------------------------------+
#property copyright "."
#property link      "."
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 8         // Количество буферов индикатора
#property indicator_plots   8         // Количество графических серий

#property indicator_label1 "TestLine" 
#property indicator_type1 DRAW_LINE  
#property indicator_style1 STYLE_SOLID 
#property indicator_width1 1  
#property indicator_color1 Red  
//+------------------------------------------------------------------+
//|                        БУФЕРЫ                                    |
//+------------------------------------------------------------------+
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];
//+------------------------------------------------------------------+
//|                     ПАРАМЕТРЫ БУфЕРА                             |
//+------------------------------------------------------------------+
int OnInit(){                   

SetIndexBuffer(0,Buffer1,INDICATOR_DATA);
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);  
PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);         
PlotIndexSetInteger(0,PLOT_LINE_COLOR,Blue);   

return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
//| Деинициализация                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
Comment("");}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| 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[]){
                
                
for(int Z = 30; Z>=0; Z--) {
Buffer1[Z] = iClose(NULL,0,Z);} 
Comment(Buffer1[0]);               

return(rates_total);}
//+------------------------------------------------------------------+

 
Nikita Zubarov:

Hello, I decided to rewrite the indicator from MQL4 to MQL5 and got stuck in indicator buffers... I think I entered everything I needed but the indicator line is still not displayed!

Here's an example, I want to display the close price for the last 30 bars, I even put a comment on the buffer, to see if it is filled with something ...

The buffer is filling but the chart is empty and I don't see any image (((

What may be the problem? Maybe bars are backwards in MQL5?)


The numbering of bars in MQL5 is reversed

for(int Z = rates_total-50; Z<rates_total; Z++)


indexing can be changed usinghttps://www.mql5.com/ru/docs/array/arraysetasseries
Документация по MQL5: Операции с массивами / ArraySetAsSeries
Документация по MQL5: Операции с массивами / ArraySetAsSeries
  • www.mql5.com
//| Custom indicator initialization function                         | //| Custom indicator iteration function                              |
 
Igor Makanu:

The numbering of bars in MQL6 is opposite


you can change the indexing usinghttps://www.mql5.com/ru/docs/array/arraysetasseries

Thank you!, added a line and it started to show normally!

ArraySetAsSeries(Buffer1,true); 
but I think the numbering of the bars is the same from right to left, just the buffers go backwards....
 
Nikita Zubarov:

Thanks!, added a line and it's starting to show properly!

but it seems to me the numbering of bars is the same from right to left, just buffers go backwards....

In 4, bar number 0 is the rightmost bar.

In 5, bar #0 is the leftmost bar.

by default, the indexing of indicator buffers is the same as for time series

if you use ArraySetAsSeries(), it will be applied only to one array - in your example to the indicator buffer array Buffer1 , for correct calculation you should also apply it to close

ArraySetAsSeries(Buffer1,true); 
ArraySetAsSeries(close,true); 
for(int Z = 30; Z>=0; Z--) 
{
Buffer1[Z] = сlose[i];
} 

or change the loop as described above

 
Hello, Can you please advise me if I want my EA to open a position on a symbol other than the current chart.
OrderSend(MarketInfo("EURUSD",MODE_ASK), OP_BUY, Lots, Ask, Slip, 0, 0, "", Magic, 0, Blue)
Am I correct? correct me if not
 
Averman:
Hello, Can you please advise me if I want my EA to open a position on a symbol other than the current chart.
OrderSend(MarketInfo("EURUSD",MODE_ASK), OP_BUY, Lots, Ask, Slip, 0, 0, "", Magic, 0, Blue)
Am I correct? correct me if not

Of course it's not right.

OrderSend("EURUSD", OP_BUY, Lots, MarketInfo("EURUSD",MODE_ASK), Slip, 0, 0, "", Magic, 0, Blue) 
If I haven't made a mistake somewhere, you have. But in any case, the meaning should be understandable.
 
MQL6 has already appeared, has anyone tested this shell?
 
Seric29:
MQL6 has already appeared, has anyone tested this shell?

Is today April 1?

 
Alexey Viktorov:

Isn't it April 1?

And I started googling)).

... found a one-page mql6 website and one link to a forum at mql5.com