Stumped - NinjaTrader Programming | futures io social day trading
futures io futures trading


Stumped
Updated: Views / Replies:603 / 6
Created: by Zxeses Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Stumped

  #1 (permalink)
3rd times a charm!
San Francisco CA
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: CQG
Favorite Futures: ES
 
Zxeses's Avatar
 
Posts: 139 since Jun 2014
Thanks: 90 given, 171 received

Stumped

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

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
3rd times a charm!
San Francisco CA
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: CQG
Favorite Futures: ES
 
Zxeses's Avatar
 
Posts: 139 since Jun 2014
Thanks: 90 given, 171 received


Blah, nevermind, fixed it....

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

Reply With Quote
The following user says Thank You to Zxeses for this post:
 
  #4 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,340 since Dec 2012
Thanks: 11,282 given, 7,092 received

@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
Reply With Quote
 
  #5 (permalink)
Trading Apprentice
Durham, NC
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Kinetick
Favorite Futures: ES, CL
 
Posts: 48 since Oct 2014
Thanks: 0 given, 20 received

Glad I could help.
:P

Reply With Quote
 
  #6 (permalink)
3rd times a charm!
San Francisco CA
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: CQG
Favorite Futures: ES
 
Zxeses's Avatar
 
Posts: 139 since Jun 2014
Thanks: 90 given, 171 received


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 :-)

Reply With Quote
The following user says Thank You to Zxeses for this post:
 
  #7 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,340 since Dec 2012
Thanks: 11,282 given, 7,092 received


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
Reply With Quote

Reply



futures io > > > > > Stumped

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stumped on mindlessly simple Unmanaged order anachronist Elite Automated NinjaTrader Trading 7 November 26th, 2014 04:41 AM


All times are GMT -4. The time now is 11:17 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-16 in 0.10 seconds with 19 queries on phoenix via your IP 54.226.34.209