NexusFi: Find Your Edge


Home Menu

 





Stumped


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Zxeses with 3 posts (2 thanks)
    2. looks_two ratfink with 2 posts (0 thanks)
    3. looks_3 EnsoTrader with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,080 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
Zxeses's Avatar
 Zxeses 
San Francisco CA
 
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 173

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


Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CFTC Requests Tag 50 Trader Identity Data From CME and I …
Traders Hideout
Cboe Launches BITVX Bitcoin Volatility Index and Unveils …
Prediction Markets & Event Contracts
Iran War Prediction Markets: Ceasefire 16%, Ground Invas …
Prediction Markets & Event Contracts
SEC and CFTC Unlock Customer Cross-Margining for Treasur …
Treasury Notes and Bonds
Coinbase Launches Regulated Crypto Futures Across 26 Eur …
Cryptocurrency
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Hello Im new here
5 thanks
  #3 (permalink)
 
Zxeses's Avatar
 Zxeses 
San Francisco CA
 
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 173


Blah, nevermind, fixed it....

 
Code
		protected override void OnBarUpdate() 
			{
			if (CurrentBar < Count-1) return;


Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,430

@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.]


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
EnsoTrader
Durham, NC
 
Posts: 48 since Oct 2014
Thanks Given: 0
Thanks Received: 21

Glad I could help.
:P


Reply With Quote
  #6 (permalink)
 
Zxeses's Avatar
 Zxeses 
San Francisco CA
 
Experience: Intermediate
Platform: Ninja
Broker: CQG
Trading: ES
Posts: 139 since Jun 2014
Thanks Given: 90
Thanks Received: 173


ratfink View Post
@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 :-)


Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,430


Zxeses View Post
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'.


Travel Well
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on November 24, 2014


© 2026 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 - Downloads - Top
no new posts