-3

I'm a novice programmer, so forgive me if this is something obvious. I've checked all the braces and find matching pairs in all cases here. The code compiles fine without this snippet. Any ideas?

protected bool Bullish(int ConsecutiveBullishBars)
    { 
       private int howmanybars = ConsecutiveBullishBars - 1;
       private bool IsMarketBullish = false;

        while (howmanybars >= 0) 
        {
            if (Close[howmanybars] > KeltnerChannel(Offset, Period)[howmanybars])
            {
                IsMarketBullish = true;
            }

            else
            {
                IsMarketBullish = false;
            }
            howmanybars--;
        }

        return IsMarketBullish;
    }

Here is the full code: http://pastebin.com/aHbzqKbw

hutch34
  • 35
  • 6
  • 1
    @MitchWheat, I suspect the method returns array/dictionary or something like that. – alex.b Feb 19 '14 at 00:59
  • ..@aleksey.berezan: Too early in morning! :) – Mitch Wheat Feb 19 '14 at 01:02
  • As @Jay said - the error is somwhere else. But even with this code it can be optimised to `return Close[0] > KeltnerChannel(Offset, Period)[0]` – JleruOHeP Feb 19 '14 at 01:03
  • @JleruOHeP: I don't think that's exactly he same behavior. If Close has zero length, your solution would throw. – recursive Feb 19 '14 at 01:11
  • @jay Code compiles fine with removing this method...no error about missing brackets there, so I don't think that is the case... but I'm happy to post the rest of the code as well. Thanks for taking a look: http://pastebin.com/aHbzqKbw – hutch34 Feb 19 '14 at 01:43

1 Answers1

3

It doesn't make any sense to mark local method variables as private. That is what is causing your errors.

Why the compiler is giving you an } expected error, I'm not sure. I'm guessing that the compiler is assuming that private int howmanybars is being interpreted as a private instance field definition, which cannot be declared inside a method. So it is telling you that it expects the Bullish method to end before the declaration.

protected bool Bullish(int ConsecutiveBullishBars)
{ 
   int howmanybars = ConsecutiveBullishBars - 1;
   bool IsMarketBullish = false;

    while (howmanybars >= 0) 
    {
        if (Close[howmanybars] > KeltnerChannel(Offset, Period)[howmanybars])
        {
            IsMarketBullish = true;
        }
        else
        {
            IsMarketBullish = false;
        }
        howmanybars--;
    }

    return IsMarketBullish;
}
shf301
  • 31,086
  • 2
  • 52
  • 86
  • Thank you! This makes sense of course. I removed the `private` declarations, and then added the arguments to where the `Bullish()` and `Bearish()` methods were called and it compiled just fine! Still not sure why it gave me the `}` expected error, but all is well now. – hutch34 Feb 19 '14 at 02:22
  • Actually, re-reading your comment, I think you are exactly right: The compiler expected `Bullish()` to end before the `private` declaration. This is where the compiler told me the error was. – hutch34 Feb 19 '14 at 02:29