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

Time frame "From" and "To" dates in strategy

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

    Time frame "From" and "To" dates in strategy

    Hi all,
    in strategy I need Time frame "From" and "To" dates from Strategy Analyzer. Where can I find them? I could find eg. "Min. bars required" (BarsRequired) but not these dates.
    Thanks
    Attached Files

    #2
    Hello marada,

    Thank you for your post.

    I am looking into this on my end as this is not documented for NinjaTrader 7.

    Comment


      #3
      Hello marada,

      Thank you for your patience.

      You can use Bars.To and Bars.From for the From and To dates in the Strategy Analyzer.

      Comment


        #4
        Hello PatrickH, thanks a lot!
        But I just realized that I can not use this... I want modify an optimization method eg. "min. drawdown" (@MinDrawDown.cs) but I get an error "CS0120 - An object reference is required for the nonstatic field, method, or property 'member'."
        The reason to modify it is that this method can give me a nice result with even dd = 0 but with number of trades = 2. This is unusable. So my idea was to check minimum number of trades per year based on From and To dates from Strategy Analyzer. I have tested first with TradesPerformance.TradesPerDay but this (and other) calculations are based on first and last trade dates.
        Is there any way how to use Bars.From and Bars.To in optimization method? Or do you have any other idea how to check/calculate a minimum number of trades per year?
        Last edited by marada; 10-02-2015, 02:20 PM.

        Comment


          #5
          Hello marada,

          Thank you for your update.

          So my idea was to check minimum number of trades per year based on From and To dates from Strategy Analyzer.
          Is this all you are looking for? Can you attach your script?

          Comment


            #6
            Yes PatrickH, this is what Im looking for.

            Look at picture pls. I want avoid such results from a list of results. All results meet the condition of low drawdown but such results are nonsens. The strategy itself is correct, I also get results with 200, 500... trades. I want avoid nonsense results from a list and get more serious ones. I usually get about 70 % of nonsense results in the list. When my calculation of eg. Nr. of Trades per Day would be based on Start Day and End Day I would get almost 0.00 in this example and it would not meet my condition of min. 0.08 trades per day. I hope you understand what I mean.

            Code:
            // 
            // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
            //
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Drawing;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Indicator;
            using NinjaTrader.Strategy;
            #endregion
            
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
            	[Gui.Design.DisplayName("min. drawdown")]
            	public class MinDrawDown : OptimizationType
            	{
            		public override double GetPerformanceValue(SystemPerformance systemPerformance)
            		{
            			// **** (1) I use this now to calculate number of days within time periode ****
            			// **** (1) but MaxDate and MinDate is based on first and last trade dates ****
            			double tdays = (systemPerformance.AllTrades.TradesPerformance.MaxDate.Ticks 
            			- systemPerformance.AllTrades.TradesPerformance.MinDate.Ticks) / TimeSpan.TicksPerDay;
            			
            			// **** (2) I need this because I want calculate min. of trades per year from the whole time period ****
            			//double tdays = 0.0;//(Bars.From.Ticks - Bars.To.Ticks) / TimeSpan.TicksPerDay;
            			
            			if ((tdays <= 0.0)
            			|| !(systemPerformance.AllTrades.TradesPerformance.TradesPerDay > 0.08 // **** (1) this is based on first and last trade dates ****
            			&& systemPerformance.AllTrades.TradesPerformance.Currency.AvgProfit > 75.0
            			&& (systemPerformance.AllTrades.TradesPerformance.GrossProfit + systemPerformance.AllTrades.TradesPerformance.GrossLoss)
            			/ tdays * 365 * 1.1 > Math.Abs(systemPerformance.AllTrades.TradesPerformance.Currency.DrawDown))
            			) return -10000.0;
            				
            			return systemPerformance.AllTrades.TradesPerformance.Percent.DrawDown;
            		}
            	}
            }
            Attached Files

            Comment


              #7
              Hello marada,

              Thank you for your response.

              It would not be possible to access the From and To dates of the Bars object from within the Optimization Type.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, 04-17-2024, 06:40 PM
              6 responses
              49 views
              0 likes
              Last Post algospoke  
              Started by arvidvanstaey, Today, 02:19 PM
              4 responses
              11 views
              0 likes
              Last Post arvidvanstaey  
              Started by samish18, 04-17-2024, 08:57 AM
              16 responses
              61 views
              0 likes
              Last Post samish18  
              Started by jordanq2, Today, 03:10 PM
              2 responses
              11 views
              0 likes
              Last Post jordanq2  
              Started by traderqz, Today, 12:06 AM
              10 responses
              21 views
              0 likes
              Last Post traderqz  
              Working...
              X