• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable Accessible by Custom Performance Metric

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

    Variable Accessible by Custom Performance Metric

    Hi, I created a multi instrument strategy that has a variable that keeps track of the total profit from the trades that are made across all of the different instruments. I want to optimize based on this total profit variable so I am trying to create a performance metric that accesses this variable. How do I import that variable into my custom performance metric? I have tried Strategies[0].Account_bal_calc (among random other attempts), but it returns an error. I have made the variable accessible (I think) by adding this to the properties of the strategy:

    [Browsable(false)]
    [XmlIgnore]
    public double Account_bal_calc
    {
    get { Update(); return Account_balance_calc; } // Allows our public BearIndication Series<bool> to access and expose our interal bearIndication Series<bool>
    }

    #2
    Hello dpappyp,

    While the strategy instance is provided to OptimizationFitness scripts in OnCalculatePerformanceValue(), I am not aware of a way to access the collection of strategy instances from a PerformanceMetric script.

    I will further research this and I will let you know what I find.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      What would be the correct OptimizationFitness code for my example? :

      OnCalculatePerformanceValue().Account_bal_calc ?

      Comment


        #4
        Hello dpappyp,

        Below is a public link to the help guide on OnCalculatePerformanceValue().
        https://ninjatrader.com/support/help...mancevalue.htm

        The strategy instance is provided by the override's parameters and needs to be casted as the exact script type and then you can access any properties of that strategy instance.

        As an example if you were to do this with the SampleMACrossOver.

        Code:
        protected override void OnCalculatePerformanceValue(StrategyBase strategy)
        {
        	NinjaTrader.NinjaScript.Strategies.SampleMACrossOver mystrat = strategy as NinjaTrader.NinjaScript.Strategies.SampleMACrossOver;
        
        	Print(mystrat.Fast);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Beautiful! I can optimize on my in strategy variable now! Thanks!

          Comment


            #6
            Hello dpappyp,

            Previous you were inquiring about accessing the collection of strategy instances for a PerformanceMetric script that puts a statistic in the summary.

            Are you no longer wanting to do this?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes, I would still like to do that as well

              Comment


                #8
                Hello dpappyp,

                Thank you for your patience.

                I am looking into your original inquiry further.
                Originally posted by dpappyp View Post
                Hi, I created a multi instrument strategy that has a variable that keeps track of the total profit from the trades that are made across all of the different instruments. I want to optimize based on this total profit variable so I am trying to create a performance metric that accesses this variable. How do I import that variable into my custom performance metric? I have tried Strategies[0].Account_bal_calc (among random other attempts), but it returns an error. I have made the variable accessible (I think) by adding this to the properties of the strategy:

                [Browsable(false)]
                [XmlIgnore]
                public double Account_bal_calc
                {
                get { Update(); return Account_balance_calc; } // Allows our public BearIndication Series<bool> to access and expose our interal bearIndication Series<bool>
                }
                I would like to ask why the 'Total net profit' does not provide the value you need in your Performance results?
                How is your custom 'Account_bal_calc' calculated? Are the multiple instruments in the code or is this a basket test on an Instrument List?

                I look forward to your response.
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Wait, can I create order entries against the other instruments that I load into a strategy? I thought that you could only enter orders against the main instrument that the strategy was run against? I created data series to keep track of virtual orders against the other instruments and to calculate a cumulative net profit

                  Comment


                    #10
                    The order entry sizes are based on the account balance so I need to keep a running total. I also have arrays with dividend payout dates and amounts that I add to the running account total if I am long in those instruments on those dividend dates. I'm not sure if I can do all that without keeping track of entries and exits manually.

                    Comment


                      #11
                      Hello dpappyp,

                      Thank you for your response.

                      You can in fact enter and exit on the added instruments in your strategy. Please refer to our documentation on this at the following link: https://ninjatrader.com/support/help...nstruments.htm

                      Please let me know if you have any questions.
                      Patrick H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by digibob, Today, 10:01 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post digibob
                      by digibob
                       
                      Started by ptertich, Today, 09:59 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post ptertich  
                      Started by sledge, Today, 06:11 PM
                      1 response
                      8 views
                      0 likes
                      Last Post sledge
                      by sledge
                       
                      Started by Bionian, Today, 02:46 PM
                      2 responses
                      9 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by rwilliam, Today, 01:54 PM
                      1 response
                      19 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X