NexusFi: Find Your Edge


Home Menu

 





Nube question. What am i doing wrong?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Ragdoll with 2 posts (0 thanks)
    2. looks_two MrYou with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 bobwest with 1 posts (0 thanks)
    1. trending_up 1,723 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Nube question. What am i doing wrong?

  #1 (permalink)
 Ragdoll 
Walterboro, South Carolina
 
Experience: Intermediate
Platform: ninjatrader, amibroker, thinkorswim
Trading: futures
Posts: 13 since Aug 2013
Thanks Given: 1
Thanks Received: 6

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];

bidaskvol indicator = new bidaskvol();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();

bidaskvol[] tmp = new bidaskvol[cachebidaskvol == null ? 1 : cachebidaskvol.Length + 1];
if (cachebidaskvol != null)
cachebidaskvol.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cachebidaskvol = 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>
/// 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");

return _indicator.bidaskvol(input);
}
}
}
#endregion

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
45 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
MrYou's Avatar
 MrYou 
NC, USA
 
Experience: None
Platform: None Yet
Trading: Guitar
Posts: 403 since Jun 2011
Thanks Given: 618
Thanks Received: 196


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.

Reply With Quote
  #4 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,168 since Jan 2013
Thanks Given: 57,464
Thanks Received: 26,278


Ragdoll View Post
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.
...

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.

Or, you can wait for NT8.

Reply With Quote
  #5 (permalink)
 Ragdoll 
Walterboro, South Carolina
 
Experience: Intermediate
Platform: ninjatrader, amibroker, thinkorswim
Trading: futures
Posts: 13 since Aug 2013
Thanks Given: 1
Thanks Received: 6

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.

thanks again for the explanation,

Ragdoll

Started this thread Reply With Quote




Last Updated on September 11, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts