Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
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)
Stumped
Updated November 24, 2014
Top Posters
looks_one
Zxeses
with 3 posts (2 thanks)
looks_two
ratfink
with 2 posts (0 thanks)
looks_3
Quick Summary
with 1 posts (0 thanks)
looks_4
EnsoTrader
with 1 posts (0 thanks)
trending_up
1,452 views
thumb_up
2 thanks given
group
2 followers
forum
6 posts
attach_file
0 attachments
Stumped
November 24th, 2014, 12:20 PM
San Francisco CA
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 172
Ok, I'm stumped on this one.
Problem: Getting this error in my output window:
Quoting
Error on calling 'OnBarUpdate' method for indicator 'DavesBidAskPriceLine' on bar 0: DavesBidAskPriceLine.DrawRay: anchor1BarsAgo out of valid
range 0 through 0, was 100.
My debug output shows this:
BarCount: 14652 LineWidth: 100
Here is the code:
Quoting
protected override void OnBarUpdate()
{
if (savedLastPrice==null) savedLastPrice = Close[0];
if (savedLastPrice == Close[0]) return;
int LineWidth = Math.Min(Count, maxLineWidth);
if (maxLineWidth==0 || LineWidth==0)
{
DrawRay("CurPriceLine", -1, Close[0], 0, Close[0], colorPriceLine);
}
else
{
Print("BarCount: " + Count + " LineWidth: " + LineWidth);
DrawRay("CurPriceLine", LineWidth, Close[0], -1, Close[0], colorPriceLine);
}
savedLastPrice = Close[0];
ChartControl.ChartPanel.Invalidate();
}
When I manually set the LineWidth to zero in the Else section, it works (ray from 0 to -1)
I've even set it to -5 to -1 and that works...
In my OnMarketUpdate section, when I draw a Rectangle, this works fine... no problems:
Quoting
else
{
DrawRectangle("AskPriceReg", true, LineWidth, askPriceStart, -1, askPriceEnd, Color.Empty, colorAskZone, 3);
DrawRectangle("BidPriceReg", true, LineWidth, bidPriceStart , -1, bidPriceEnd, Color.Empty, colorBidZone, 3);
}
Clearly from my debug output, there are enough bars, I would think 14k bars is enough, but it still errors with a setting anything above 0.
Here is the complete code for reference:
Code
namespace NinjaTrader.Indicator
{
[Description("A custom line price indicator that includes Bid/Ask data, and the ability to limit the size to just your current/recent chart so it doesnt show when reviewing historical data.")]
public class DavesBidAskPriceLine : Indicator
{
#region Variables
//Dictionary<double, long> rowsAsk = new Dictionary<double, long>();
//Dictionary<double, long> rowsBid = new Dictionary<double, long>();
Color colorAskZone = Color.DarkGreen;
Color colorBidZone = Color.DarkBlue;
Color colorPriceLine = Color.Orange;
int maxLineWidth = 0;
int maxBidAskWidth = 200;
bool overlayLine = false;
int opacityAsk = 10;
int opacityBid = 10;
double askPriceStart;
double askPriceEnd;
double bidPriceStart;
double bidPriceEnd;
double savedLastPrice;
#endregion
#region Initialize
protected override void Initialize()
{
AutoScale = true;
Overlay = true;
CalculateOnBarClose = false;
DisplayInDataBox = true;
PaintPriceMarkers = false;
DrawOnPricePanel = true;
PlotsConfigurable = false;
}
#endregion
#region MarketDepth
protected override void OnMarketData(MarketDataEventArgs ev)
{
string dtype = ev.MarketDataType.ToString();
if (dtype!="Ask" && dtype!="Bid") return;
//Print("ev.MarketDataType: " + ev.MarketDataType.ToString());
int LineWidth = Math.Min(Count, maxBidAskWidth);
if (savedLastPrice==null || MarketData.Ask.Price != savedLastPrice && MarketData.Bid.Price != savedLastPrice)
{
// Set (or reset) everything;
savedLastPrice = MarketData.Last.Price;
askPriceStart=MarketData.Ask.Price;
askPriceEnd=savedLastPrice;
bidPriceStart=MarketData.Bid.Price;
bidPriceEnd=savedLastPrice;
}
else
{
// Ask price change check
if (MarketData.Ask.Price == savedLastPrice)
{
askPriceStart=MarketData.Ask.Price+(TickSize/2);
askPriceEnd=savedLastPrice-(TickSize/2);
}
else
{
askPriceStart=MarketData.Ask.Price;
askPriceEnd=savedLastPrice+(TickSize/2);;
}
// Bid price change check
if (MarketData.Bid.Price == savedLastPrice)
{
bidPriceStart=MarketData.Bid.Price-(TickSize/2);
bidPriceEnd=savedLastPrice+(TickSize/2);
}
else
{
bidPriceStart=MarketData.Bid.Price;
bidPriceEnd=savedLastPrice-(TickSize/2);
}
}
if (LineWidth==0)
{
DrawRectangle("AskPriceReg", true, -1, askPriceStart, Count, askPriceEnd, Color.Empty, colorAskZone, 3);
DrawRectangle("BidPriceReg", true, -1, bidPriceStart, Count, bidPriceEnd, Color.Empty, colorBidZone, 3);
// Removed to OnBarUpdate for compat with Index charts
//DrawRay("CurPriceLine", -1, savedLastPrice, 2, savedLastPrice, colorPriceLine);
}
else
{
DrawRectangle("AskPriceReg", true, LineWidth, askPriceStart, -1, askPriceEnd, Color.Empty, colorAskZone, 3);
DrawRectangle("BidPriceReg", true, LineWidth, bidPriceStart , -1, bidPriceEnd, Color.Empty, colorBidZone, 3);
// Removed to OnBarUpdate for compat with Index charts
//DrawRay("CurPriceLine", maxLineWidth, savedLastPrice, -1, savedLastPrice, colorPriceLine);
}
savedLastPrice = MarketData.Last.Price;
ChartControl.ChartPanel.Invalidate();
}
#endregion
#region OnBarUpdate
protected override void OnBarUpdate()
{
if (savedLastPrice==null) savedLastPrice = Close[0];
if (savedLastPrice == Close[0]) return;
int LineWidth = Math.Min(Count, maxLineWidth);
if (maxLineWidth==0 || LineWidth==0)
{
DrawRay("CurPriceLine", -1, Close[0], 0, Close[0], colorPriceLine);
}
else
{
Print("BarCount: " + Count + " LineWidth: " + LineWidth);
DrawRay("CurPriceLine", LineWidth, Close[0], -1, Close[0], colorPriceLine);
}
savedLastPrice = Close[0];
ChartControl.ChartPanel.Invalidate();
}
#endregion
#region Properties
[GridCategory("Settings")]
[Gui.Design.DisplayName("Bar width (max.), 0 = Infinite")]
public int MaxLineWidth {
get { return maxLineWidth; }
set { maxLineWidth = Math.Max(Math.Min(value, int.MaxValue), 0); }
}
[GridCategory("Settings")]
[Gui.Design.DisplayName("Bid/Ask width")]
public int MaxBidAskWidth {
get { return maxBidAskWidth; }
set { maxBidAskWidth = Math.Max(Math.Min(value, int.MaxValue), 0); }
}
#endregion
}
}
Any help would be appreciated
-Dave
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
November 24th, 2014, 12:27 PM
San Francisco CA
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 172
Blah, nevermind, fixed it....
Code
protected override void OnBarUpdate()
{
if (CurrentBar < Count-1) return;
November 24th, 2014, 02:37 PM
Birmingham UK
Market Wizard
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425
@Zxeses , Afaik, -1 is not a valid 'barsAgo' value in the parameters to the drawing calls, that should be part of the problem, as well as the number of bars needed that you already covered .
[e.g. if you want a horizontal ray off the last bar you would need to use 1 and 0, not 0 and -1.]
November 24th, 2014, 02:52 PM
Durham, NC
Posts: 48 since Oct 2014
Thanks Given: 0
Thanks Received: 21
Glad I could help.
:P
November 24th, 2014, 03:13 PM
San Francisco CA
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 172
ratfink
@
Zxeses , Afaik, -1 is not a valid 'barsAgo' value in the parameters to the drawing calls, that should be part of the problem, as well as the number of bars needed that you already
covered .
[e.g. if you want a horizontal ray off the last bar you would need to use 1 and 0, not 0 and -1.]
Well, -1 and -5 all work fine, indicator updated and posted :-)
November 24th, 2014, 03:15 PM
Birmingham UK
Market Wizard
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425
Zxeses
Well, -1 and -5 all work fine, indicator updated and posted :-)
Thanks for the info, I guess Ninja has lots of variations on 'valid' and 'unsupported'.
Last Updated on November 24, 2014