Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

MarketDataEventArgs.ToString() method culture specific?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MarketDataEventArgs.ToString() method culture specific?

    Question is whether the string generated by calling MarketDataEventArgs.ToString() is culture specific. I will explain by an example.
    code snippet handling OnMarketData event:
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    string exampleString = e.ToString();
    }
    Running this method in US may result in the following 'exampleString':
    Instrument='CL 12-13 Nymex' Type=Last Price=94.88 Volume=1 Time=11/6/2013 1:28:13

    The question is whether this string, in particular its price portion, will be formatted differently in Europe, for example French culture ( CultureInfo("fr-FR") ) will format decimal point separation with a comma instead. and thus it might be that the string could look like this
    Instrument='CL 12-13 Nymex' Type=Last Price=94,88 Volume=1 Time=11/6/2013 1:28:13
    This would be the case if the 'ToString()' method internally used a call to 'Price.ToString()' as Double.ToString() is culture specific and would return 94.88 in US and 94,88 in most european cultures.

    It is important to know the answer to this question for anyone who develops applications for NinjaTrader with international audience in mind.

    #2
    Hello JQuant,

    Thank you for your post.

    This should be dependent on your region settings for Windows.
    http://windows.microsoft.com/en-us/w...#1TC=windows-7
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your answer. Could you post an example of an update entry in a non-us region?
      Even better, could you confirm that the following is the case:
      in the price portion of the string, the only difference across regions will be that some use '.' as decimal point separator and others use ',' as separator. Everything else (regarding price entry) will be the same. Therefore to correctly parse a price 'double' from an entry would be to find if it contains a '.' and in that case use 'en-US' culture or if it contains ',' then use 'fr-FR' culture. So, in pseudo code, assuming one first separates the correct portion of price string as 'priceString', we could handle it as follows:

      double price = 0;
      if(priceString.Contains("."))
      {
      price = Convert.ToDouble(priceString, usCulture);
      }
      else if(priceString.Contains(","))
      {
      price = Convert.ToDouble(priceString, frenchCulture);
      }
      else
      {
      price = Convert.ToDouble(priceString);//here it doesn't matter what region we are in...
      }
      where usCulture is 'en-US' instance of CultureInfo and frenchCulture is 'fr-FR' instance of CultureInfo class.

      Comment


        #4
        Hello JQuant,

        You actually have the example right there. That will check the priceString if it does contain a , or ar . for the value
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by benmarkal, Yesterday, 12:52 PM
        3 responses
        22 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by helpwanted, Today, 03:06 AM
        1 response
        17 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        11 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        6 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        244 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Working...
        X