Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimizing on Time

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

    Optimizing on Time

    Hi

    Struggling a bit with this, I'm trying to optimize on time - so the system buys @ 9:00am or 10:00am etc
    The strategy works fine with default values but once I tried to optimize I realized I could not.

    So it seems I can optimize on integers but not time, so I changed the code in if (State == State.SetDefaults)
    to go from
    OpenTime = DateTime.Parse("09:00", System.Globalization.CultureInfo.InvariantCulture) ;
    CloseTime = DateTime.Parse("14:00", System.Globalization.CultureInfo.InvariantCulture) ;


    Didnt work:
    OpenTime = new DateTime( 2018, 01, 01, OptimStr, 0, 0);
    CloseTime = new DateTime( 2018, 01, 01, OptimStp, 0, 0);

    I also tried this - but also didnt work
    OpenTime = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture) .AddHours(OptimStr);
    CloseTime = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture) .AddHours(OptimStp);


    What does work:
    OpenTime = new DateTime( 2018, 01, 01, 9, 0, 0);
    CloseTime = new DateTime( 2018, 01, 01, 14, 0, 0);

    How come if the 14 is changed from 14 to "OptimStp" then it stops working?
    The values on the Strategy Analyser is 9 and 14 as well.
    Everytime I try to print out anything the Output window clears if I run the backtest so I can never seem to print out to a log.


    Indicator code:
    [NinjaScriptProperty]
    [Range(0, 24)]
    [Display(Name="OptimStr", Description="OptimStr", Order=1, GroupName="Parameters")]
    public int OptimStr { get; set; }

    [NinjaScriptProperty]
    [Range(0, 24)]
    [Display(Name="OptimStp", Description="OptimStp", Order=2, GroupName="Parameters")]
    public int OptimStp { get; set; }

    #2
    Hello bchip,

    Thanks for your post.

    Where else are updating your DateTime variables? If you are only setting these in State.SetDefaults, I would not expect this to effect the optimization. If you update your DateTime variables in OnStateChange under State.DataLoaded or State.Configure, I would expect these variables to be updated from the Optimizer. SetDefaults is simply used to assign default parameter values, so they will not update as the optimization modifies a variable.

    If you are seeing something different, could you attach a simple example that demonstrates what you have set up exactly?

    I look forward to being of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi

      Yes my problem was that the values for OptimStr & OptimStp was in the State.SetDefaults
      I changed it to State.Configure and it works now.

      Thank you

      Comment


        #4
        A working example for the community on optimizing time.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kujista, Today, 06:23 AM
        5 responses
        15 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by f.saeidi, Today, 10:19 AM
        0 responses
        4 views
        0 likes
        Last Post f.saeidi  
        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  
        Working...
        X