Help with code error - NinjaTrader Programming | futures io social day trading
futures io futures trading


Help with code error
Updated: Views / Replies:3,161 / 10
Created: by kashter Attachments:1

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
 1  
 
Thread Tools Search this Thread
 

Help with code error

  #1 (permalink)
Elite Member
Moving
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: Mirus/Zen Fire
Favorite Futures: ES
 
Posts: 82 since May 2010
Thanks: 90 given, 44 received

Help with code error

Hi,
I have modified the PriorDayOHLC code slightly to suit me needs. The problem is the script works sometimes and in most times it throws the following error:

Quoting 
Error on calling 'OnBarUpdate' method for indicator 'AAPriorDayOHLC' on bar 1084: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

I am at my limited wits end. Anyone know what I need to do to get this thing going?

Cheers,
Kash

Attached Files
Register to download File Type: cs AAPriorDayOHLC.cs (12.6 KB, 15 views)
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)
Elite Member
Cheyenne,Wyoming...USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: NQ, YM
 
Posts: 69 since Nov 2010
Thanks: 329 given, 54 received

Enough history?


Hi Kash,
Recently had this happen to me also. I only had 2 days loaded on the chart. As soon as I switched it to 10 days all was well.
Hope it is this simple for your case also!

gever17

Reply With Quote
 
  #4 (permalink)
Elite Member
Moving
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: Mirus/Zen Fire
Favorite Futures: ES
 
Posts: 82 since May 2010
Thanks: 90 given, 44 received

Hi gever,
Tried your suggestion and loaded more than 15, 25 and 50 days, all still give error. Unfortunately it is more than that. Thanks

Kash


gever17 View Post
Hi Kash,
Recently had this happen to me also. I only had 2 days loaded on the chart. As soon as I switched it to 10 days all was well.
Hope it is this simple for your case also!

gever17


Reply With Quote
 
  #5 (permalink)
Membership Temporarily Revoked
Espoo, Finland
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus Future/Zen-Fire
Favorite Futures: Futures: FDAX, ES, NQ, FESX, CL. Currency futures: 6E
 
raffu's Avatar
 
Posts: 11 since Dec 2010
Thanks: 5 given, 1 received


kashter View Post
Hi,
I have modified the PriorDayOHLC code slightly to suit me needs. The problem is the script works sometimes and in most times it throws the following error:


I am at my limited wits end. Anyone know what I need to do to get this thing going?

Cheers,
Kash

Or have you checked "Maximum bars look bac" or "Min. bars required"

Sometimes those might help?

Reply With Quote
 
  #6 (permalink)
Elite Member
Orlando, Florida
 
Futures Experience: Advanced
Platform: NinjaTrader, TradeStation, MultiCharts, eSignal, MetaTrader
Favorite Futures: ES
 
Posts: 56 since Aug 2010
Thanks: 3 given, 66 received

My guess is that the error is in the following line of code.

 
Code
// Calculate the bars prior intraday close value for the 1515 hrs bar
int barsAgo = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day-1, CloseHour, CloseMinute, 59));
If the date is March 1st, Time[0].Day-1 will return a value of 0. You need to use Time[0].Subtract(new TimeSpan(x,x,x,x)).Day. Also, you can use try/catch blocks to verify that this is indeed the issue.

Reply With Quote
 
  #7 (permalink)
Elite Member
Moving
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: Mirus/Zen Fire
Favorite Futures: ES
 
Posts: 82 since May 2010
Thanks: 90 given, 44 received

Hi raffu & Moore,
I was stepping through the whole code line by line to make sure all is logical when I fumbled at the same line of code as you Moore have highlighted! So on further 'research' and pushing the boundaries of my c# coding abilities, I realized that "Time[0].Day-1" was the culprit. It works ok when today is Wednesday to Friday but fails when it is Monday or Tuesday, as I suspect it cannot gather values for Sunday or Saturday as my chart session templates are Mon-Fri.

So to cut a long story short, I added the following snippet to the script:
 
Code
DateTime day = DateTime.Now;
					
					//Amend days back based on present day
					if (day.DayOfWeek.ToString() == "Monday") 
						n = 3; //go to Friday
					else
						n = 1; // go to yesterday

int barsAgo = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day-n, CloseHour, CloseMinute, 59));
Now the code above will substitute the right number of day/s to subtract depending on the today. If today is Monday, then code will skip Sun & Sat and use Friday values.

Unfortunately it still gives the same error!!! Not sure what more there is to it. Hope someone can help out.

Cheers,
Kash


MooreTech View Post
My guess is that the error is in the following line of code.

 
Code
// Calculate the bars prior intraday close value for the 1515 hrs bar
int barsAgo = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day-1, CloseHour, CloseMinute, 59));
If the date is March 1st, Time[0].Day-1 will return a value of 0. You need to use Time[0].Subtract(new TimeSpan(x,x,x,x)).Day. Also, you can use try/catch blocks to verify that this is indeed the issue.


Reply With Quote
 
  #8 (permalink)
Elite Member
Orlando, Florida
 
Futures Experience: Advanced
Platform: NinjaTrader, TradeStation, MultiCharts, eSignal, MetaTrader
Favorite Futures: ES
 
Posts: 56 since Aug 2010
Thanks: 3 given, 66 received

The problem is still with the same line of code. Time[0].Day returns a value between 1 and 31 indicating the day of the month. If the day of the month is the first, Time[0].Day-n will return a 0 or negative value, which is the cause of your error. To get the proper value, you need to use Time[0].Subtract(new TimeSpan(n,0,0,0)).Day. Additionally, you will likely need to make similar changes to the month and year values.

Reply With Quote
The following user says Thank You to MooreTech for this post:
 
  #9 (permalink)
Elite Member
Moving
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: Mirus/Zen Fire
Favorite Futures: ES
 
Posts: 82 since May 2010
Thanks: 90 given, 44 received

Moore,
Thanks for the reply, will try out the fix during the lull hours.

Cheers.

Reply With Quote
 
  #10 (permalink)
Elite Member
Orlando, Florida
 
Futures Experience: Advanced
Platform: NinjaTrader, TradeStation, MultiCharts, eSignal, MetaTrader
Favorite Futures: ES
 
Posts: 56 since Aug 2010
Thanks: 3 given, 66 received


A little snippet to help get you started. I didn't test this code, but it should give you the idea.

 
Code
TimeSpan ts = new TimeSpan(1,0,0,0);
DateTime prevTime = Time[0].Subtract(ts);
int barsAgo = CurrentBar - Bars.GetBar(prevTime.Year,prevTime.Month,prevTime.Day,CloseHour,CloseMinute,59);

Reply With Quote
The following user says Thank You to MooreTech for this post:

Reply



futures io > > > > > Help with code error

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
ninja error soumi71 NinjaTrader 11 January 7th, 2011 11:10 AM
OutofMemoryException Error eone NinjaTrader 6 October 10th, 2010 03:38 PM
Error when trying to install indicator DennisA NinjaTrader Programming 3 August 18th, 2010 11:35 PM
Ninjatrader error help soumi71 NinjaTrader 9 January 14th, 2010 05:40 PM
Error on Compile Maletor NinjaTrader Programming 2 June 13th, 2009 04:30 PM


All times are GMT -4. The time now is 06:45 PM.

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-13 in 0.13 seconds with 20 queries on phoenix via your IP 54.90.92.204