ERROR 4807

 

Hi.. been getting this error on mt5 cant get it working

searched for many ERROR 4807 solution..cant get a solution "code"

played with it for while still cant get it working

//+------------------------------------------------------------------+
//|                                                       TMA+CG.mq4 |
//|                                                           mladen |
//| arrowse coded acording to idea presented by rajiv                |
//+------------------------------------------------------------------+
#property copyright "rajivxxx"
#property link      "rajivxxx@gmail.com"

#property indicator_chart_window

#property indicator_buffers 5
#property indicator_plots   5
//--- Up  Buffer
#property indicator_label1  "Up Buffer"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellow
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- Down Buffer
#property indicator_label2  "Down Buffer"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrAqua
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- Mid Buffer
#property indicator_label3  "Mid Bufer"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrMaroon
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- Up Arrow
#property indicator_label4  "Up Arrow"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2
//--- Down Arrow
#property indicator_label5  "Down Arrow"
#property indicator_type5   DRAW_ARROW
#property indicator_color5  clrBlue
#property indicator_style5  STYLE_SOLID
#property indicator_width5  2


input ENUM_TIMEFRAMES TimeFrame       = PERIOD_CURRENT;
input int    HalfLength      = 56;
input int    Price           = PRICE_WEIGHTED;
input double BandsDeviations = 1.618;
input bool   Interpolate     = true;

//--- indicator buffers
double tmBuffer[];
double upBuffer[];
double dnBuffer[];
double wuBuffer[];
double wdBuffer[];
double upArrow[];
double dnArrow[];
int    tmhandle,uphandle,dnhandle,brhandle;
double returnbar[];
double MA[];
int    mahandle;
double ATR[];
int    atrhandle;
int now;
string IndicatorFileName;
bool   calculatingTma = false;
bool   returningBars  = false;
datetime Time[];
int count,bars;
ENUM_TIMEFRAMES    timeFrame;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   timeFrame  = stringToTimeFrame(TimeFrame);
//--- indicator buffers mapping
   SetIndexBuffer(0,tmBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,upBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,dnBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,upArrow,INDICATOR_DATA);
   SetIndexBuffer(4,dnArrow,INDICATOR_DATA);
   SetIndexBuffer(5,wuBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,wdBuffer,INDICATOR_CALCULATIONS);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0.0);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
          calculatingTma=true; return(0); 
          returningBars=true;  return(0); 
   
   IndicatorFileName = GetRelativeProgramPath();;
   mahandle=iMA(_Symbol,_Period,1,0,MODE_SMA,Price);
   atrhandle=iATR(_Symbol,_Period,20);
         tmhandle = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations);
         uphandle = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations);
         dnhandle = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations);
         brhandle = iCustom(NULL,timeFrame,IndicatorFileName,"returnBars");
    bars=Bars(_Symbol,_Period);
