Questions from Beginners MQL5 MT5 MetaTrader 5 - page 918

 
Tango_X:

Thank you! I always thought referring to classes was a pointer to a class. But here it's just a declaration... what's that got to do with it?

These are the very basics of OOP, have a little look at the Help. For example, the new/delete operators and so on.

 
Tango_X:

Thank you! I always thought referring to classes was a pointer to a class. But here it's just a declaration... what's that got to do with it?

I'll look into it, thanks!!!

 
Seric29:

In which metatrader do you create symbols on MT5?

Yes, on MT5

 
fxsaber:

You can't.

That's a shame.

I do this after uploading to excel, but it has its own shortcomings there too. It's a pity that there's no such feature built in.

But I have a hunch that it can somehow be implemented programmatically)

 
ISL:

Yes, on MT5.

It's a pity MT4 doesn't allow you to create symbols, you can change values but you can't create them.

 

teach me how to get rid of ArraySetAsSeries() !!!

here i rewrote a part of known indicator for MT4 (Perfect trend line), everything works as in MT4, BUT... But I can't get rid of forced ArraySetAsSeries() written by me - otherwise the indicator doesn't count correctly, I know that ArraySetAsSeries() will change the direction of indexing in the array, but for 2 days I haven't managed to do it myself!

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_plots   1
//--- plot BufBars
#property indicator_label1  "BufBars"
#property indicator_type1   DRAW_COLOR_BARS
#property indicator_color1  clrRed,clrAqua,clrNONE
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3

//--- input parameters
input int SlowLength         = 7; //Slow length
input int SlowPipDisplace    = 0; //Slow pip displace
input int FastLength         = 3; //Fast length
input int FastPipDisplace    = 0; //Fast pip displace
//--- indicator buffers
double         BufBarsBuffer1[];
double         BufBarsBuffer2[];
double         BufBarsBuffer3[];
double         BufBarsBuffer4[];
double         BufBarsColors[];
double         BufLSELLBuffer[];
double         BufLBUYBuffer[];
static int trend=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufBarsBuffer1,INDICATOR_DATA);
   SetIndexBuffer(1,BufBarsBuffer2,INDICATOR_DATA);
   SetIndexBuffer(2,BufBarsBuffer3,INDICATOR_DATA);
   SetIndexBuffer(3,BufBarsBuffer4,INDICATOR_DATA);
   SetIndexBuffer(4,BufBarsColors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5,BufLSELLBuffer,INDICATOR_DATA);
   SetIndexBuffer(6,BufLBUYBuffer,INDICATOR_DATA);
   for(int i=0;i<7;i++)
     {
      PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,FastLength+1);
      PlotIndexSetDouble(i,PLOT_EMPTY_VALUE,0.0);
     }
   ArraySetAsSeries(BufBarsBuffer1,true);
   ArraySetAsSeries(BufBarsBuffer2,true);
   ArraySetAsSeries(BufBarsBuffer3,true);
   ArraySetAsSeries(BufBarsBuffer4,true);
   ArraySetAsSeries(BufBarsColors,true);
   ArraySetAsSeries(BufLBUYBuffer,true);
   ArraySetAsSeries(BufLSELLBuffer,true);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   trend=0;
//---
   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,limit;
   double thigh1,tlow1,thigh2,tlow2,trendUp,trendDn;
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   if(prev_calculated==0)
     {
      limit=rates_total-1;
      BufLSELLBuffer[limit]=high[limit];
      BufLBUYBuffer[limit]=low[limit];
      limit--;
     }
   else limit=rates_total-prev_calculated+1;
   for(i=limit;i>=0;i--)
     {
      thigh1= high[iHighest(NULL,0,MODE_HIGH,SlowLength,i)]+SlowPipDisplace * _Point;
      tlow1 = low[iLowest(NULL,0,MODE_LOW,SlowLength,i)]-SlowPipDisplace * _Point;
      thigh2= high[iHighest(NULL,0,MODE_HIGH,FastLength,i)]+FastPipDisplace * _Point;
      tlow2 = low[iLowest(NULL,0,MODE_LOW,FastLength,i)]-FastPipDisplace * _Point;
      if(close[i]>BufLBUYBuffer[i+1])  trendUp=tlow1;  else trendUp=thigh1;
      if(close[i]>BufLSELLBuffer[i+1]) trendDn=tlow2;  else trendDn=thigh2;
      BufLSELLBuffer[i]= trendDn;
      BufLBUYBuffer[i] = trendUp;
      BufBarsBuffer1[i] = 0.0;
      BufBarsBuffer2[i] = 0.0;
      BufBarsBuffer3[i] = 0.0;
      BufBarsBuffer4[i] = 0.0;
      BufBarsColors[i]  = 2;
      if(close[i]<trendUp && close[i]<trendDn)
        {
         BufBarsBuffer1[i] = open[i];
         BufBarsBuffer2[i] = high[i];
         BufBarsBuffer3[i] = low[i];
         BufBarsBuffer4[i] = close[i];
         BufBarsColors[i]  = 0;
        }
      if(close[i]>trendUp && close[i]>trendDn)
        {
         BufBarsBuffer1[i] = open[i];
         BufBarsBuffer2[i] = high[i];
         BufBarsBuffer3[i] = low[i];
         BufBarsBuffer4[i] = close[i];
         BufBarsColors[i]  = 1;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Igor Makanu:

teach me how to get rid of ArraySetAsSeries() !!!

here i rewrote a part of known indicator for MT4 (Perfect trend line), everything works as in MT4, BUT... I know that ArraySetAsSeries() will change the direction of indexing in the array, but for 2 days I haven't managed it myself!

I can do the following

#ifdef __MQL5__
   ArraySetAsSeries(BufBarsBuffer1,true);
   ArraySetAsSeries(BufBarsBuffer2,true);
   ArraySetAsSeries(BufBarsBuffer3,true);
   ArraySetAsSeries(BufBarsBuffer4,true);
   ArraySetAsSeries(BufBarsColors,true);
   ArraySetAsSeries(BufLBUYBuffer,true);
   ArraySetAsSeries(BufLSELLBuffer,true);
#endif
 
Vitaly Muzichenko:

I can do it this way

I know that you can calculate the indicator values withoutArraySetAsSeries(), but I do not see what I am doing wrong. I tried to find a simple example in kodobase, but alas, all indicators are written in different ways, I cannot figure it out (((

SZY: I don't need the cross-platform indicator, I want to handle the default arrays indexing, I've already used ArrayGetAsSeries() - I don't understand it

 
Igor Makanu:

I know that you can calculate the indicator values withoutArraySetAsSeries(), but I do not see what I am doing wrong. I tried to find a simple example in kodobase, alas, all indicators are written in different ways, I cannot understand it (((

Your indicator calculation goes from the beginning to the end (from the most recent historical data to the most recent - to the current one). And this indicates the indexing as in timeseries. So the arrays should be indexed accordingly, which is what you have.

What goes wrong then?

 
Igor Makanu:

I know that I can calculate the indicator values withoutArraySetAsSeries(), but I do not see what I am doing wrong. I tried to find a simple example in kodobase but alas, all indicators are written in different ways, I cannot figure it out (((

SZZ: I don't need the cross-platform indicator, I want to handle the default arrays indexing, I've already used ArrayGetAsSeries() - I don't understand it

You can do it without ArraySetAsSeries, just use Print or Comment to make it clear, that the 0 array index, for example open[0], will be printed. From here you can make your own decisions. It will help you figure out what is what.

Reason: