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

What does Cbi mean ?

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

    What does Cbi mean ?

    Hi there,

    When trying to develop my custom Optimization Fitness in NT8, I checked the Max Strength Fitness in NT 8, and there is a line like this:

    Code:
    Cbi.TradeCollection trades = strategy.SystemPerformance.AllTrades;
    I guess the whole line is to store information with all trades (all relevant, like number of trades, long trades, shorts trades, profit & loss etc) in the variable "trades" ? But I can nowhere find the specific explanation of "Cbi" (by googling and NT8 reference), any definition on this?

    Thank you !

    #2
    So, what I want is a SQN (System Quality Number) defined as:

    SQN=Sqrt(Number of Trades) * AverageProfit&Loss / StdDev(profit of All trades)

    Code:
    Cbi.TradeCollection trades= strategy.SystemPerformance.AllTrades;
    
    Value=Math.Sqrt(trades.TradesCount)*strategy.SystemPerformance.AllTrades.TradesPerformance.Percent.AverageProfit/strategy.SystemPerformance.AllTrades.TradesPerformance.Percent.StdDev;
    Will this code get what I want? or I have to calculate every trade's profit to give a StdDev?
    Last edited by wolfcuring; 05-30-2019, 02:34 AM.

    Comment


      #3
      Hello wolfcuring, thanks for your post.

      Cbi stands for Common broker interface. Cbi is undocumented, so I don't have any first-hand information on the namespace. The TradePerformance class is documented among other items in Cbi.

      Any account item within AllTrades.TradesPerformance will be in terms of all trades summed together for that optimization period. If you print something out within OnCalculatePerformanceValue you will see the print occur for each optimization of the strategy. Please verify the output by printing out Value at the end of OnCalculatePerformanceValue and compare the output to a test set of data that is verified, e.g.

      Code:
      protected override void OnCalculatePerformanceValue(StrategyBase strategy)
      {
      if(strategy.SystemPerformance.AllTrades.TradesPerformance.Percent.StdDev == 0)
                      return;
      Cbi.TradeCollection trades= strategy.SystemPerformance.AllTrades;
      Value=Math.Sqrt(trades.TradesCount)*strategy.SystemPerformance.AllTrades.TradesPerformance.Percent.A verageProfit/strategy.SystemPerformance.AllTrades.TradesPerform ance.Percent.StdDev;
      Print(Value);
      }
      I look forward to hearing of your results.
      Last edited by NinjaTrader_ChrisL; 05-31-2019, 01:42 PM.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Hi Chris,

        The SQN worked as expected. while the "protected override void OnCalculatePerformanceValue(StrategyBase strategy)" throw an error like this:
        Code:
         [TABLE="border: 0, cellpadding: 0, cellspacing: 0"]
        [TR]
        [TD="width: 943"]NinjaTrader.NinjaScript.Strategies.M3.OnCalculatePerformanceValue(NinjaTrader.NinjaScript.StrategyBase)': no suitable method found to override[/TD]
         		[/TR]
        [/TABLE]

        Comment


          #5
          Hello wolfcuring, thanks for your reply.

          The error indicates you are overriding OnCalculatePerformanceValue in a Strategy, this method belongs to the NinjaTrader.NinjaScript.OptimizationFitnesses namespace only. I made a test out of your formula you posted, place the attached file within Documents\NinjaTrader 8\bin\Custom\OptimizationFitnesses. In the strategy analyzer, set to run an optimization and set "Optimize on" to SQNTest.

          Kind regards.
          Attached Files
          Last edited by NinjaTrader_ChrisL; 05-31-2019, 01:43 PM.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChrisL View Post
            Hello wolfcuring, thanks for your reply.

            The error indicates you are overriding OnCalculatePerformanceValue in a Strategy, this method belongs to the NinjaTrader.NinjaScript.OptimizationFitnesses namespace only. I made a test out of your formula you posted, place the attached file within Documents\NinjaTrader 8\bin\Custom\OptimizationFitnesses. In the strategy analyzer, set to run an optimization and set "Optimize on" to SQNTest.

            Kind regards.
            You probably want to correct the code to account for/escape a division by zero. StdDev can be zero, if there is no trade, or if all trades return the exact same profit (unlikely, true).

            Comment


              #7
              Thanks for the catch koganam, posts have been edited to reflect the change.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Thank for your code Chris, and many thanks to Koganam for your advice, I will add a line to my original code to avoid the zero condition.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by 00nevest, 04-27-2024, 02:27 PM
                3 responses
                27 views
                0 likes
                Last Post 00nevest  
                Started by Newtrader101, Today, 07:36 AM
                0 responses
                1 view
                0 likes
                Last Post Newtrader101  
                Started by 21laienoch, Today, 07:25 AM
                0 responses
                6 views
                0 likes
                Last Post 21laienoch  
                Started by burtoninlondon, 04-28-2024, 12:38 AM
                1 response
                16 views
                0 likes
                Last Post burtoninlondon  
                Started by MacDad, 02-25-2024, 11:48 PM
                8 responses
                175 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X