It's a simple gap fading strategy that is meant to run on 1 minute data. A second data series is added to determine the official settlement (close) price. There's a Print statement for each BarsInProgress value - 0 for minute bars and 1 for day bars. When enabled in the Strategies tab, the minute Print statements appear in the Output window however the day Print statements do not (i.e. OnBarUpdate never fires for BarsInProgress == 1).
Here is the 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.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Simple gap fade strategy for testing purposes.
/// </summary>
[Description("Simple gap fade strategy for testing purposes.")]
public class GapTest : Strategy
{
#region Variables
// Wizard generated variables
// 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()
{
Add(PeriodType.Day, 1);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
if (!Bars.BarsType.IsIntraday)
{
DrawTextFixed("error msg", "Gap strategy only works on intraday intervals", TextPosition.BottomRight);
return;
}
Print(String.Format("GAP TEST:\t{0}\t{1}\tprice = {2}\tgap price = {3}",
Time[0].ToLongDateString(),
Time[0].ToLongTimeString(),
Close[0].ToString(),
GapPrice.ToString()));
string signalName = "Gap Fade";
if (!GapFilled)
{
if (Close[0] > GapPrice && GapPrice > 0)
{
EnterShort(signalName);
ExitShortLimit(GapPrice, signalName);
}
else if (Close[0] < GapPrice)
{
EnterLong(signalName);
ExitLongLimit(GapPrice, signalName);
}
}
}
else if (BarsInProgress == 1)
{
Print("____________________________________________________________________________");
Print(String.Format("GAP TEST:\t{0}\t{1}\tDaily close = {2}", Time[0].ToLongDateString(), Time[0].ToLongTimeString(), Close[0].ToString()));
Print("____________________________________________________________________________");
}
}
#region GapPrice
/// <summary>
/// The previos session's close.
/// </summary>
protected double GapPrice
{
get
{
double gapPrice = double.MinValue;
if (CurrentBars[1] > 0)
{
gapPrice = Closes[1][0];
}
return gapPrice;
}
}
#endregion
#region GapFilled
/// <summary>
/// Indicates whether or not the gap has filled during the current session.
/// </summary>
/// <returns></returns>
protected bool GapFilled
{
get { return GapPrice <= CurrentDayOHL().CurrentHigh[0] && GapPrice >= CurrentDayOHL().CurrentLow[0]; }
}
#endregion
#region Properties
#endregion
}
}

Comment