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:
#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
}
}
}
Can someone explain what I am doing wrong, if anything?
Kind Regards,
Harry Seager

Comment