// 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 Test : Strategy
{
#region Variables
// Wizard generated variables
private double currentDay;
private double currentOpenRangeHigh;
private double currentOpenRangeLow;
private int longTrade;
private int shortTrade;
// 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()
{
CalculateOnBarClose = true;
SetProfitTarget("", CalculationMode.Ticks, 6);
SetStopLoss("", CalculationMode.Ticks, 6, true);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0]) != currentDay)
{
currentDay = ToDay(Time[0]);
currentOpenRangeHigh = 0;
currentOpenRangeLow = 100000;
longTrade = 0;
shortTrade = 0;
}
// Condition set 1
if (ToTime(Time[0]) >= ToTime(9,00, 0)
&& ToTime(Time[0]) <= ToTime(10, 00, 0))
{
if (High[0] > currentOpenRangeHigh)
{
currentOpenRangeHigh = High[0];
}
if (Low[0] < currentOpenRangeLow)
{
currentOpenRangeLow = Low[0];
}
}
// Condition set 3
if (ToTime(Time[0]) > ToTime(7, 20, 0) && ToTime(Time[0]) < ToTime(9, 30, 0))
{
if (Close[0] > currentOpenRangeHigh && longTrade <1)
{
EnterLong(DefaultQuantity, "");
}
// Condition set 4
}
if (Close[0] < currentOpenRangeLow && shortTrade < 1)
{
EnterShort(DefaultQuantity, "");
}
}
Comment