This Bid/Ask Spread indicator is plotting a dot on candle close. There some body can change
it to calculate on the High and Low please.
Thank you
#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.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Spread between the Bid and Ask prices
/// </summary>
[Description("Spread between the Bid and Ask prices")]
public class BidAskSpread : Indicator
{
#region Variables
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.PaleTurquoise, PlotStyle.Dot, "Bid"));
Add(new Plot(Color.HotPink, PlotStyle.Dot, "Ask"));
Add(new Plot(Color.Empty, "spreadSeries"));
Overlay = true;
CalculateOnBarClose = false;
AutoScale = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Historical)
return;
double spread = (GetCurrentAsk() - GetCurrentBid());
if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Currency)
{
string[] yenword = { "J", "P", "Y" };
string name = Instrument.FullName;
int lettersfound = 0;
for (int j = 0; j < yenword.Length; j++)
{
for (int i = 0; i < name.Length; i++)
{
string letter = name[i].ToString();
if (letter == yenword[j])
lettersfound++;
}
}
if (lettersfound >= yenword.Length)
{
DrawTextFixed("spread", (Math.Round((spread * 100), 1).ToString()) + " pip spread", TextPosition.TopRight, Color.Black, new Font("Arial", 14), Color.Black, Color.AntiqueWhite, 3);
spreadSeries.Set((Math.Round((spread * 100), 1)));
}
else
{
DrawTextFixed("spread", (Math.Round((spread * 10000), 1).ToString()) + " pip spread", TextPosition.TopRight, Color.Black, new Font("Arial", 14), Color.Black, Color.AntiqueWhite, 3);
spreadSeries.Set((Math.Round((spread * 10000), 1)));
}
}
else if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Future)
{
DrawTextFixed("spread", (Math.Round((spread / TickSize), 1).ToString()) + " tick spread", TextPosition.TopRight, Color.Black, new Font("Arial", 14), Color.Black, Color.AntiqueWhite, 3);
spreadSeries.Set((Math.Round((spread / TickSize), 1)));
}
Bid.Set(GetCurrentBid());
Ask.Set(GetCurrentAsk());
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Bid
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Ask
{
get { return Values[1]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries spreadSeries
{
get { return Values[2]; }
}
#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 BidAskSpread[] cacheBidAskSpread = null;
private static BidAskSpread checkBidAskSpread = new BidAskSpread();
/// <summary>
/// Spread between the Bid and Ask prices
/// </summary>
/// <returns></returns>
public BidAskSpread BidAskSpread()
{
return BidAskSpread(Input);
}
/// <summary>
/// Spread between the Bid and Ask prices
/// </summary>
/// <returns></returns>
public BidAskSpread BidAskSpread(Data.IDataSeries input)
{
if (cacheBidAskSpread != null)
for (int idx = 0; idx < cacheBidAskSpread.Length; idx++)
if (cacheBidAskSpread[idx].EqualsInput(input))
return cacheBidAskSpread[idx];
lock (checkBidAskSpread)
{
if (cacheBidAskSpread != null)
for (int idx = 0; idx < cacheBidAskSpread.Length; idx++)
if (cacheBidAskSpread[idx].EqualsInput(input))
return cacheBidAskSpread[idx];
BidAskSpread indicator = new BidAskSpread();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();
BidAskSpread[] tmp = new BidAskSpread[cacheBidAskSpread == null ? 1 : cacheBidAskSpread.Length + 1];
if (cacheBidAskSpread != null)
cacheBidAskSpread.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheBidAskSpread = 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>
/// Spread between the Bid and Ask prices
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BidAskSpread BidAskSpread()
{
return _indicator.BidAskSpread(Input);
}
/// <summary>
/// Spread between the Bid and Ask prices
/// </summary>
/// <returns></returns>
public Indicator.BidAskSpread BidAskSpread(Data.IDataSeries input)
{
return _indicator.BidAskSpread(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Spread between the Bid and Ask prices
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BidAskSpread BidAskSpread()
{
return _indicator.BidAskSpread(Input);
}
/// <summary>
/// Spread between the Bid and Ask prices
/// </summary>
/// <returns></returns>
public Indicator.BidAskSpread BidAskSpread(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.BidAskSpread(input);
}
}
}
#endregion
Comment