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

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");
      }
      BertrandNinjaTrader Customer Service

      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.
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by MSerag, 05-06-2024, 11:52 PM
              5 responses
              26 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Aviram Y, Today, 06:03 AM
              0 responses
              1 view
              0 likes
              Last Post Aviram Y  
              Started by Skifree, Yesterday, 11:21 AM
              5 responses
              17 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by hanaewqydow, Today, 06:02 AM
              0 responses
              1 view
              0 likes
              Last Post hanaewqydow  
              Started by tradingnasdaqprueba, Yesterday, 03:42 AM
              10 responses
              37 views
              0 likes
              Last Post tradingnasdaqprueba  
              Working...
              X