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

Iterate over strategy parameters

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

    Iterate over strategy parameters

    I'd like to be able to create a dump of all my strategy parameters, in much the same way as seen under Strategy Analyser's Settings tab. Yes... I have a lot of parameters ;-)

    Is there a method to iterate over all grid parameters so I can add to my output log?

    Thanks,

    #2
    Hello tgn55,

    Thanks for the post.

    There is not a specific NinjaScript method that I am aware of to gather the properties like this but you could use C# reflection to reflect a type. Are you trying to get the defaults for the properties as well or just a list of properties from that script?

    Also what is the scope of what you want to do, are you specifically trying to dump the parameters that were used in a optimization? You may be able to instead create a custom optimizer for that purpose.


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

    Comment


      #3
      Thanks Jesse.
      I guess this really is more an issue with my indicator... which mostly reflects my strategy, but of course I don't have the SA Settings tab for the indy...
      My code writes trades (even in my indicator ;-) to the output tab... including which setup I used. .I export this to Excel so I can do some further analysis. Having a log of the parameters would be nice.

      In Strategy Analyzer, most of what I want to analyze is of course already there... the exception being which setup triggered the trade. If there was a way to include the entry name as a field/ column in SA that recording this, PLUS the ability to filter on that... that would be sweet. But I suspect that's not happening any time soon! Probably closest I can get is to export the Trades table... or... just save the Output tab contents, as I include the entry name. Back to where I started!

      Summarizing: my real objective is to be able to analyze trades by setup (ie, entry), Trying to find a way to dump all parameters along with that info. Unless you see another solution?

      Thanks...

      Comment


        #4
        Hello tgn55,

        I guess this really is more an issue with my indicator... which mostly reflects my strategy, but of course I don't have the SA Settings tab for the indy...
        My code writes trades (even in my indicator ;-) to the output tab... including which setup I used. .I export this to Excel so I can do some further analysis. Having a log of the parameters would be nice.
        It sounds like you already have some logging in place, you could use reflection to get the properties of that type. That's not a NinjaScript task but C# has that feature and it could be used. That would be if you had a lot of parameters and didn't want to make a string manually that included each parameter, you could loop over the scripts parameters and build a string. Here is the MSDN documentation for that collection: https://docs.microsoft.com/en-us/dot...tframework-4.5
        You could do that on your current instance as well by changing what is shown to use this:

        Code:
        PropertyInfo[] myPropertyInfo = this.GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
        
        for (int i = 0; i < myPropertyInfo.Length; i++)
        {
             Print(myPropertyInfo[i].ToString());
        }
        In Strategy Analyzer, most of what I want to analyze is of course already there... the exception being which setup triggered the trade. If there was a way to include the entry name as a field/ column in SA that recording this, PLUS the ability to filter on that... that would be sweet. But I suspect that's not happening any time soon! Probably closest I can get is to export the Trades table... or... just save the Output tab contents, as I include the entry name. Back to where I started!
        Yes likely using the trades tab would be the only way to see it in a column and export it currently. If there is a specific window which you want to see this in or way you think this could be executed I can put in a feature request.

        Summarizing: my real objective is to be able to analyze trades by setup (ie, entry), Trying to find a way to dump all parameters along with that info. Unless you see another solution?
        If the purpose is to dump information and you specifically are using excel you may want to also take a look at this forum post: https://ninjatrader.com/support/foru...96-ninja-excel that post has a lot of information about using the excel api which could save some time. That is not something I can assist with but the community has been using that for awhile now to interface with excel.

        Otherwise using reflection is likely the easiest way to grab the parameters to help build a string for your log. You can use searches online such as the following which is what lead to the above sample:
        c# get properties of object
        c# get properties of object exclude base


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

        Comment


          #5
          Very cool... thanks heaps Jesse ! Two great threads to follow up on ;-)

          Comment


            #6
            So... finally got around to playing with Reflection... unfortunately, seems it can only print the type/name etc... not values of parameters (according to StackOverflow comments...), and of course, that's exactly what I wanted to do.

            Let me know if you believe otherwise...
            Back to the drawing board, I think...

            Cheers,
            T.

            Comment


              #7
              Originally posted by tgn55 View Post
              So... finally got around to playing with Reflection... unfortunately, seems it can only print the type/name etc... not values of parameters (according to StackOverflow comments...), and of course, that's exactly what I wanted to do. Let me know if you believe otherwise... Back to the drawing board, I think... Cheers, T.
              Replace your print string with this..
              Code:
              Print(myPropertyInfo[i].ToString() + "     =     " + myPropertyInfo[i].GetValue(this, null).ToString());


              -=Edge=-
              NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

              Comment


                #8
                Ah, cool - thanks Edge. I did play with the print string, tried to use GetValue, but was unsure of the args to use.

                Working just fine, now, thanks!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Rapine Heihei, Today, 08:19 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 08:25 PM
                0 responses
                5 views
                0 likes
                Last Post Rapine Heihei  
                Started by f.saeidi, Today, 08:01 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 07:51 PM
                0 responses
                6 views
                0 likes
                Last Post Rapine Heihei  
                Started by frslvr, 04-11-2024, 07:26 AM
                5 responses
                98 views
                1 like
                Last Post caryc123  
                Working...
                X