#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; using System.Globalization; #endregion // Written by Ben L. [email protected] // Feel free to ask for enhancements! // May God bless you and your business. // small mods by Mindset Dec 2010// configurable colors,thickness,length and code adjustments namespace NinjaTrader.Indicator { /// <summary> /// Puts horizontal lines at the bid & ask prices /// </summary> [Description("Puts a horizontal line at the bid & ask price")] public class ShowBidAsk : Indicator { #region Variables private bool displayText=true; private Color AskColor = Color.Blue; private Color BidColor = Color.Red; private int endbarsago = -12;//6.5 drawlines can't plot into future private int startbarsago = -3; private int Thickness = 1; #endregion protected override void Initialize() { Overlay = true; } protected override void OnBarUpdate() { } protected override void OnMarketData(MarketDataEventArgs e) { double a=e.MarketData.Ask.Price; double b=e.MarketData.Bid.Price; double TValue = Instrument.MasterInstrument.PointValue * TickSize; double SpreadCost = (a-b)/TickSize * TValue; /*removed currency symbol - some users don't trade $ denom instruments so it could be misleading. You can convert whatever symbols currency into your own trading currency but it's way too complicated for this small piece of code. */ string v = "Bid/Ask Spread:\n"+SpreadCost.ToString("0.00"); if(displayText) DrawTextFixed("text",v,TextPosition.TopLeft);//You can move this to any position you wish. { if ( e.MarketDataType == MarketDataType.Ask) { base.DrawLine("ask",false,startbarsago,e.Price,endbarsago,e.Price,AskColor,DashStyle.Solid,Thickness); } else if (e.MarketDataType == MarketDataType.Bid) { base.DrawLine("bid",false,startbarsago,e.Price,endbarsago,e.Price,BidColor,DashStyle.Solid,Thickness); } } } #region Blank out Label public override string ToString() { return "BidAsk";//To make blank change to ""; } #endregion #region Properties [Description("Display Text")] [GridCategory("Parameters")] [Gui.Design.DisplayName ("a.Display Text")] public bool DisplayText { get { return displayText; } set { displayText = value; } } [XmlIgnore()] [Description("Bid Color")] [Gui.Design.DisplayName ("e.Bid Color")] [GridCategory("Parameters")] public Color bidColor { get { return BidColor; } set { BidColor = value; } } [Browsable(false)] public string bidColorSerialize { get { return Gui.Design.SerializableColor.ToString(BidColor); } set {BidColor = Gui.Design.SerializableColor.FromString(value); } } [XmlIgnore()] [Description("Ask Color")] [Gui.Design.DisplayName ("f.Ask Color")] [GridCategory("Parameters")] public Color askColor { get { return AskColor; } set { AskColor = value; } } [Browsable(false)] public string askColorSerialize { get { return Gui.Design.SerializableColor.ToString(AskColor); } set {AskColor = Gui.Design.SerializableColor.FromString(value); } } [Description("Negative nos extends line further into the future.")] [GridCategory("Parameters")] [Gui.Design.DisplayName ("c EndBarNo")] public int Endbarsago { get { return endbarsago; } set { endbarsago = value; } } [Description("Negative nos pushes line start to the right.")] [GridCategory("Parameters")] [Gui.Design.DisplayName ("b.StartBarNo")] public int Startbarsago { get { return startbarsago; } set { startbarsago = value; } } [GridCategory("Parameters")] [Description("Thickness of line")] [NinjaTrader.Gui.Design.DisplayName("d.Line thickness")] public int thickness { get { return Thickness; } set { Thickness = value; } } #endregion } }
I also have CQG, Bid/Ask is a lot more accurate there (in sync with ChartTrader), however, it may be due to CQG sending out more/faster updates ?
chris
Comment