Check if string is valid symbol

Created at 06 Aug 2015, 21:40
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
FJ

fjl3

Joined 06.08.2015

Check if string is valid symbol
06 Aug 2015, 21:40


Hello everyone!

I am struggling with some code, and was hoping someone could point me in the right direction. I am combining to currencies, and want to check if the combination of the two is a valid symbol.

For example if I combine CHF and USD in both orders, CHFUSD and USDCHF, I need to be able to determine which is a valid symbol. If the indicator attempts USDCHF (the valid symbol) first, it proceeds as expected, but if an invalid symbol is tried the indicator halts.

Here is the code I am trying to check the symbols with:

private bool checkSymbol(string symbolCode)
{
    try
    {
        Symbol testSymbol = MarketData.GetSymbol(symbolCode);

        if (testSymbol.Bid == 0.0)
        {
            return false;
        }

        return true;
    } catch
    {
        return false;
    }
}

Any help would be greatly appreciated. Thanks in advance!


@fjl3
Replies

Spotware
17 Aug 2015, 18:54

Dear Trader,

Please have a look at the following code snippet:

        private bool checkSymbol(string symbolCode)
        {
            Symbol testSymbol = MarketData.GetSymbol(symbolCode);

            if (testSymbol == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

@Spotware