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

Extract Start Date and End Date for Optimization Fitness

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

    Extract Start Date and End Date for Optimization Fitness

    Hello, I want to build an optimization fitness that uses Start Date and End Date that is set manually in Strategy Analyzer's settings.

    I want to use that and not Minimum Trade Date and Maximum Trade Date, because for strategies with low trade numbers, there may not be enough data to get correct Start and End date.

    So how can I do that?

    #2
    Hello UltraNIX,

    There are no documented properties for this.

    I've done some searching but haven't found anything undocumented on the forums I feel would answer this question.

    I will put in a feature request on your behalf for the development to consider supporting this.
    Once I have a tracking ID for this request I will post in this thread for future reference.

    In the meantime, you could record the first processed tick, and last processed tick datetimes.. It depends on how and when you want to use this information. Do you want the end date while processing the first few bars?

    Are you wanting these values in the strategy itself, or the optimization script?
    Last edited by NinjaTrader_ChelseaB; 04-04-2021, 09:45 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello UltraNIX,

      There are no documented properties for this.

      I've done some searching but haven't found anything undocumented on the forums I feel would answer this question.

      I will put in a feature request on your behalf for the development to consider supporting this.
      Once I have a tracking ID for this request I will post in this thread for future reference.

      In the meantime, you could record the first processed tick, and last processed tick datetimes.. It depends on how and when you want to use this information. Do you want the end date while processing the first few bars?

      Are you wanting these values in the strategy itself, or the optimization script?
      Optimization script. Idea behind it is to find difference between two manually set dates and then count average trades per working day using such formula: Total Trade Count [number of trades] / (End Date - Start Date) * (260 [working days in a year] / 365 [total days in a year]. Maybe I can achieve similar results using Average Trades Per Day that is already built-in Ninja, then I would need to have a formula how it is calculated.

      Comment


        #4
        Hello UltraNIX,

        NinjaTrader_Jim suggested using the strategy.Bars of the iteration instance.

        Print(strategy.Bars.FromDate);
        Print(strategy.Bars.ToDate);

        Will this suffice?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I cannot test.

          I try to compile and it always gives me this error:
          NinjaScript File Error Code Line Column
          \NETFramework,Version=v4\5\AssemblyAttributes.cs Duplicate 'global::System.Runtime.Versioning.TargetFramework Attribute' attribute CS0579 4 12
          I downloaded .NET 6.0 Runtime (v6.0.0-preview.2) - Windows x64 Installer, also, the latest version of NinjaTrader, reinstalled it, but it still gives me that error.

          It started giving me this error, when I used Visual Studio 2019 after some 2 months and it gave me a popup to "Rename to 4.8" or something, I don't remember exactly. And now it doesn't even compile in Visual Studio as well. Something's messed up, please, help me to fix it.

          Comment


            #6
            Reinstalled NinjaTrader.

            Yes, it works, thank you very much!

            Comment


              #7
              However, if I try to convert timespan between two dates into Int32, I got this error:
              Code:
              Strategy 'AI_EXV_MES_210111_O/-1': Error on calling 'GetPerformanceValue' method: Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.
              My Int32 code for timespan between 2 dates is:
              Code:
              Convert.ToInt32(strategy.Bars.ToDate - strategy.Bars.FromDate)
              How can this be solved?

              Comment


                #8
                Hello UltraNIX,

                If you want to convert a DateTIme to an integer you can use ToTime() / ToDay().



                I don't think those two objects will cast directly though.. You could make a method that makes your own int similar to how ToTime works if that is inadequate.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello UltraNIX,

                  If you want to convert a DateTIme to an integer you can use ToTime() / ToDay().



                  I don't think those two objects will cast directly though.. You could make a method that makes your own int similar to how ToTime works if that is inadequate.
                  Not able to make my own method here, tried to browse through references, but I could not find anything that could match. Can you help me?

                  Comment


                    #10
                    Hello UltraNIX,

                    Also, subtracting dates would use <DateTime>.Subtract().
                    https://docs.microsoft.com/en-us/dot...t?view=net-5.0
                    Code:
                    Print( [B]ToDate[/B]( strategy.Bars.ToDate.Subtract(strategy.Bars.FromDate) ) );
                    Is this causing a compile error or not printing the subtracted date?
                    Last edited by NinjaTrader_ChelseaB; 04-06-2021, 01:46 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Not sure why, but error was caused by this part of formula: (260/365). In this part of formula, I am counting working days per year. But it returns 0 and this gives error of division by 0.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by yertle, Yesterday, 08:38 AM
                      7 responses
                      28 views
                      0 likes
                      Last Post yertle
                      by yertle
                       
                      Started by bmartz, 03-12-2024, 06:12 AM
                      2 responses
                      20 views
                      0 likes
                      Last Post bmartz
                      by bmartz
                       
                      Started by funk10101, Today, 12:02 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post funk10101  
                      Started by gravdigaz6, Yesterday, 11:40 PM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by MarianApalaghiei, Yesterday, 10:49 PM
                      3 responses
                      10 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X