Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

i need help to print numbers as strings, and with the correct number of decimals.

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

    i need help to print numbers as strings, and with the correct number of decimals.





    people with nt,


    i have been trying for a number of weeks now to get nt to generate text files as logs for events of interest. i received very little assistance from nt support but i have continued to work hard on this objective and have been able to make good progress. actually, i have been watching videos and going though microsoft's courses to learn to code in c# and it has been very helpful for this matter.


    at this point i have been able to get streamwriter to work acceptably in nt.

    Code:
    private void recordevent ( string filepath )
    {
    filepath = string.Format(@"{0}ntlogs {1} {2} {3} {4} {5}.txt", Pridir, Symtic, DateTime.Now.ToString("yyyyMMdd HHmmss"), Castyp, Close[0]);
    Print(filepath); sw = new StreamWriter(filepath); sw.AutoFlush = true; sw.WriteLine(message); sw.Close();
    }

    from everything i have studied, it seems to me that nt implicitly converts the number Close[0] to string in the fragment above as it has been working correctly for me.


    however, there are several other numerical inputs and variables (some are integer, some are decimal type) i want to be able to print to my text files using this same string.Format(@"...", method. in these cases, implicit conversion by c# will not be good enough. ¿how can i command nt to convert decimal or integer values to string? ¿and very importantly, how can i define the number of decimals that will be printed? ¿and, is it possible to define the number of decimals to be printed as a user defined input instead of hard coding it?




    very well, i hope i will receive far more effective assistance from nt support this time. thanks, regards.

    #2
    Hello rtwave,

    While the NinjaTrader staff cannot debug a script on your behalf or write code for you, we can detail how documented NinjaScript items work.

    I do have an example that writes bar information to file that you may use as an example.
    https://ninjatrader.com/support/foru...nce#post100192

    To convert an integer to a string use <int>.ToString().
    To convert a double to a string use <double.ToString().

    This would fall under general C# and is not specific to NinjaScript. Integers, doubles, and strings are all common to C#.
    Below are public links to the Microsoft documentation.
    https://docs.microsoft.com/en-us/dotnet/api/system.int32.tostring?view=netframework-4.8#System_Int32_ToString
    https://docs.microsoft.com/en-us/dotnet/api/system.double.tostring?view=netframework-4.8


    Also, below are public links to the Microsoft documentation on format strings.
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    https://docs.microsoft.com/en-us/pre...ad66z(v=vs.85)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I hope you understand that no one will write and compile code for you? On this forum there are a huge number of articles, which describe in detail how to solve this problem. I can't throw off the link, because I don't remember when I saw that post. I had a similar problem, I needed to display the numbers of 500 random numbers in the range from 0 to 10000. Each time the maximum number that was displayed was 244. I don't know what it was connected with, but now this is my least favorite number, although it has a very cool value which you can find out about here https://www.sunsigns.org/angel-number-244-meaning/. The only thing that helped me was to completely rewrite the entire code, slightly changing the algorithm ..
      Last edited by VictorNorth9; 08-22-2020, 12:26 AM.

      Comment


        #4
        Hello VictorNorth9,

        Welcome to the NinjaTrader forums!

        Let me know if you have any questions on this topic.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Nolyn, Today, 10:59 AM
        0 responses
        1 view
        0 likes
        Last Post Nolyn
        by Nolyn
         
        Started by Gkomi, Today, 10:02 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by JTizz, Today, 08:58 AM
        6 responses
        29 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by Bob49, Today, 08:40 AM
        0 responses
        19 views
        0 likes
        Last Post Bob49
        by Bob49
         
        Started by Malik_demoacct, Today, 08:31 AM
        0 responses
        17 views
        0 likes
        Last Post Malik_demoacct  
        Working...
        X