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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        44 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        54 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        34 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        95 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        57 views
        0 likes
        Last Post PaulMohn  
        Working...
        X