21/10/2010 06:03:55 InsertBid position = 0 price = 1.035 volume = 1 GetCurrentBid = 1.035 21/10/2010 06:03:55 Bid Price=1.0349 Volume=2 Position=1 Bid = 1.035 21/10/2010 06:03:55 RemoveBid position = 0 price = 0 volume = 0 GetCurrentBid = 1.035 21/10/2010 06:03:55 Bid Price=1.0349 Volume=2 Position=0 Bid = 1.035 21/10/2010 06:03:55 UpdateBid position = 0 price = 1.0349 volume = 1 GetCurrentBid = 1.035 21/10/2010 06:03:55 Bid Price=1.0349 Volume=1 Position=0 Bid = 1.035 21/10/2010 06:03:55 Bid Price=1.0349 Volume=1 Position=0 Bid = 1.035
My altered strat is copied below
regards
Dave
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// Add this to the declarations. It allows for the use of ArrayLists.
using System.Collections.Generic;
namespace NinjaTrader.Indicator
{
[Description("Sample demonstrating how you can create your own Level II data book.")]
public class SampleMarketDepth : Indicator
{
#region Variables
private List<LadderRow> askRows = new List<LadderRow>();
private List<LadderRow> bidRows = new List<LadderRow>();
private string sp = " | ";
#endregion
private class LadderRow
{
public string MarketMaker; // relevant for stocks only
public double Price;
public long Volume;
public LadderRow(double myPrice, long myVolume, string myMarketMaker)
{
MarketMaker = myMarketMaker;
Price = myPrice;
Volume = myVolume;
}
}
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}
protected override void OnBarUpdate()
{
// Since the L2 data is only stored on real-time bars, there is no need to print L2 books on historical data
if (Historical)
return;
}
protected override void OnMarketDepth(MarketDepthEventArgs e)
{
List<LadderRow> rows = null;
// Checks to see if the Market Data is of the Ask type
if (e.MarketDataType == MarketDataType.Ask)
rows = askRows;
// Checks to see if the Market Data is of the Bid type
else if (e.MarketDataType == MarketDataType.Bid) {
rows = bidRows;
}
if (rows == null)
return;
if (e.MarketDataType == MarketDataType.Bid && e.Position < 2)
Print(Time[0]+" "+e.Operation.ToString()+e.MarketDataType.ToString ()+" position = "+
e.Position+" price = "+e.Price+" volume = "+e.Volume+" GetCurrentBid = "+GetCurrentBid());
if (e.Operation == Operation.Insert)
{
if (e.Position >= rows.Count)
rows.Add(new LadderRow(e.Price, e.Volume, e.MarketMaker));
else
rows.Insert(e.Position, new LadderRow(e.Price, e.Volume, e.MarketMaker));
}
else if (e.Operation == Operation.Remove && e.Position < rows.Count)
rows.RemoveAt(e.Position);
else if (e.Operation == Operation.Update)
{
rows[e.Position].MarketMaker = e.MarketMaker;
rows[e.Position].Price = e.Price;
rows[e.Position].Volume = e.Volume;
}
for (int idx = 0; idx < bidRows.Count; idx++)
if (bidRows[idx].Price == 1.0349)
Print(Time[0]+" "+"Bid Price=" + bidRows[idx].Price + " Volume=" + bidRows[idx].Volume + " Position=" + idx + " Bid = "+GetCurrentBid());
}
#region Properties
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private SampleMarketDepth[] cacheSampleMarketDepth = null;
private static SampleMarketDepth checkSampleMarketDepth = new SampleMarketDepth();
/// <summary>
/// Sample demonstrating how you can create your own Level II data book.
/// </summary>
/// <returns></returns>
public SampleMarketDepth SampleMarketDepth()
{
return SampleMarketDepth(Input);
}
/// <summary>
/// Sample demonstrating how you can create your own Level II data book.
/// </summary>
/// <returns></returns>
public SampleMarketDepth SampleMarketDepth(Data.IDataSeries input)
{
if (cacheSampleMarketDepth != null)
for (int idx = 0; idx < cacheSampleMarketDepth.Length; idx++)
if (cacheSampleMarketDepth[idx].EqualsInput(input))
return cacheSampleMarketDepth[idx];
lock (checkSampleMarketDepth)
{
if (cacheSampleMarketDepth != null)
for (int idx = 0; idx < cacheSampleMarketDepth.Length; idx++)
if (cacheSampleMarketDepth[idx].EqualsInput(input))
return cacheSampleMarketDepth[idx];
SampleMarketDepth indicator = new SampleMarketDepth();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();
SampleMarketDepth[] tmp = new SampleMarketDepth[cacheSampleMarketDepth == null ? 1 : cacheSampleMarketDepth.Length + 1];
if (cacheSampleMarketDepth != null)
cacheSampleMarketDepth.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheSampleMarketDepth = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Sample demonstrating how you can create your own Level II data book.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.SampleMarketDepth SampleMarketDepth()
{
return _indicator.SampleMarketDepth(Input);
}
/// <summary>
/// Sample demonstrating how you can create your own Level II data book.
/// </summary>
/// <returns></returns>
public Indicator.SampleMarketDepth SampleMarketDepth(Data.IDataSeries input)
{
return _indicator.SampleMarketDepth(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Sample demonstrating how you can create your own Level II data book.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.SampleMarketDepth SampleMarketDepth()
{
return _indicator.SampleMarketDepth(Input);
}
/// <summary>
/// Sample demonstrating how you can create your own Level II data book.
/// </summary>
/// <returns></returns>
public Indicator.SampleMarketDepth SampleMarketDepth(Data.IDataSeries input)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.SampleMarketDepth(input);
}
}
}
#endregion
Comment