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 helpwanted, Today, 03:06 AM
        0 responses
        3 views
        0 likes
        Last Post helpwanted  
        Started by Brevo, Today, 01:45 AM
        0 responses
        6 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X