What is wrong?

 

  for the ParSar:

double GetSARValue(string cPair, int nPeriod, int bar)   

  {

   double sar[1];

   int sarHandle = iSAR(cPair,nTimeFrame1,Step,Maximum,0);

   if(sarHandle!=INVALID_HANDLE)

     {

      CopyBuffer(sarHandle,0,bar,1,sar);

     }

   return(sar[0]);

  }

//+------------------------------------------------------------------+

string TestSAR(int nPeriod, string cPair)

  {

  

     double nResultClose;

     double nResultSAR;

     

   nResultClose=iClose(cPair,nTimeFrame1,0);

   nResultSAR = GetSARValue(cPair,nTimeFrame1,Step,Maximum,0);

   

   if(nResultClose < nResultSAR  )

      return("SELL");

   if(nResultClose > nResultSAR )

      return("BUY");

   return("");

  }


 

To put it nicely... everything.

We all got to start somewhere, so it's cool, but not going to lie this looks like some AI generated BS.


Your GetSARValue() function is defined as: double GetSARValue(string cPair, int nPeriod, int bar)

But when you're calling it in TestSAR(): nResultSAR = GetSARValue(cPair, nTimeFrame1, Step, Maximum, 0);


GetSARValue is missing needed parameters:

double GetSARValue(string cPair, int timeframe, double step, double max, int bar)
{
   double sar[1];
   int sarHandle = iSAR(cPair, timeframe, step, max);

   if(sarHandle != INVALID_HANDLE)
   {
      if(CopyBuffer(sarHandle, 0, bar, 1, sar) != 1)
         return(EMPTY_VALUE); // handle error
   }
   else
      return(EMPTY_VALUE); // handle error

   return(sar[0]);
}


You're passing nPeriod in both functions but never using it.

Global variables like nTimeFrame1, Step, Maximum must be defined.

TestSAR is incorrect.

string TestSAR(string cPair, int timeframe, double step, double max)
{
   double nResultClose = iClose(cPair, timeframe, 0);
   double nResultSAR = GetSARValue(cPair, timeframe, step, max, 0);

   if(nResultSAR == EMPTY_VALUE)
      return("NO SIGNAL"); // error case

   if(nResultClose < nResultSAR)
      return("SELL");

   if(nResultClose > nResultSAR)
      return("BUY");

   return("");
}


The correct code should look like:

//+------------------------------------------------------------------+
//| GetSARValue: Returns SAR value for a given pair and bar         |
//+------------------------------------------------------------------+
double GetSARValue(string cPair, int timeframe, double step, double max, int bar)
{
   double sar[1];
   int sarHandle = iSAR(cPair, timeframe, step, max);

   if(sarHandle != INVALID_HANDLE)
   {
      if(CopyBuffer(sarHandle, 0, bar, 1, sar) == 1)
         return sar[0];
      else
         Print("CopyBuffer failed for SAR.");
   }
   else
   {
      Print("Failed to create SAR handle.");
   }

   return EMPTY_VALUE;
}

//+------------------------------------------------------------------+
//| TestSAR: Compares current close with SAR and returns signal     |
//+------------------------------------------------------------------+
string TestSAR(string cPair, int timeframe, double step, double max)
{
   double nResultClose = iClose(cPair, timeframe, 0);
   double nResultSAR = GetSARValue(cPair, timeframe, step, max, 0);

   if(nResultSAR == EMPTY_VALUE)
      return "NO SIGNAL";

   if(nResultClose < nResultSAR)
      return "SELL";

   if(nResultClose > nResultSAR)
      return "BUY";

   return "";
}

//+------------------------------------------------------------------+
//| Example usage                                                    |
//+------------------------------------------------------------------+
void OnStart() // Use OnTick() if you're in an EA rather than indicator.
{
   string signal = TestSAR("EURUSD", PERIOD_H1, 0.02, 0.2);
   Print("Signal: ", signal);
}

As noted above, change OnStart to OnTick if you're coding an EA rather than indicator.