What is the mistake?

 

In MQL5 I get this error: wrong parameters count for iSAR:

string TestParSar_(int nPeriod, string cPair)

  {

   double nResultClose;

   double nResultSar;

   

   nResultSar=iSAR(cPair,nTimeFrame1,Step,Maximum,0);

   nResultClose =iClose(cPair,nTimeFrame1,0);

   

   if(nResultClose < nResultSar)

     {

      return("SELL");

     }

   if(nResultClose > nResultSar)

     {

      return("BUY");

     }

   return("");


 
You are using mql4 code for mql5. 

In mt5 indicators commands return the indicator handle, not the indicator buffer value.
 
Robert Milovic:
nResultSar=iSAR(cPair,nTimeFrame1,Step,Maximum,0);
int  iSAR( 
   string           symbol,      // symbol name 
   ENUM_TIMEFRAMES  period,      // period 
   double           step,        // price increment step - acceleration factor 
   double           maximum      // maximum value of step 
   );

fix iSar

 

MQL5 requires different parameters for iSAR():

int handleSAR = iSAR(
   string                symbol,	// symbol
   ENUM_TIMEFRAMES       period,	// timeframe (use ENUM_TIMEFRAMES)
   double                step,		// acceleration step (typically 0.02)
   double                maximum	// maximum step (typically 0.2)
);

Update your code to:

string TestParSar_(int nPeriod, string cPair)
{
   double sarValue[1];        // Array to store SAR values
   int handleSAR = iSAR(cPair, PERIOD_CURRENT, Step, Maximum);
   
   if(handleSAR == INVALID_HANDLE) return "ERROR";
   
   // Copy latest SAR value
   if(CopyBuffer(handleSAR, 0, 0, 1, sarValue) <= 0) return "ERROR";
   
   double nResultClose = iClose(cPair, PERIOD_CURRENT, 0);

   if(nResultClose < sarValue[0]) return "SELL";
   if(nResultClose > sarValue[0]) return "BUY";
   return "";
}
 
James McKnight #:

MQL5 requires different parameters for iSAR():

Update your code to:

Thanks, that works perfectly fine, Thanks