Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Time Frame Strategy

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

    Multi-Time Frame Strategy

    Hi,

    I'm trying to optimize a multi-time frame strategy I have designed. It would appear that I can't even back-test it let alone Optimize it in Strategy Analyzer, everytime I do a backtest I get zero trades. However when I run the strategy in real-time trades do appear and I can access the strategy performance by selecting historical performance. I have attached the code below:

    Code:
    #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.Indicator;
    using NinjaTrader.Strategy;
    #endregion
    
    namespace NinjaTrader.Strategy
    {
    	#region Header
    		[Description("simple JMA/JMA crossover")]
    		public class Jurik_JMA_UpDown2 : Strategy
    		#endregion
        {
    		#region Variables	// default values
    			private double jma_len = 21; 	
    			private double jma_phase = -100; 
    			private double jma_len2 = 21; 	
    			private double jma_phase2 = -100; 
    			private int TimeFrame1 = 15;
    			private int TimeFrame2 = 60;
    			// ---------------------------------
    			private DataSeries JMAseries1;
    			private DataSeries JMAseries2;
    			#endregion
    		
    		#region Input Parameters
    			[Description("JMA length, any value >= 1")]
    			[GridCategory("Parameters")]
    			public double JMA_len
    			{
    				get { return jma_len; }
    				set { jma_len = Math.Max(1, value); }
    			}
    			
    			[Description("JMA phase, any value between -100 and +100")]
    			[GridCategory("Parameters")]
    			public double JMA_phase
    			{
    				get { return jma_phase; }
    				set { jma_phase = Math.Max(-100, Math.Min(100,value)); }
    			}	
    			
    			[Description("JMA length, any value >= 1")]
    			[GridCategory("Parameters")]
    			public double JMA_len2
    			{
    				get { return jma_len2; }
    				set { jma_len2 = Math.Max(1, value); }
    			}
    			
    			[Description("JMA phase, any value between -100 and +100")]
    			[GridCategory("Parameters")]
    			public double JMA_phase2
    			{
    				get { return jma_phase2; }
    				set { jma_phase2 = Math.Max(-100, Math.Min(100,value)); }
    			}	
    			
    			[Description("Time Frame, any value >= 1")]
    			[GridCategory("Parameters")]
    			public int Time_Frame1
    			{
    				get { return TimeFrame1; }
    				set { TimeFrame1 = Math.Max(1, value); }
    			}
    			
    			[Description("Time Frame, any value >= 1")]
    			[GridCategory("Parameters")]
    			public int Time_Frame2
    			{
    				get { return TimeFrame2; }
    				set { TimeFrame2 = Math.Max(1, value); }
    			}
    			#endregion
    
    		protected override void Initialize()
            {
    			#region Chart Features
                // Add a x minute Bars object to the strategy
    				Add(PeriodType.Minute, Time_Frame1);
    			
    			// Add a x minute Bars object to the strategy
    				Add(PeriodType.Minute, Time_Frame2);
    			
    				Add(Jurik_JMA_custom( 0, JMA_len , JMA_phase));
    				Add(Jurik_JMA_custom( 0, JMA_len2 , JMA_phase2));
    				Jurik_JMA_custom( 0, JMA_len , JMA_phase).Plots[0].Pen.Color = Color.Blue;
    				Jurik_JMA_custom( 0, JMA_len2 , JMA_phase2).Plots[0].Pen.Color = Color.Black;
    				CalculateOnBarClose = true;
    				#endregion
    			
    			#region Series Initialization
    				JMAseries1 = new DataSeries(this);	// sync dataseries to historical data bars
    				JMAseries2 = new DataSeries(this);	// sync dataseries to historical data bars
    				#endregion
    		}
    
            protected override void OnBarUpdate()
            {
    				if (BarsInProgress != 0)
    				return;
    			#region Strategy Formula
    				JMAseries1.Set( Jurik_JMA_custom(BarsArray[1], 0, JMA_len , JMA_phase ).JMA_Series[0] );
    				JMAseries2.Set( Jurik_JMA_custom(BarsArray[2], 0, JMA_len2 , JMA_phase2 ).JMA_Series[0] );
    				
    				if (JMAseries1[0] > JMAseries1[1] && JMAseries2[0] > JMAseries2[1])
    					EnterLong(1, "L");
    				if (JMAseries1[0] < JMAseries1[1] && JMAseries2[0] < JMAseries2[1])
    					EnterShort(1, "S");
    				#endregion			
            }
        }
    }
    I have also tried to backtest the Sample Multi-Time Frame strategy which came with NT7 however am experiencing the same problem as above.

    Can someone explain what I am doing wrong, if anything?

    Kind Regards,
    Harry Seager

    #2
    Harry,

    I am not seeing anything here off the top of my head. Could you make sure you have historical data for the other instruments here? You can check in the Tools > Historical Data Manager tool.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Fixed it. Don't know why its suddenly started working!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rocketman7, Today, 02:12 AM
      2 responses
      16 views
      0 likes
      Last Post rocketman7  
      Started by briansaul, Today, 05:31 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PaulMohn, Today, 03:49 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by frslvr, 04-11-2024, 07:26 AM
      6 responses
      106 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      6 responses
      26 views
      0 likes
      Last Post trilliantrader  
      Working...
      X