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);
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 ""; }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
In MQL5 I get this error: wrong parameters count for iSAR: