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

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

    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 cshox, Today, 11:11 AM
        0 responses
        3 views
        0 likes
        Last Post cshox
        by cshox
         
        Started by TAJTrades, Today, 11:03 AM
        0 responses
        3 views
        0 likes
        Last Post TAJTrades  
        Started by wuannetraam, Today, 02:40 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by jjs12, Today, 10:29 AM
        2 responses
        13 views
        0 likes
        Last Post jjs12
        by jjs12
         
        Started by Ludwik, Today, 03:52 AM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X