Errors, bugs, questions - page 1190

 
Sorry, it's in MT4
 
Luckhuman:
Sorry, it's in MT4.
Try adding the #property strict directive. Maybe some error will be written in the log.
 
Luckhuman:
Sorry, this is in MT4
Unfortunately the CopySpread() function is not supported in MetaTrader 4 (there was an error in the help).
 
Automated-Trading:
Unfortunately the CopySpread() function is not supported in MetaTrader 4 (there was an error in the help).
How many indicator buffers does MT4 support? I was able to bind only 17 buffers
 
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#include <Object.mqh>

class CDoubleDynArray : public CObject
  {
public:
   double            Buffer[];

                     CDoubleDynArray(void){}
                    ~CDoubleDynArray(void){}
  };

CDoubleDynArray *buffers[];

int OnInit()
  {
//--- indicator buffers mapping
   ArrayResize(buffers,24);
   int i;
   for(i=0;i<ArraySize(buffers);i++)
      buffers[i]=new CDoubleDynArray;

   IndicatorBuffers(ArraySize(buffers));
   SetIndexBuffer(0,buffers[0].Buffer);
   for(i=1;i<ArraySize(buffers);i++)
     {
      if(!SetIndexBuffer(i,buffers[i].Buffer,INDICATOR_CALCULATIONS))
         Print(i," ",GetLastError());
      else
         Print(i," ",ArraySize(buffers[i].Buffer));
     }
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   IndicatorBuffers(1);
   for(int i=1;i<ArraySize(buffers);i++)
     {
      delete buffers[i];
      buffers[i]=NULL;
     }
   delete buffers[0]; 
   ArrayResize(buffers,0); 
  }

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[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 
Luckhuman:


Where in the code can you see that only 17? You're creating 24, aren't you?

Show me what the log says.

 
Luckhuman:
How many indicator buffers does MT4 support? I was able to bind only 17 buffers

There are 512 buffers available in MT4:

The number of buffers cannot exceed 512 and be less than the value specified in the indicator_buffers property. If your custom indicator requires additional buffers for counting, you should use this function to specify the total number of buffers.

In the example you need to add a line:

#property indicator_buffers 24
IndicatorBuffers - Документация на MQL4
  • docs.mql4.com
IndicatorBuffers - Документация на MQL4
 
Automated-Trading:


In the example you need to add a line:

can we make a warning like in MT5 about missing property plots ?
 
Automated-Trading:

There are 512 buffers available in MT4:

In the example we need to add a line:

In this line I specify the number of buffers

IndicatorBuffers(ArraySize(buffers));

Here is a screenshot of the result

 
Automated-Trading:

There are 512 buffers available in MT4:

A line should be added to the example:

#property indicator_buffers 24

With this line, it works. But then IndicatorBuffers() function doesn't work, because it is the one used in the code with value 24

Please excuse me. I have cut the code down to a test example, starting from a template indicator. There was the following line in the indicator

#property indicator_buffers 1
#property indicator_plots   1