Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Testing enums values work as expected in standard backtest, but not in optimization

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

    Testing enums values work as expected in standard backtest, but not in optimization

    Hi, I have an enum which I can successfully test the value selected in a standard backtest. However, when I run an optimization things do not work as expect. I am 99% sure this is due to my not knowing how to compensate for the change enum selectors undergo when an optimization is chosen. (this change is visually obvious - for a "Standard" Backtest an enum selector is in form of a dropdown style menu, whereas for an 'Optimization' the selector for an enum automatically changes to checkbox values for each enum option)

    The change is apparently enough that my tests against selected enum values is not working during an optimization, even though I can see that the optimizer itself is iterating through the checkbox values. Basically, I think I just need to know how to reference the optimizer checkbox values, but I do not know how to do this. Any help would be greatly appreciated!

    #2
    Hello Calebg,

    From your code you would not have to do anything different to utilize the optimized value similar to the other properties you made. Can you provide a specific example of what you tried that is not working?

    The general process to use an enum would be as follows:

    You can use the enum from this indicator sample as a test: https://ninjatrader.com/support/help...ned_parame.htm

    The property in a strategy would then look like:

    Code:
    [Display(GroupName = "Parameters", Description="Choose a Moving Average Type."), NinjaScriptProperty]
    public CustomEnumNamespace.UniversalMovingAverage MAType
    {
         get;set;
     }
    and if you printed the value in an optimization:
    Code:
    protected override void OnStateChange()
    {
       else if (State == State.DataLoaded)
       {
           Print(MAType);
        }
    }
    Assuming a few of the check boxes were checked, we should see results like:

    Code:
    EMA
    WMA
    SMA
    EMA

    I look forward to being of further assistance.

    Comment


      #3
      Sorry ahead of time for an abbreviated reply, but I decided to punt using enums all together, because for a couple months running I have been running into various hassles around them. For my own personal development I'll probably classify them as 'not the right tool for the job, more often than not' and make every effort to find a different structure to work with. In this case I just replace the enum with a 'standard' manual parameter input box which accepts a certain range of integer values. This makes the code not as readable I guess, but it was instantly worth it just to not have to deal with enums and now everything is working as expected.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X