"If", "else" and "}" not allowed on global scope error codes I am getting but not sure how to fix

 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime    // Swing High color
#property indicator_color2 Red     // Swing Low color

extern int lookbackBars = 10;  // Number of bars to look back for swing high/low identification

double swingHighBuffer[];
double swingLowBuffer[];

int CustomIndicatorCounted()
{
    return Bars - lookbackBars;
}

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 limit = rates_total - lookbackBars;

    if (prev_calculated > 0)
        limit--;

    for (int i = limit; i >= 0; i--)
    {
        double highPrice = high[i];
        double lowPrice = low[i];

        bool isSwingHigh = true;
        bool isSwingLow = true;

        for (int j = 1; j <= lookbackBars; j++)
        {
            if (high[i + j] >= highPrice || low[i + j] <= lowPrice)
            {
                isSwingHigh = false;
                isSwingLow = false;
                break;
            }
        }

        if (isSwingHigh)
        {
            for (int k = 1; k <= lookbackBars; k++)
            {
                if (high[i - k] >= highPrice || high[i + k] >= highPrice)
                {
                    isSwingHigh = false;
                    break;
                }
            }

            if (isSwingHigh)
            {
                swingHighBuffer[i] = highPrice;
                swingLowBuffer[i] = EMPTY_VALUE;
            }
            else
            {
                swingHighBuffer[i] = EMPTY_VALUE;
                swingLowBuffer[i] = EMPTY_VALUE;
            }
        }
        else if (isSwingLow)
        {
            for (int l = 1; l <= lookbackBars; l++)
            {
                if (low[i - l] <= lowPrice || low[i + l] <= lowPrice)
                {
                    isSwingLow = false;
                    break;
                }
            }

            if (isSwingLow)
            {
                swingHighBuffer[i] = EMPTY_VALUE;
                swingLowBuffer[i] = lowPrice;
            }
            else
            {
                swingHighBuffer[i] = EMPTY_VALUE;
                swingLowBuffer[i] = EMPTY_VALUE;
            }
        }
        else
        {
            swingHighBuffer[i] = EMPTY_VALUE;
            swingLowBuffer[i] = EMPTY_VALUE;
        }
    }
}

 
Zarod Allen:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime    // Swing High color
#property indicator_color2 Red     // Swing Low color

extern int lookbackBars = 10;  // Number of bars to look back for swing high/low identification

double swingHighBuffer[];
double swingLowBuffer[];

int CustomIndicatorCounted()
{
    return Bars - lookbackBars;
}

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 limit = rates_total - lookbackBars;

    if (prev_calculated > 0)
        limit--;

    for (int i = limit; i >= 0; i--)
    {
        double highPrice = high[i];
        double lowPrice = low[i];

        bool isSwingHigh = true;
        bool isSwingLow = true;

        for (int j = 1; j <= lookbackBars; j++)
        {
            if (high[i + j] >= highPrice || low[i + j] <= lowPrice)
            {
                isSwingHigh = false;
                isSwingLow = false;
                break;
            }
        }

        if (isSwingHigh)
        {
            for (int k = 1; k <= lookbackBars; k++)
            {
                if (high[i - k] >= highPrice || high[i + k] >= highPrice)
                {
                    isSwingHigh = false;
                    break;
                }
            }

            if (isSwingHigh)
            {
                swingHighBuffer[i] = highPrice;
                swingLowBuffer[i] = EMPTY_VALUE;
            }
            else
            {
                swingHighBuffer[i] = EMPTY_VALUE;
                swingLowBuffer[i] = EMPTY_VALUE;
            }
        }
        else if (isSwingLow)
        {
            for (int l = 1; l <= lookbackBars; l++)
            {
                if (low[i - l] <= lowPrice || low[i + l] <= lowPrice)
                {
                    isSwingLow = false;
                    break;
                }
            }

            if (isSwingLow)
            {
                swingHighBuffer[i] = EMPTY_VALUE;
                swingLowBuffer[i] = lowPrice;
            }
            else
            {
                swingHighBuffer[i] = EMPTY_VALUE;
                swingLowBuffer[i] = EMPTY_VALUE;
            }
        }
        else
        {
            swingHighBuffer[i] = EMPTY_VALUE;
            swingLowBuffer[i] = EMPTY_VALUE;
        }
    }
}

Delete ";" after OnCalculate()

 
Longsen Chen #:

Delete ";" after OnCalculate()

Oh wow thank you so much for your help I am new to this so again thanks a lot
 
Longsen Chen #:

Delete ";" after OnCalculate()

One other last issue I am getting a "not all control paths return a value" warning about the last "}" at the very end of the code any suggestions?

 
Zee Al #:

One other last issue I am getting a "not all control paths return a value" warning about the last "}" at the very end of the code any suggestions?

This means you have miss curly bracket } at the end of the code
 
Wissam Hussein #: This means you have miss curly bracket } at the end of the code

No, it means no value was returned.

int OnCalculate(…)
{
    int limit = rates_total - lookbackBars;
    ⋮
        else
        {
            swingHighBuffer[i] = EMPTY_VALUE;
            swingLowBuffer[i] = EMPTY_VALUE;
        }
    }
<<<<<what int are you returning?
}
 
William Roeder #:

No, it means no value was returned.

 This should be return(rates_total) 

 
Wissam Hussein #: This should be return(rates_total) 
That's one value that I never return.
          How to do your lookbacks correctly #9#14 & #19 (2016)
Reason: