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

TradesPerformance Class 'MaxConsecLoser'

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

    TradesPerformance Class 'MaxConsecLoser'

    Let me say : great work in giving access to trade performance data from within a system on onbarupdate.

    So here's some issues:

    1)
    I am working on a system with 6.5.0.4 that dynamically changes my default quantity to reflect the # of consecutive losers in a historical backtest.

    Problem: MaxConsecutiveLosers when used in this context only shows me the max during the entire life of a backtest:

    performance.alltimetrades.tradesperformance.maxcon seclosers


    I'd instead like a way to determine the # of consecutive losers at any state of a backtest (ie if I am in a big losing streak, at a certain point it is wise to substantially increase size as the probability of it continuing becomes less). I need to be able to draw upon the current losing or winning streak #s.

    So is there a 'consecutiveloser' instead of 'maxconsecutiveloser' variable, or a way to replicate it?




    2)
    another issue: when backtesting a strategy, the cumulative profit/loss graph is reflective of defaultquantity remaining fixed. Is there a way to factor the drawdowns and cumulative profits in an accurate way with variable quantity size yet? Or is this on the to do list?

    #2
    Will respond to this by tomorrow.
    RayNinjaTrader Customer Service

    Comment


      #3
      Unfortunately this is not supported. We'll add it to the list. Thanks for your suggestions.

      Comment


        #4
        Well I figured out a way around it to anyone that wants this sooner than later:

        (region variables

        privateint tradecounter = 0;
        privateint consecwinner = 0;
        privateint consecloser = 0;

        (onbarupdate
        Trade firstTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];

        if (Performance.AllTrades.Count > tradecounter)
        {
        if (firstTrade.ProfitCurrency >= 0)
        { tradecounter = tradecounter +
        1;
        consecwinner = consecwinner +
        1;
        consecloser =
        0; }
        else { tradecounter = tradecounter +1;
        consecloser = consecloser +
        1;
        consecwinner =
        0; };
        }
        else
        tradecounter = Performance.AllTrades.Count;
        // for debugging
        Print("l:" + consecloser + " w:" + consecwinner + " tradecount variable:" + tradecounter);


        So the only problem that remains is drawdown and cumulative profit charts in the strategy analyzer.

        Comment


          #5
          Add Consecutive Losers, Consecutive Winners as method/function to library

          thank you for sharing your solution!

          Ideally, rather than integrating this code with each strategy. What is the best way to set this up as a method (function, whatever they call functions these days, grrrr) so that it can be easily called from within a strategy?

          I am more of a kludger than a programmer, so a brief outline would be extremely helpful if you or anyone can lend a hand!

          The idea would be

          if (maxconlosers)
          {
          //increase default amount by whatever for next trade.
          }

          This way, if I am on a losing streak, I can really hammer my account down! lol

          [UPDATE]
          Also, noob question. The line below is throwing an error. I wrapped it in a try/catch (although I don't know how to show the error (yet)). Anyway, the word Trade does not show up in blue, but when I mouse over, it does say NinjaTrader.Strategy.Trade or whatever, so some intellisense is working. Do I need to include something up top in the Declarations? The usual suspects are there.

          Trade firstTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];


          The line


          Thanks


          R2Ktrader
          Last edited by r2kTrader; 02-20-2009, 04:33 PM.

          Comment


            #6
            Hello,

            To set it up as a function just do something like this below the OnBarUpdate() block:

            private int FindMaxLosers(...you may want some parameters here...)
            {

            //some code here to find the max losers and assign it to a variable...say
            //my_losers and return that count as an int

            return my_losers;

            }

            Then within the OnBarUpdate() block just call FindMaxLowers() like this, for example:

            int loser_count = FindMaxLosers();

            Also, this link my help:


            Note: I did not study the code posted below your post, but this should answer you question generally.
            DenNinjaTrader Customer Service

            Comment


              #7
              Ben,

              Thank you for the reply. I am actually reading/studying C# so my questions can make more sense. (http://www.csharp-station.com is a great free primer)

              What I want to do, is have a library that is centralized and then be able to call in a method/function, etc. from within my strategies and indicators.

              For example, my money management library should be centralized and then I can just pass data back and forth from within the strategy and have a standard setup that I use when I build a new strategy.

              So my question is, where/how do i put everything? Do I setup a class with methods and then use intellisense from within my strat/ind?

              I'm figuring it out. It's not brain surgery, but if there was an example that showed how to do it, it would go a long way to bridging what I am reading on csharp-station.com (tutorial) and how ninja approaches things.

              Thanks NT!


              R2Ktrader

              Comment


                #8
                You may consider locating your "centralized" logic in the UsreDefinedMethods file.

                You certainly could go beyond that and build your own "library". However, this would be outside the scope of what we support nor do we recommend it. You would be on your own.

                Comment


                  #9
                  UserDefinedFunctions was what I was looking for. hence my virtual "library". I just wanted to centralize the functions for risk/trade management.

                  Thanks!


                  r2kTrader

                  Originally posted by NinjaTrader_Dierk View Post
                  You may consider locating your "centralized" logic in the UsreDefinedMethods file.

                  You certainly could go beyond that and build your own "library". However, this would be outside the scope of what we support nor do we recommend it. You would be on your own.

                  Comment


                    #10
                    getting issue when addig Trade firsttrade and Trade lastTrade

                    Hi,

                    I'm getting issue when using the Trade

                    protectedoverridevoid OnBarUpdate()
                    {
                    Trade firstTrade = Performance.AllTrades[0];
                    Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count -
                    1];

                    as described in the manual. I'd like to include these in order to track each trade performance in the output file.


                    1) First of all the word Trade does not appear in blue as it is in the Manual.

                    2) If I include these lines, my backtest does not work all all. There is NO trade. If I remove them, it works.

                    Any idea? Thanks.

                    Comment


                      #11
                      Jean,

                      The word does not need to be in blue. Please check your Control Center logs for errors.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Josh View Post
                        Jean,

                        The word does not need to be in blue. Please check your Control Center logs for errors.
                        I've check the Log

                        The issue is with the Index. The message is in french in my log file (I'm french) . I i translate it into English it would be something like

                        Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the connection size.

                        I guess it happens when there is still no trade (
                        Performance.AllTrades.Count - 1) would then be negative. I've replaced it by

                        int Counter=Math.Max(0,Performance.AllTrades.Count - 1);


                        Trade lastTrade = Performance.AllTrades[Counter];

                        but it did not work either. Any idea?

                        When I remove the two "Trade" lines it works, but then I'm not able to get the information I'd like to get on trade performance.


                        Comment


                          #13
                          Originally posted by Jean-Marc-Molina View Post
                          I've check the Log

                          The issue is with the Index. The message is in french in my log file (I'm french) . I i translate it into English it would be something like

                          Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the connection size.

                          I guess it happens when there is still no trade (
                          Performance.AllTrades.Count - 1) would then be negative. I've replaced it by

                          int Counter=Math.Max(0,Performance.AllTrades.Count - 1);


                          Trade lastTrade = Performance.AllTrades[Counter];

                          but it did not work either. Any idea?

                          When I remove the two "Trade" lines it works, but then I'm not able to get the information I'd like to get on trade performance.


                          sorry : in the log message ...
                          Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the collection size.
                          .

                          Comment


                            #14
                            Originally posted by Jean-Marc-Molina View Post
                            sorry : in the log message ...
                            Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the collection size.
                            .
                            BTW thank you for the quick answer.

                            Maybe you could Email me a code that works wth the Trade declaration and I'll figure out what's the issue.

                            Comment


                              #15
                              Jean-Marc-Molina,

                              The issue is not with that particular line, it is actually with the first line. Since you do not have a first trade yet you cannot access it. Perhaps this thread will help: http://www.ninjatrader-support2.com/...t=14287&page=2
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by egordleo, Today, 05:50 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post egordleo  
                              Started by kevinenergy, 02-17-2023, 12:42 PM
                              118 responses
                              2,778 views
                              1 like
                              Last Post kevinenergy  
                              Started by briansaul, Today, 05:31 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post briansaul  
                              Started by fwendolynlpxz, Today, 05:19 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post fwendolynlpxz  
                              Started by traderqz, Yesterday, 12:06 AM
                              11 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X