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

How to allow user to enter/edit parameter as currency

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

    How to allow user to enter/edit parameter as currency

    I would like to allow the user of my strategy to enter/edit a parameter that is a currency. For example, lets say the following were displayed in my parameters list:
    MaxDailyLoss $000.00
    If 400 (with or without $) were typed and tab or return key pressed $400.00 would be displayed and a double variable in my code would be filled with 400.00. I can think of several ways this could be done. Just looking for the best or NT friendly way.

    #2
    Originally posted by bernie_c View Post
    I would like to allow the user of my strategy to enter/edit a parameter that is a currency. For example, lets say the following were displayed in my parameters list:
    MaxDailyLoss $000.00
    If 400 (with or without $) were typed and tab or return key pressed $400.00 would be displayed and a double variable in my code would be filled with 400.00. I can think of several ways this could be done. Just looking for the best or NT friendly way.
    Parse a string into a double, but display the Property as the string?

    Comment


      #3
      Hello,

      Thank you for the question.

      If you absolutely need the $ in the field where you type the value, I would agree with koganam on parsing a string into a double.

      Otherwise another solution would be to put the $ in the parameter name, here is a simple example parameter:

      Code:
      private double maxDailyLoss;
      		
      [Description("")]
      [GridCategory("Parameters")]
      [Gui.Design.DisplayName("MaxDailyLoss $")]
      public double MaxDailyLoss
      {
      	get{ return maxDailyLoss;} set{ Math.Max(1, value);}
      }
      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Koganam,
        This code snippet is what I tried before starting this thread. I was certain it would work, however, the quoted exception is thrown. Is this what you meant by "parse"?
        Code:
        [Description( "" )]
        [GridCategory("c Parameters")]
        [Gui.Design.DisplayName ("       Dollars")]
        public string Dollar_str
        {
            get { return dollar_str; }
            set { 			
                             dollar_num   = Double.Parse( value );
        		     dollar_str	= dollar_num.ToString(); 
        	  }	
        }
        **NT** Error on getting/setting property 'Dollar_str' for strategy 'bcSm/296c35a0a40e426db1b2c74ab9323fb0': Exception has been thrown by the target of an invocation.

        Comment


          #5
          Originally posted by bernie_c View Post
          Koganam,
          This code snippet is what I tried before starting this thread. I was certain it would work, however, the quoted exception is thrown. Is this what you meant by "parse"?
          Code:
          [Description( "" )]
          [GridCategory("c Parameters")]
          [Gui.Design.DisplayName ("       Dollars")]
          public string Dollar_str
          {
              get { return dollar_str; }
              set { 			
                               dollar_num   = Double.Parse( value );
          		     dollar_str	= dollar_num.ToString(); 
          	  }	
          }
          That depends on whether the currency symbol is a part of your string. In which case, you have to specify "NumberStyles".

          Comment


            #6
            Here is what worked:
            Code:
            get { return dollar_str; }
            set { 			
            	dollar_num = Double.Parse( value, NumberStyles.Number | NumberStyles.AllowCurrencySymbol );
            				
            	dollar_str	 = dollar_num.ToString( "C", new System.Globalization.CultureInfo("en-US") );
                   }
            I had tried using NumberStyles earlier, but was getting compile errors because my using statements were not right. All is good now though.

            Thanks again Koganam.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ZenCortexCLICK, Today, 04:58 AM
            0 responses
            5 views
            0 likes
            Last Post ZenCortexCLICK  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            172 responses
            2,280 views
            0 likes
            Last Post sidlercom80  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            18 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            7 views
            0 likes
            Last Post adeelshahzad  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X