Announcement

Collapse
No announcement yet.

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.

    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 NullPointStrategies, Today, 05:17 AM
      0 responses
      44 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      65 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X