Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Show more than 2 decimal places

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

    Show more than 2 decimal places

    Hello
    I'm at a very early stage of learning NT script. I was able to find an indicator that I could modify and everything works except for one issue. The price will only show up to two decimals places and I need four. I'm referring to the price label and the scale (only showing 1.7 now, it needs to be 1.700, please see the "2 decimal" attachment). I only had to change the mathematical equation, no variables were added or changed. Also I have attached the modified indicator "Marketsentiment" which was taken from the "Spread" indicator. This is the line that I modified:

    Code:
    Value.Set((Instrument2Close[0] / (Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2)) / (Closes[Instrument1][0] / (Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2)));
    This was the original line:

    Code:
    //Value.Set(Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2);    // set output using synchronized data series
    In years past declaring a variable type "real" would set it up to show decimal places but I don't see any declaration of that type. I using NT 7 beta 16. Any help would be apprecaited.
    Thanks
    Attached Files

    #2
    I found this:

    Code:
    public override string FormatPriceMarker(double price)
            {
                // Formats price values to 4 decimal places
                return price.ToString("N4");
            }
    Will just inserting this do it? Or do I need to tie it to a variable?

    Comment


      #3
      Yes, this should do the job for you, for example this SMA below would show 4 digits as well -

      Code:
       
      protectedoverridevoid OnBarUpdate()
      {
      Value.Set(SMA(20)[0]);
      }
       
      publicoverridestring FormatPriceMarker(double price)
       
      {
      // Formats price values to 4 decimal places
      return price.ToString("N4");
      }

      Comment


        #4
        That worked!
        TY!

        Comment


          #5
          Atr

          Hello,

          I am trying to format ATR to 2 decimal places. I tried to use the code supplied by NT_Bertrand below, obviously will amend from 4 decimal to 2 decimals. I copied the code as it is into and NT Script, and got error CS0246, "The type or namespace name publicoverridestring could not be found (are you missing a using directive or an assembly reference?)" .
          Referring to the help menu suggested I re-imported a 3rd party dll. I see this code was in reply to a question back in 2010, is this code still applicable to the current version of NT? If it is, then where do I import this 3rd party DLL from, or any other suggestion on a way to go about formatting the decimal places?

          Thanks
          Dan

          Comment


            #6
            Atr

            Ok, I have come up with the following for what I want, though not sure how it's different from the code posted by NT_Bertrand. Of course, I am still at the very early learning stage of NTScripts and C#

            Code:
            Value.Set(Math.Round(ATR(14)[0],2));

            Comment


              #7
              Glad to hear you found a working solution fro you Dan, could you please post or email me the script you tried setting up with the overridden string example I posted? I would then gladly take a look.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              590 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              342 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              555 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X