//---
   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 calculated;
   calculated=BarsCalculated(mahandle);
   if(calculated<rates_total)
   {
      Print("Not all data of mahandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
   }
   calculated=BarsCalculated(atrhandle);
   if(calculated<rates_total)
   {
      Print("Not all data of atrhandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
   }
   calculated=BarsCalculated(tmhandle);
   if(calculated<rates_total)
   {
      Print("Not all data of tmhandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
   }
   calculated=BarsCalculated(uphandle);
   if(calculated<rates_total)
   {
      Print("Not all data of uphandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
   }
   calculated=BarsCalculated(dnhandle);
   if(calculated<rates_total)
   {
      Print("Not all data of dnhandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
   }
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
   {
      to_copy=rates_total-prev_calculated+1;
      if(prev_calculated>0) to_copy++;
   }
   if(CopyBuffer(mahandle,0,0,to_copy,MA)<=0)
   {
      Print("Getting MA is failed! Error",GetLastError());
   }
   if(CopyBuffer(atrhandle,0,0,to_copy,ATR)<=0)
   {
      Print("Getting ATR is failed! Error",GetLastError());
   }
   if(CopyBuffer(tmhandle,0,0,to_copy,tmBuffer)<=0)
   {
      Print("Getting tmBuffer is failed! Error",GetLastError());
   }
   if(CopyBuffer(uphandle,1,0,to_copy,upBuffer)<=0)
   {
      Print("Getting upBuffer is failed! Error",GetLastError());
   }
   if(CopyBuffer(dnhandle,2,0,to_copy,dnBuffer)<=0)
   {
      Print("Getting dnBuffer is failed! Error",GetLastError());
   }
   if(CopyBuffer(brhandle,0,0,to_copy,returnbar)<=0)
   {
      Print("Getting returnbar is failed! Error",GetLastError());
   }

CopyTime(_Symbol,_Period,0,count,Time);
   ArraySetAsSeries(MA,true);
   ArraySetAsSeries(ATR,true);
   ArraySetAsSeries(Time,true);
   ArraySetAsSeries(tmBuffer,true);
   ArraySetAsSeries(upBuffer,true);
   ArraySetAsSeries(dnBuffer,true);
   ArraySetAsSeries(upArrow,true);
   ArraySetAsSeries(dnArrow,true);
   ArraySetAsSeries(returnbar,true);

   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(time,true);
   int limit;
   if(prev_calculated==0)
      limit=rates_total-(MathMax(HalfLength,1)+1);
   else limit=rates_total-(MathMax(HalfLength,1)+1);
          
           if (returningBars)  { tmBuffer[0] = limit; return(0); }
           if (calculatingTma) { calculateTma(limit); return(0); }
           if (timeFrame > Period()) limit = (int)MathMax(limit,MathMin(bars-1,returnbar[0]*timeFrame/Period()));

 if( now != time[0])
   {
 for(int i=limit; i>=1 && !IsStopped(); i--)
      {
      int      shift1 = iBarShift(NULL,timeFrame,Time[i]);
      datetime time1  = iTime    (NULL,timeFrame,shift1);
  if (high[i+1]>upBuffer[i+1] && close[i+1]>open[i+1] && close[i]<open[i]) upArrow[i] = high[i]+ATR[i];
  if (low[i+1]<dnBuffer[i+1] && close[i+1]<open[i+1] && close[i]>open[i]) dnArrow[i] = high[i]-ATR[i];

         if (timeFrame <= Period() || shift1==iBarShift(NULL,timeFrame,Time[i-1])) continue;
         if (!Interpolate) continue;
      //
      //
         int n;
         for( n = 1; i+n < bars && Time[i+n] >= time1; n++) continue;
         double factor = 1.0 / n;
         for(int k = 1; k < n; k++)
            {
               tmBuffer[i+k] = k*factor*tmBuffer[i+n] + (1.0-k*factor)*tmBuffer[i];
               upBuffer[i+k] = k*factor*upBuffer[i+n] + (1.0-k*factor)*upBuffer[i];
               dnBuffer[i+k] = k*factor*dnBuffer[i+n] + (1.0-k*factor)*dnBuffer[i];
            }               



      }
      now = (int)time[0];
 }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
void calculateTma(int limit)
{
   int i,j,k;
   double FullLength = 2.0*HalfLength+1.0;
   
   //
   //
   //
   //
   //
   
   for (i=limit; i>=0; i--)
   {
      double sum  = (HalfLength+1)*MA[i];
      double sumw = (HalfLength+1);
      for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
      {
         sum  += k*MA[i+j];
         sumw += k;

         if (j<=i)
         {
            sum  += k*MA[i-j];
            sumw += k;
         }
      }
      tmBuffer[i] = sum/sumw;

      //
      //
      //
      //
      //
            
         double diff = MA[i]-tmBuffer[i];
         if (i> (bars-HalfLength-1)) continue;
         if (i==(bars-HalfLength-1))
         {
            upBuffer[i] = tmBuffer[i];
            dnBuffer[i] = tmBuffer[i];
            if (diff>=0)
               {
                  wuBuffer[i] = MathPow(diff,2);
                  wdBuffer[i] = 0;
               }
            else
               {               
                  wdBuffer[i] = MathPow(diff,2);
                  wuBuffer[i] = 0;
               }                  
            continue;
         }
      
         //
         //
         //
         //
         //
         
         if(diff>=0)
            {
               wuBuffer[i] = (wuBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
               wdBuffer[i] =  wdBuffer[i+1]*(FullLength-1)/FullLength;
            }
         else
            {
               wdBuffer[i] = (wdBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
               wuBuffer[i] =  wuBuffer[i+1]*(FullLength-1)/FullLength;
            }
         upBuffer[i] = tmBuffer[i] + BandsDeviations*MathSqrt(wuBuffer[i]);
         dnBuffer[i] = tmBuffer[i] - BandsDeviations*MathSqrt(wdBuffer[i]);
   }
}
//+------------------------------------------------------------------+
string GetRelativeProgramPath()

  {

   int pos2;

//--- get the absolute path to the application

   string path=MQLInfoString(MQL_PROGRAM_PATH);

//--- find the position of "\MQL4\" substring

   int    pos =StringFind(path,"\\MQL4\\");

//--- substring not found - error

   if(pos<0)

      return(NULL);

//--- skip "\MQL4" directory

   pos+=5;

//--- skip extra '\' symbols

   while(StringGetCharacter(path,pos+1)=='\\')

      pos++;

//--- if this is a resource, return the path relative to MQL5 directory

   if(StringFind(path,"::",pos)>=0)

      return(StringSubstr(path,pos));

//--- find a separator for the first MQL4 subdirectory (for example, MQL4\Indicators)

//--- if not found, return the path relative to MQL4 directory

   if((pos2=StringFind(path,"\\",pos+1))<0)

      return(StringSubstr(path,pos));

//--- return the path relative to the subdirectory (for example, MQL4\Indicators)

   return(StringSubstr(path,pos2+1));

  }
int stringToTimeFrame(string tfs)
{
   for(int l = StringLen(tfs)-1; l >= 0; l--)
   {
      int tchar = StringGetCharacter(tfs,l);
          if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256))
               tfs = (string)StringSetCharacter(tfs, 1, tchar - 32);
          else 
              if(tchar > -33 && tchar < 0)
                  tfs = (string)StringSetCharacter(tfs, 1, tchar + 224);
   }
   int tf=0;
         if (tfs=="M1" || tfs=="1")     tf=PERIOD_M1;
         if (tfs=="M5" || tfs=="5")     tf=PERIOD_M5;
         if (tfs=="M15"|| tfs=="15")    tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")    tf=PERIOD_M30;
         if (tfs=="H1" || tfs=="60")    tf=PERIOD_H1;
         if (tfs=="H4" || tfs=="240")   tf=PERIOD_H4;
         if (tfs=="D1" || tfs=="1440")  tf=PERIOD_D1;
         if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
         if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
         if (tf==0 || tf<Period())      tf=Period();
   return(tf);
} 


Thanks..

Alert: Error copying Bollinger Bands indicator Buffers - error:4807!!
Alert: Error copying Bollinger Bands indicator Buffers - error:4807!!
  • 2016.08.30
  • www.mql5.com
Hi, so i was about to test my EA and I had this error "Alert: Error copying Bollinger Bands indicator Buffers - error:4807!!" What am I doing wrong...
 
Abubakar Saidu:

Hi.. been getting this error on mt5 cant get it working

searched for many ERROR 4807 solution..cant get a solution "code"

played with it for while still cant get it working

Thanks..

Why not add a Print() statement:

   IndicatorFileName = GetRelativeProgramPath();;
   Print (IndicatorFileName);

To verify whether you are sending a valid indicator name to iCustom()?

 
2020.03.20 07:45:31.248    tryingtoconvert(GBPUSD,M5)    Not all data of mahandle is calculated (-1bars ). Error4807
2020.03.20 07:45:31.273    tryingtoconvert(GBPUSD,M5)    
only this nothing else,

actually am trying to learn and master converting any mt4 indicator.. to mt5.. am only successful in converting one from mq4-mq5 and one from mq5-mq4

without property strict
IndicatorFileName = WindowExpertName();


with property strict WidowsExpertName() is not working

unless this is used

IndicatorFileName = GetRelativeProgramPath()

string GetRelativeProgramPath()

  {

   int pos2;

//--- get the absolute path to the application

   string path=MQLInfoString(MQL_PROGRAM_PATH);

//--- find the position of "\MQL4\" substring

   int    pos =StringFind(path,"\\MQL4\\");

//--- substring not found - error

   if(pos<0)

      return(NULL);

//--- skip "\MQL4" directory

   pos+=5;

//--- skip extra '\' symbols

   while(StringGetCharacter(path,pos+1)=='\\')

      pos++;

//--- if this is a resource, return the path relative to MQL5 directory

   if(StringFind(path,"::",pos)>=0)

      return(StringSubstr(path,pos));

//--- find a separator for the first MQL4 subdirectory (for example, MQL4\Indicators)

//--- if not found, return the path relative to MQL4 directory

   if((pos2=StringFind(path,"\\",pos+1))<0)

      return(StringSubstr(path,pos));

//--- return the path relative to the subdirectory (for example, MQL4\Indicators)

   return(StringSubstr(path,pos2+1));

  }




Thanks a lot for your feedback
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Path to the file of an image that will be used as an icon of the EX5 program. Path specification rules are the same as for resources. The property must be specified in the main module with the MQL5 source code. The icon file must be in the ICO format. When launching a script or an Expert Advisor on the chart, the stack of at least 8 MB is...