• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Added Time series question..

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

    Added Time series question..

    I added a 2nd time series or the Day time series and added a condition for avgdailyvolume based on this series. It has altered my backtest net profit results and should not have any effect(im just testing the SPY symbol). When I remove Add(PeriodType.Day, 1); the results go back to what they should be. Do I have something out of order or out of place below? Should I have a BIP == 2 above the avgdailyvolume condition?

    Code:
    protected override void Initialize()
    {
                
    Add(PeriodType.Minute, 1);
    Add(PeriodType.Day, 1);
    Add(SMA(Fast));
    Add(SMA(Slow));
    				
    CalculateOnBarClose = false;
            }
    
            
    protected override void OnBarUpdate()
    {
    
    {avgdailyvolume = SMA(Volumes[2],20)[0];}
    if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[2] < BarsRequired) return;
    			
    // Condition set 1 Long Entry, fast MA cross above slow MA & current price > high of bar at cross.         
    if (BarsInProgress == 1) //OnBarUpdate called for 1min bars
    if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend)
    if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2]	&& SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] + distance ) 	
    
    if ((avgdailyvolume > 100000) && (Closes[2][1] >= 10 && Closes[2][1] <= 200))
    
    {
    EnterLong(200, "");
    }

    #2
    Hello zachj,

    Thank you for your post.

    You are including the avgdailyvolume calculated of the Daily bars in your condition to EnterLong(), this will change the way your strategy performs versus if you remove the Daily bars and the avgdailyvolume from the strategy.

    How are you calculating avgdailyvolume when you remove the Daily bars? Or do remove both the Daily bars and the avgdailyvolume? Either way the calculations are going to be different for the strategy and thus the results of testing this strategy will be different.

    Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :

    First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

    For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

    It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

    If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - Click here for a list of certified NinjaScript Consultants
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      I wasn't looking at the volume at all before, so the volume and daily series were added in together. All I'm currently testing is SPY just to confirm the new code is not effecting the net profit. I have the volume set to >100k which shouldn't change the net profit seeing SPY volume is always way over this. The reason for adding the volume requirement is for when I'm backtesting a whole index to eliminate stocks with low volume.
      This added code is changing the net profit when backtesting SPY so something is off? Specifically it looks like the added series in the initialize section is what's causing it.
      Otherwise the other code is just for a simple sma crossover with a condition for price moving above the high of a previous bar at the crossover.

      Comment


        #4
        Hello zachj,

        Thank you for your response.

        When you change or add additional items to your code for conditions to enter you can expect to see different results in testing.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          I don't see why though because a condition for volume > 100k, how would that change anything. SPY volume is always over like 100million.
          The added daily series is somehow effecting the code that was already in there which is all based off minute data.

          Comment


            #6
            Hello zachj,

            Thank you for your response.

            Please try printing the values to the Output window using Print when the Daily bars are included in your strategy. Debugging your strategy is going to be the best method to discover why the results are different.

            For information on Print() please visit the following link: http://www.ninjatrader.com/support/h.../nt7/print.htm
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              I went to the link, it doesn't show how to use this? Where do I put the Print statement, under where avgdailyvolume is defined? And how do I get the info to come up in the output window, just by compiling it?

              Comment


                #8
                Hello zachj,

                Thank you for your response.

                Print() will Output to the Output window (Tools > Output) when running the strategy. You will want to Print() the avgdailyvolume when your conditions is true:
                Code:
                if ((avgdailyvolume > 100000) && (Closes[2][1] >= 10 && Closes[2][1] <= 200))
                
                {
                EnterLong(200, "");
                Print(avgdailyvolume);
                }
                For information on debugging please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3418
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  I don't see any volume prints under 100 million. Anything else I should check?

                  How does the program determine which is the secondary and which is the 3rd price series? Just the order from top to bottom correct?

                  Comment


                    #10
                    Hello zachj,

                    Thank you for your response.

                    If 20 day Moving Average volume is less than 1 million than you can expect to see drastically different results.

                    You are correct, the data series are loaded based on the order they are added to the Initialize() method.

                    Please let me know if you have any questions.
                    Patrick H.NinjaTrader Customer Service

                    Comment


                      #11
                      Im not sure what you mean by under 1million, all the readings are over 100 million. I'm just backttesting spy for now. But having a condition in there to Not include stocks under 500k shouldn't have any effect but its changing the net. It doesn't even matter, I can take out the volume condition and it still changes the net. Its the line Add(PeriodType.Day, 1); that is having the effect. The other code is being effected by this added series even though it's not using it. It's not making sense.

                      Comment


                        #12
                        Hello zachj,

                        Thank you for your response.

                        So I can fully test this on my end, please provide me with the code with the avgdailyvolume and the code without the avgdailyvolume.

                        I need both versions so I can compare and see what you remove and do not remove.
                        Patrick H.NinjaTrader Customer Service

                        Comment


                          #13
                          Not sure if you needed everything but here is the variables and the whole entire thing. All I'm doing is //commenting and uncommenting the 3 lines below in blue and it comes up with a different Net Profit. Using SPY. Primary series 5min.


                          Code:
                          namespace NinjaTrader.Strategy
                          {
                              
                              [Description("")]
                              public class Test : Strategy
                              {
                                  #region Variables
                                  
                                  private int fast = 3;
                                  private int slow = 50; 
                                  private int  timestart = 94500;
                          	private int  timeend = 140000;
                          	private double distance = .01;
                          	private double avgdailyvolume = 0;
                          		
                                  
                                  #endregion
                          
                                  
                                  protected override void Initialize()
                                  {
                                      
                          			Add(PeriodType.Minute, 1);
                          			Add(PeriodType.Day, 1);
                          			Add(SMA(Fast));
                                      Add(SMA(Slow));
                          				
                                      CalculateOnBarClose = false;
                                  }
                                
                                  protected override void OnBarUpdate()
                                  {
                          			avgdailyvolume = SMA(Volumes[2],20)[0];
                          			if ((avgdailyvolume > 100000) && (Closes[2][1] >= 10 && Closes[2][1] <= 200))
                          			
                          			if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend)
                          
                                      // Condition set 1 Long Entry, fast MA cross above slow MA & current price > high of bar at cross.         
                          			if ((BarsInProgress == 1) //OnBarUpdate called for 1min bars
                          			&& (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2]	&& SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] + distance 
                          				)) 
                          
                                      {
                                          EnterLong(200, "");
                                      }
                          
                          			
                                  }
                          
                                  #region Properties
                                  [Description("Fast MA Period")]
                                  [GridCategory("Parameters")]
                                  public int Fast
                                  {
                                      get { return fast; }
                                      set { fast = Math.Max(1, value); }
                                  }
                          
                                  [Description("Slow MA Period")]
                                  [GridCategory("Parameters")]
                                  public int Slow
                                  {
                                      get { return slow; }
                                      set { slow = Math.Max(1, value); }
                                  }
                          		
                          		[Description("")]
                          		[Category("Parameters")]
                          		public int TimeStart
                          		{
                          			get { return timestart; }
                          			set { timestart = Math.Max(0, value); }
                          		}
                          		
                          		[Description("")]
                          		[Category("Parameters")]
                          		public int TimeEnd
                          		{
                          			get { return timeend; }
                          			set { timeend = Math.Max(0, value); }
                          		}
                          		
                          		
                          		[Description("")]
                          		[Category("Parameters")]
                          		public double Distance
                          		{
                          			get { return distance; }  
                          			set { distance = Math.Max(0, value); }
                          		}
                          		
                                  #endregion
                              }
                          }
                          Last edited by zachj; 06-19-2013, 05:00 PM.

                          Comment


                            #14
                            Hello zachj,

                            Thank you for your response.

                            Can you provide screenshots of the difference in Net Profit and what you expect to see with these lines in your code?

                            I look forward to your response.
                            Patrick H.NinjaTrader Customer Service

                            Comment


                              #15
                              Files attached. As you can see the Net drops by 500 with the Volume code in there. I expect to see from my code that they would be exactly the same, as the volume code is simply a measure to eliminate stocks that are under 100k average daily volume. Im just running this backtest on SPY which is always over 100 million in daily volume. Either way this should not change the Net one penny. There has to be a bug in ninjatrader and its reading of volume or some bug with adding a 3rd price series. I even tried simply adding if VOLMA(14) > 100k and it still does not work properly. Screening out stocks under 100k in volume should be a very simple task to accomplish yet this has turned into a complicated time consuming task. This is simple code. There must be a NT bug.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ketoproplus, Today, 05:08 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post ketoproplus  
                              Started by asmmbillah, Today, 03:55 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post asmmbillah  
                              Started by cmarkb, Today, 12:04 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post cmarkb
                              by cmarkb
                               
                              Started by supernova0219, Yesterday, 07:48 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post supernova0219  
                              Started by qwfxny, Yesterday, 07:20 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post qwfxny
                              by qwfxny
                               
                              Working...
                              X