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

Optimizing Custom Value in Strategy in NinjaScript Editor

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

    Optimizing Custom Value in Strategy in NinjaScript Editor

    Hi again,

    I have a Bollinger band equation that is functioning correctly. However, I am trying to change the last value at the end of the equation to a variable, so that I can optimize it within the strategy analyzer tool, and have been having some trouble.

    As I have it set up now, there is a parameter, and it allows me "optimize" it, but nothing actually happens. Somehow it is not interpreting the variable changing. (the variable is "Bbx")
    This is the code I have:

    This is the function that is working and calculating correctly with a fixed value (backtests produce various results when I change the value), I am trying to optimize the value ".2" at the end of the equation
    ((((Bollinger(2,20).Upper[0]) - (Bollinger(2,20).Lower[0])) / (Bollinger(2,20).Upper[0])) * 100 >= .2)


    This is the function that I have been trying to optimize by: (I have also tried putting "Bbx/100" in its own parentheses)
    ((((Bollinger(2,20).Upper[0]) - (Bollinger(2,20).Lower[0])) / (Bollinger(2,20).Upper[0])) * 100 >= Bbx/100 )

    I have it as (Bbt/100) because I read that only integers can be optimized as custom values, so I used (Bbx/100) to produce the desired decimal value for the strategy

    This is the code I have under the properties region for Bbx under strategy parameters:

    [NinjaScriptProperty]
    [Range(int.MinValue, int.MaxValue)]
    [Display(Name="Bbx", Order=5, GroupName="Custom Calculations")]
    public int Bbx
    { get; set; }

    I have also tried:

    [NinjaScriptProperty]
    [Range(int.MinValue, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource), Name= "Bbx", Order=5, GroupName= "Custom Calculations")]
    public int Bbx
    { get; set; }

    I also have the default value already set under: if (State == State.SetDefaults)

    Whenever I try to optimize, I get the same value for Bbx over and over (even when I make it the only optimizable parameter).

    How can I fix this?

    #2
    Hello thereyoflite,

    Thanks for your post.

    Do you get different results when using a double so the value is not converted to an integer?

    When use prints to output how the condition is evaluating, what are the values of the following when you change the optimization parameter?

    I.E. how does the following evaluate?
    • (((Bollinger(2,20).Upper[0]) - (Bollinger(2,20).Lower[0])) / (Bollinger(2,20).Upper[0])) * 100)
    • (Bbx/100)

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    I look forward to hearing from you.
    JimNinjaTrader Customer Service

    Comment


      #3

      Thanks for your reply,

      I have not printed the values, I was inputting manually and compiling then running a back test each time to see if I could generate different results. The variable itself is valid, as I tested manually outside of the equation. That leads me to believe that the error is within the equation itself. I am trying to see how I can print the two parts of the equation which you provided

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kujista, Today, 06:23 AM
      4 responses
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by traderqz, Yesterday, 09:06 AM
      2 responses
      16 views
      0 likes
      Last Post traderqz  
      Started by traderqz, Today, 12:06 AM
      3 responses
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by f.saeidi, Today, 08:13 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X