Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Ok. I'm familiar with basic coding concepts and I decided to dip my toe into ninjascript. Nothing fancy just an indicator to plot the current ask volume and the current bid volume. I found the appropriate calls and got the code to compile. The problem is with the bid line. Instead of a line it shows up as a tab on the right side of the chart pointing to the value of the ask line.
Thanks in advance,
Ragdoll
Here is the code, I've bolded the lines I think are relevant:
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>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class bidaskvol : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#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.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Ask"));
Add(new Plot(Color.FromKnownColor(KnownColor.LimeGreen), PlotStyle.Line, "Bid")); Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula. long askVolume=GetCurrentAskVolume();
long bidVolume=GetCurrentBidVolume();
Plot0.Set(askVolume);
Plot1.Set(bidVolume); }
#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 Plot0
{
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 Plot1
{
get { return Values[1]; }
}
#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 bidaskvol[] cachebidaskvol = null;
private static bidaskvol checkbidaskvol = new bidaskvol();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public bidaskvol bidaskvol()
{
return bidaskvol(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public bidaskvol bidaskvol(Data.IDataSeries input)
{
if (cachebidaskvol != null)
for (int idx = 0; idx < cachebidaskvol.Length; idx++)
if (cachebidaskvol[idx].EqualsInput(input))
return cachebidaskvol[idx];
lock (checkbidaskvol)
{
if (cachebidaskvol != null)
for (int idx = 0; idx < cachebidaskvol.Length; idx++)
if (cachebidaskvol[idx].EqualsInput(input))
return cachebidaskvol[idx];
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.bidaskvol bidaskvol()
{
return _indicator.bidaskvol(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.bidaskvol bidaskvol(Data.IDataSeries input)
{
return _indicator.bidaskvol(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.bidaskvol bidaskvol()
{
return _indicator.bidaskvol(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.bidaskvol bidaskvol(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");
I haven't tried using your code yet, but from looking at it no error is standing out.
Have you tried removing the indicator from your chart and re-adding it? Sometimes I think the drawing options get "stuck" when you've changed something, and you're just reloading (F5) the NinjaScript in the chart.
I'm afraid you're running into a limitation of Ninja Trader 7. It doesn't have the bid/ask data for historical data -- that is, you can get it for the current bar only, which means that you have to accumulate it yourself in real time with your PC left on all the time.... No, I'm not kidding.
This will be changed in NT8, but its release date is still not out.
Here's a note in the Help file for both GetCurrentAskVolume() and GetCurrentBidVolume() :
"Note: When accessed during a historical backtest, the volume of the evaluated bar is substituted."
What that means is that you are plotting the same value for both bid and ask, one plot on top of each other, and it's actually just the total volume. You can check this by going into the Properties dialog for the indicator, and changing the plot of, say, the bid line from Dash Style "Solid" to "Dot" and Width to 3. You will see that you actually have 2 plots with the same values, overlying each other.
If you add the "VOL" indicator to the chart, and set its panel to the same panel number as your bidaskvol indicator and the Scale Justification to the same, you'll see that the volume bars exactly match the bidaskvol plot.
Sorry, man.
To get what you're looking for in NT7, you can look into the Gomi indicator threads here on nexusfi.com (formerly BMT). Try starting here and following the links: https://nexusfi.com/wiki/trading-wiki/GOMRecorder . (You do not want to code this yourself.)
The Gomi package records the tick data and allows plotting of bid/ask data; there are also threads here where people have made backfill data available for download so you don't have to build it up. The Gomi stuff is complex, but you can get a lot of help in the threads.
There is also a Gomi option to use up/downtick data, which is pretty accurate and does work with normal historical data. I suggest reading the threads and using Search a lot.
thanks for the reply. I put a couple of print statements in and you are confirming what I suspected. I am just starting to get a feel for ninjascript and it was driving me nuts.