DLls in Metatrader 4

To add comments, please log in or register
JefCrystal
113
JefCrystal  

I have three DLLS I use one is for SQL and built by  Sergey Lukin Runs Great ! Thanks for posting it  I also TA-Lib-Core.dll and one I made .  To prevent mutex I found a post from William Roeder https://www.mql5.com/en/forum/154746. Works great! Thanks!

Here is the question I have two.   EA_1 wins the race and Locks.  EA two is waiting.  EA one is Waiting for DLL to process and it takes to long and releases and then makes the request again. How long will EA one wait for DLL to reply before it moves on ?   Question two. Some time I get a error Access violation read to 0x00000000 I found some Items on Stack exchange that  infer it can be an array that is 2 Big. How big is 2 Big ? Last Question. I have always opened a chart and waited 1 min per chart to bring data down 1st time Then I open them and close them when done using some thing like iClose(sSymbol,iTimeFrame,0); Is this really necessary? To Insure the data is up 2 data. I have had indicators start a a different point Than [0] meaning there is no data or gap in data .

EAX_Mysql - MySQL library
EAX_Mysql - MySQL library
  • www.mql5.com
Accidently I ran into MQL5 and was forced to pull a MySQL library together. As for any library I hope the examples show how the library can be used. As for any library actually the most important things are examples how to use it ;) Identify your MQL5 Data Directory (MQL5). Download Connector/C (libmysql) for your MetaTrader environment (32 or...
GrumpyDuckMan
882
GrumpyDuckMan  

 How long will EA one wait for DLL to reply before it moves on ? It might have expired without an un expectation handled 

 How big is 2 Big ?  Maybe array is out of range.   

Some time I get a error Access violation read to 0x00000000? Might be no data available.

JefCrystal
113
JefCrystal  
GrumpyDuckMan:

 How long will EA one wait for DLL to reply before it moves on ? It might have expired without an un expectation handled 

 How big is 2 Big ?  Maybe array is out of range.   

Some time I get a error Access violation read to 0x00000000? Might be no data available.

Thanks for the comments. Here is the code That is giving me grief . Below are two functions. One to requests the rates  and one to calls the DLL. The locking for race conditions works perfect . The or Access violation read to 0x00000000 happens very rarely and stops metatrader from working. I do know the error happens when the DLL is called NOT when it is returning. I do not think it is a araay size issue or Copyrates would have given me a error 

I trap for a Copy rates -1 and cut the size and check for no data . But I do not know how long to wait for error 4066. I have not checked if error 4066 can happen with copy rates returning data I doubt that can happen. Any thoughts? the error I am trapping is the  Access violation

                    
double CBNForexFunctions::dGetDllPivot(int iParamFunctionControl = 0, int iParamNoOfRecords = 0,  datetime dtParamStartTime = 0, int iParamBarStart = 0 , datetime dtParamEndTime = 0, int iParamBarEnd = 0)
{ 

   //+-------------------------------------------------------------------+      
   //|   Local Variables Initialization                                  |
   //+-------------------------------------------------------------------+       
   
   string szPatterns       = "";   
   
   double dReturnInfo      = 0.0;

   int iMaximumRecords    = iParamNoOfRecords;
   int iLastPattern        = miEATypeOfTrade;
   int iSizeArray          = 0;   
   int      z              = 0;

   int iAccountNumber      =  AccountNumber();   
   int iServerTime         = (int)TimeCurrent();    
 
   datetime dtCurrTimeNow  =  dtGetTimeCurrent();
   //+-------------------------------------------------------------------+      
   //|   Main Body                                                       |
   //+-------------------------------------------------------------------+       
   
   
   if ( iLastPattern == 0 )  { iLastPattern  =  1; }
   
  
   iMaximumRecords       =  iEnsureRetrievedRates(iParamFunctionControl, iMaximumRecords,   dtParamStartTime ,  iParamBarStart  ,  dtParamEndTime ,  iParamBarEnd);
 
 
   if (iMaximumRecords <= 100 || iAccountNumber == 0 ){ vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); return(0);}
    
   szPatterns  =   sFindPatternString(iLastPattern);
   if(ArraySize(Pivots)>0)  ArrayFree(Pivots);
   ArrayResize(Pivots, iMaximumRecords);
   ArrayInitialize(Pivots,0);
  
   if(ArraySize(Details)>0)  ArrayFree(Details);
   ArrayResize(Details, iMaximumRecords);
   ArrayInitialize(Details,0);

   
   szPatterns  =   sFindPatternString(iLastPattern);
   

   
   if ( bMGTLockOperation(DEF_PIVOT_LOCKED,60) )
   { 
      
       CalcPivotDataDetail(iAccountNumber, Rates, Pivots, iMaximumRecords, szPatterns, iLastPattern,Details, msEASymbol, miEATimeFrame, iServerTime, 50, 2013);
      
       vMGTUnLockOperation(DEF_PIVOT_LOCKED);
       mdCurrentPivotR = Pivots[0][PIVOT_RES_PRICE];
       mdCurrentPivotS = Pivots[0][PIVOT_SUP_PRICE];
   }
   else
   {  
       //+----- If it happens to lock at the very first time that it has never been
      //+----- calculated once beofre just vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); return 0 otherwise 
          if ( mdCurrentPivotR == 0 && mdCurrentPivotS == 0 ) {vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); return (0);} else  {vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); return(DEF_OPERATION_LOCKED);}
   
   }
   
  //+-------------------------------------------------------------------+
   //| Deinitialization  of Function                                     |
   //+-------------------------------------------------------------------+

    
   
 
   //+----- End God      
   return(ArraySize(Pivots)/13);  
      

   
} //+----- end of  fuction
//+----- --------------------------------------------------------------------------- |
//+----- --------------------------------------------------------------------------- |
int CBNForexFunctions::iEnsureRetrievedRates( int iParamDefines = 0,int iParamNoOfRecords = 0, datetime dtParamStartTime = 0, int iParamiBarStart = 0 , datetime dtParamEndTime = 0, int iParamEndBar = 0 )
{ 
  

 

   //+-------------------------------------------------------------------+      
   //|   Local Variables Initialization                                  |
   //+-------------------------------------------------------------------+       

   

   int   iMaximumRecords  = -1;
   int   iCountSmaller100  = 0;   
   int   iSleep_Var        = 1000;
   int   iMinimumRecords   = 100;

   datetime dtCurrentTime   = 0;           
   datetime dtBarTime       = 0;
   bool     bPassFail       = False;   
   //+----- Returns total bars and Load the rates array in tates
   ArrayFree(Rates);
   ArraySetAsSeries(Rates,True);
      switch( iParamDefines )
   {
      case deSTimeEndTime: if( dtParamStartTime == 0  || dtParamEndTime  == 0) {iParamDefines = deSuperMaxRecords ;}      break;
      case deSTimeEndBar:  if( dtParamStartTime == 0  || iParamEndBar    == 0) {iParamDefines = deSuperMaxRecords ;}      break;
      case deBars:         if( iParamNoOfRecords == 0 )                        {iParamDefines = deSuperMaxRecords ;}      break;
     
  }  
        

   
 
   int iCounterNumber    =  1;
   int iJan2000          = 946684800;
   int iBarsBack         = iBarShift(msEASymbol,miEATimeFrame,946684800,False);
   int iSizeArrayDetails = 0;
   int iSizeArrayPivots  = 0;
   //+ ------------------------------------------------------------------------------ + 
   //+ For Forward testing and  live chart use the current time of the dealing desk   +
   //+ ------------------------------------------------------------------------------ +       
   dtBarTime        =   iTime(Symbol(), PERIOD_M1, 0); 
   dtCurrentTime    =   TimeCurrent();      

   //+ ------------------------------------------------------------------------------ +          
   //+ For back testing we need to use time of the bar                                +
   //+ 946684800 GMT: Sat, 01 Jan 2000 00:00:00 GMT
   //+ ------------------------------------------------------------------------------ + 
   
      while(!bPassFail)
   {
         switch( iParamDefines )
         {
            case deSTimeEndTime:    iMaximumRecords   = CopyRates(msEASymbol, miEATimeFrame, dtParamStartTime, dtParamEndTime, Rates);   break;
            case deSBarsEndbars:    iMaximumRecords   = CopyRates(msEASymbol, miEATimeFrame, iParamiBarStart, iParamEndBar, Rates);      break;
            case deSuperMaxRecords: iMaximumRecords   = CopyRates(msEASymbol, miEATimeFrame, 0, iBarsBack, Rates);                       break;
            case deSTimeEndBar:     iMaximumRecords   = CopyRates(msEASymbol, miEATimeFrame, dtParamStartTime, iParamEndBar, Rates);     break;
            case deBars:            iMaximumRecords   = CopyRates(msEASymbol, miEATimeFrame, 0, iParamNoOfRecords, Rates);               break;
            
        }    
            if( iMaximumRecords <= 0 )
         {
         
               switch( iParamDefines )
            {
               //+----- Case one move End Time closer
               case deSTimeEndTime:    dtParamStartTime = dtParamEndTime +((dtParamEndTime -dtParamStartTime)/2) ;iBarsBack = iBarShift(msEASymbol,miEATimeFrame,dtParamStartTime,False); break;
               //+----- Case Two move End Bar closer
               case deSBarsEndbars: iParamiBarStart = iParamiBarStart /2;iBarsBack = iParamiBarStart;       break;
               //+----- Case Two move End Tim closer
               case deSuperMaxRecords: iBarsBack = iBarsBack/2;    break;
               
               case deBars: iParamNoOfRecords = iParamNoOfRecords/2;iBarsBack = iParamNoOfRecords;  break;
                      
           } 
           if( iBarsBack<=0 ) break;
         } 
     
                    
            ArrayFree(Pivots);
            iSizeArrayPivots      =   ArrayResize(Pivots, iMaximumRecords);   
            ArrayInitialize(Pivots,0);
         
            ArrayFree(Details);
            iSizeArrayDetails    =   ArrayResize(Details, iMaximumRecords);
            ArrayInitialize(Details,0);  
            if( iMaximumRecords >0 )   break;
   
   }

  
   if(iMaximumRecords >0 ) miNumberOfRecordsRetrieved = iMaximumRecords;
   //+----- Return number of records copied successfully
   //+-------------------------------------------------------------------+
   //| Deinitialization  of Function                                     |
   //+-------------------------------------------------------------------+
   mcaGOD[ iFunc ].sDebuggerURL1 = "https://www.mql5.com/en/docs/series/copyrates";
    
   

   return(iMaximumRecords);


}
ArrayCopySeries - Array Functions - MQL4 Reference
ArrayCopySeries - Array Functions - MQL4 Reference
  • docs.mql4.com
If data are copied from another chart with different symbol and/or timeframe, it is possible that the necessary data will lack. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - requested history data under updating) will be placed into the last_error variable, and there will be necessary to retry copying...
To add comments, please log in or register