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

Accessing historical & real time performance factor/ratio

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

    Accessing historical & real time performance factor/ratio

    Hi folks:

    I would like to access the historical & real time performance or profit factor/ratio. When right-clicking on a strategy, there is a selection for strategy performance>historical & real time performance. When this is run, it can output the performance factor/ratio seen the the second column title "performance".

    Here is what I would like to do:

    In my strategy code for entering a long or short position, I would like to access this ratio/factor and make it a condition for going long or short respectively.

    For example, in the strategy code, I could load, say, 14 days. Then, as an additional condition, I would like to add:
    if the historical & real time "performance" ratio/factor over the last 14 days (include right up to the present moment in the current day) is above 2.50 go long or short respectively.

    What code could I use to access the that performance factor?



    Thanks...
    Last edited by birdog; 10-13-2014, 05:53 PM.

    #2
    Hello birdog,

    Thank you for your post.

    You can find this under TradesPerformance: http://www.ninjatrader.com/support/h...erformance.htm

    Comment


      #3
      @PatrickH

      Thank you.

      I have a BarArray set for daily (Day.1).

      How would I express:

      If the Performance.RealtimeTrades.TradesPerformance.Profi tFactor > 2.50 over the past 14 days (via the BarArray).

      I use a 5 min primary bar.

      OR, would it be the same thing to just load 14 days into the strategy upon enabling and simply use:

      alone without the BarsArray and it will just pull the ProfitFactor from the days that I allow it to load in the strategy itself?

      Code:
      if (Performance.RealtimeTrades.TradesPerformance.ProfitFactor > 2.50)
      ***Also, will this pull "historical" days I allow to load and real time or just real time trades? If not, I think I need something to make it calculate for both historical (from the amount of days loaded) and real time?

      ***Lastly, is there a way to split out the ProfitFactor to where specifically in order for a long trade to happen ALL long trades only (not short) has to have a profit factor of above 2.50 and vica versa instead of both long/short together?



      Thanks Patrick!

      Greg
      Last edited by birdog; 10-13-2014, 06:39 PM.

      Comment


        #4
        Hi @patrickh

        any thoughts on the last post if you are able?

        Comment


          #5
          Hello birdog,

          Thank you for your response.

          The following code will work on any bar type to pull the Profit Factor over the past 14 days:
          Code:
                  #region Variables
          		private double totalProfitAtSessionStart = 0;
          		private DataSeries pFactorPerDay;
                  #endregion
          
                  protected override void Initialize()
                  {
          			Add(PeriodType.Day, 1);
          			pFactorPerDay = new DataSeries(this);
                  }
          
                  protected override void OnBarUpdate()
                  {
          			if(pFactorPerDay == null)
          			{
          				pFactorPerDay = new DataSeries(SMA(BarsArray[1], 1));
          			}
          			
          			if(BarsInProgress == 0)
          			{
          				if(Bars.FirstBarOfSession)
          				{
          					pFactorPerDay.Set(Performance.AllTrades.TradesPerformance.ProfitFactor - totalProfitAtSessionStart);
          					totalProfitAtSessionStart = Performance.AllTrades.TradesPerformance.ProfitFactor;
          				}
          				
          				int count = 0;
          				for(int i = 14; i >= 0; i--)
          				{
          					if(pFactorPerDay[i] > 2.5)
          						count++;
          				}
          				if(count == 14)
          					Print("Profit Factor greater than 2.5 over the last 14 days");
          			}
          		}
          As long as you use Performance.AllTrades it will be all trades in the collection, not just real time. And splitting it by short or long is performance with Performance.LongTrades or Performance.ShortTrades: http://www.ninjatrader.com/support/h...erformance.htm

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by haas88, 03-21-2024, 02:22 AM
          18 responses
          207 views
          0 likes
          Last Post haas88
          by haas88
           
          Started by Board game geek, Today, 02:20 AM
          0 responses
          1 view
          0 likes
          Last Post Board game geek  
          Started by knighty6508, Today, 01:20 AM
          2 responses
          13 views
          0 likes
          Last Post knighty6508  
          Started by franatas, Today, 01:53 AM
          0 responses
          2 views
          0 likes
          Last Post franatas  
          Started by knighty6508, Today, 01:17 AM
          0 responses
          9 views
          0 likes
          Last Post knighty6508  
          Working...
          X