Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Profit and Loss series in back test

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

    Profit and Loss series in back test

    Need to access past ProfitAndLoss series (f.e. daily, or of past trades) from within the strategy.
    How can I do it?

    Nik

    #2
    Hello,

    These are your options with trade performance statistics:


    Or is this what you are looking for:
    DenNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ben View Post
      Hello,

      These are your options with trade performance statistics:


      Or is this what you are looking for:
      http://www.ninjatrader-support.com/H...rofitLoss.html
      the first one.
      thanks a lot.

      Nik

      Comment


        #4
        Hello,

        I have another question:
        is it possible to feed PnL series into Indicator?

        Nik

        Comment


          #5
          Nik, unfortunately this is not supported.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            after a while I have succeeded to make what i wanted.

            In short program looks like this:

            using System.Collections;

            namespace NinjaTrader.Strategy
            {
            ///<summary>
            /// Enter the description of your strategy here
            ///</summary>
            [Description("Dumb strategy")]
            public class myDumbStrategy : Strategy
            {

            #region Variables
            .
            private ArrayList vecPnL = null;
            private ArrayList cumPnL = null;
            int lastTradeIndex=0;
            .
            #endregion
            protected override void Initialize()
            {
            .
            vecPnL = new ArrayList();
            cumPnL = new ArrayList();
            lastTradeIndex=0;
            .

            }

            protected override void OnBarUpdate()
            ...
            if(ToDay(Time[0])!=ToDay(Time[1])) {
            //Print("Today " + ToDay(Time[1]));
            double pnl=0;
            for(int k=lastTradeIndex;k<Performance.AllTrades.Count;k++ ) {
            if(ToDay(Time[1])==ToDay(Performance.AllTrades[k].Entry.Time)) {
            pnl+=Math.Round(Performance.AllTrades[k].ProfitCurrency,2);

            }; // end-if
            }; // end-for
            vecPnL.Add(pnl);
            if(vecPnL.Count>1) cumPnL.Add(pnl+(double)cumPnL[cumPnL.Count-1]);
            else cumPnL.Add(pnl);
            lastTradeIndex = Performance.AllTrades.Count-1;
            ...
            } // Day
            ...
            } // onUpdate
            ...
            } // dumbStrategy

            maybe some lines are missing, but I hope the idea is clear.


            Another question:

            How to Print() out of Indicator into Output screen?
            Last edited by nikkk; 01-27-2010, 08:52 AM.

            Comment


              #7
              nikkk, you could just use the Print() command for this, then open the output window from Control Center > Tools.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                nikkk, you could just use the Print() command for this, then open the output window from Control Center > Tools.
                I see. My problem is that I have created a special object which contains library of various stat.functions:

                namespace NinjaTrader.Indicator {
                public class StatLib
                {
                public static double Freq(double x) {
                ... calculated Frequency integral ...
                }
                and others
                }

                from Strategy code I simply use

                ...
                StatLib.Freq(y);
                ...

                sometimes these functions I need to debug
                Last edited by nikkk; 01-27-2010, 11:00 AM.

                Comment


                  #9
                  You could also add Print() statements to those convenience functions / methods then for debugging.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    You could also add Print() statements to those convenience functions / methods then for debugging.
                    when I do, compiler says:
                    The name "Print" does not exist in the current context

                    Comment


                      #11
                      Is this liberay created in NinjaScript or loaded externally via DLL assembly?

                      If in NinjaScript please provide a exact sample call of the Print function you were attempting to use.

                      Thanks
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        Is this liberay created in NinjaScript or loaded externally via DLL assembly?

                        If in NinjaScript please provide a exact sample call of the Print function you were attempting to use.

                        Thanks
                        here is an Indicator called MyLib

                        #region Using declarations
                        using System;
                        using System.ComponentModel;
                        using System.Diagnostics;
                        using System.Drawing;
                        using System.Drawing.Drawing2D;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Data;
                        using NinjaTrader.Gui.Chart;
                        #endregion
                        using System.Collections;
                        namespace NinjaTrader.Indicator
                        {
                        public class MyLib
                        {
                        public static double SUMPRODUCT(ArrayList vec1,ArrayList vec2) {
                        double m3 = 0.0;
                        Print(
                        "m");
                        for(int k2=0;k2<vec2.Count;k2++) {
                        m3+=(
                        double)vec1[k2]*(double)vec2[k2];
                        }
                        return m3;
                        }

                        }
                        // MyLib
                        }

                        Comment


                          #13
                          nikkk, please retry with proper scope, i.e.

                          Code:
                          public class MyLib : Indicator

                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by warreng86, 11-10-2020, 02:04 PM
                          4 responses
                          1,354 views
                          0 likes
                          Last Post mathewlo  
                          Started by Perr0Grande, Today, 08:16 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post Perr0Grande  
                          Started by elderan, Today, 08:03 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post elderan
                          by elderan
                           
                          Started by algospoke, Today, 06:40 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post algospoke  
                          Started by maybeimnotrader, Today, 05:46 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post maybeimnotrader  
                          Working...
                          X