Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need code to round double value to integer value

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

    Need code to round double value to integer value

    I want to create a MACD in which the only user input is the slow EMA and the fast EMA is automatically calculated as 90% of the slow. For example, if the user sets the slow EMA at 200, the fast will automatically be calculated as 180.

    Can anyone share any code that will help? Maybe something that will round decimals to integers or convert double values to int values.

    I apologize if I'm not using the correct terminology. Thanks for the help.

    #2
    Hello Tagliareni,

    Thank you for the post.

    You could do this by replacing the existing Fast property to multiply times 0.9. You would also need to remove the line in State.SetDefaults which sets the Fast to have a default value. Your properties would end up looking like the following:


    Code:
    [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptParameters", Order = 0)]
    public int Fast
    { get { return (int)(Slow * 0.9); } }
    
    [Range(1, int.MaxValue), NinjaScriptProperty, RefreshProperties(RefreshProperties.All)]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptParameters", Order = 1)]
    public int Slow
    { get; set; }
    I look forward to being of further assistance.

    Comment


      #3
      Thanks for that awesome response, Jesse. I'll do that now.

      Comment


        #4
        It worked perfectly.

        Thank you for your expert advice.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X