Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          572 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          331 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          549 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          550 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X