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().


        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.

                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.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by jclose, Today, 09:37 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post jclose
                      by jclose
                       
                      Started by WeyldFalcon, 08-07-2020, 06:13 AM
                      10 responses
                      1,413 views
                      0 likes
                      Last Post Traderontheroad  
                      Started by firefoxforum12, Today, 08:53 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post firefoxforum12  
                      Started by stafe, Today, 08:34 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post stafe
                      by stafe
                       
                      Started by sastrades, 01-31-2024, 10:19 PM
                      11 responses
                      169 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X