I put the strategy below using the wizard, the strategy suppose to work this way:
at a particular time (this case 4:30) and current bar it would test to see if MFI is above a value (70) then enter short, but if MFI is below a value (40) then enter long. This would only enter at market open session and close until TP, SL or end of day.
I tried the backtest, but it entered at every bar, can someone please provide advice on
how I can fix this issue.
Thanks,
Andrew
___________________________________________
#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.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class AndrewMFI_Custom : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 70; // Default setting for MyInput0
private int myInput1 = 40; // Default setting for MyInput1
private int myInput2 = 14; // Default setting for MyInput2
private int myInput3 = 14; // Default setting for MyInput3
private int myInput4 = 1; // Default setting for MyInput4
private int myInput5 = 1; // Default setting for MyInput5
private int myInput6 = 1; // Default setting for MyInput6
private int myInput7 = 1; // Default setting for MyInput7
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
SetProfitTarget("", CalculationMode.Ticks, MyInput2);
SetStopLoss("", CalculationMode.Ticks, MyInput3, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Bars.SessionBreak
&& MFI(14)[0] >= MyInput0)
{
EnterShort(DefaultQuantity, "");
}
// Condition set 2
if (Bars.SessionBreak
&& MFI(14)[0] <= MyInput1)
{
EnterLong(DefaultQuantity, "");
}
// Condition set 3
if (ToTime(16, 30, 0) == ToTime(16, 30, 0))
{
EnterLong(DefaultQuantity, "");
EnterShort(DefaultQuantity, "");
}
}
#region Properties
[Description("High Limit")]
[Category("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
[Description("Low Limit")]
[Category("Parameters")]
public int MyInput1
{
get { return myInput1; }
set { myInput1 = Math.Max(1, value); }
}
[Description("Profit target")]
[Category("Parameters")]
public int MyInput2
{
get { return myInput2; }
set { myInput2 = Math.Max(1, value); }
}
[Description("Stop Loss")]
[Category("Parameters")]
public int MyInput3
{
get { return myInput3; }
set { myInput3 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int MyInput4
{
get { return myInput4; }
set { myInput4 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int MyInput5
{
get { return myInput5; }
set { myInput5 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int MyInput6
{
get { return myInput6; }
set { myInput6 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int MyInput7
{
get { return myInput7; }
set { myInput7 = Math.Max(1, value); }
}
#endregion
}
}
___________________________________________
Comment