NexusFi: Find Your Edge


Home Menu

 





Help with Arrays not DataSeries Compiles won't run


Discussion in NinjaTrader

Updated
    1. trending_up 3,678 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Help with Arrays not DataSeries Compiles won't run

  #1 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

I'm working on some code from John Ehler's. In his notes he says of the code,

"First the entire code is completed for each bar and the values of the variables are retained from bar to bar. However, the values of the arrays are not automatically indexed to each price bar."

So I used arrays instead of DataSeries.... At first I declared and initalized in one step in the variables section. They are all the same size and all hold a double value.

double[] q = new double[50];

That compiles but on bar six, at the first line, and first time I try to address the first array by looping through it and storing some computed values, the script fails and I get the error message in the log, Error on calling 'OnBarUpdate' method for indicator CycleSpectrum on bar 6: Index was outside the bounds of the array.

The first index I tried to access is q[8] to assign a value to it inside a loop.

So I tried splitting up the declaration in the variables section:

double[] q;

and then under protected override void Initialize()

q = new double[50];

but that didn't help... I still get the "Index was outside the bounds of the array." error message in the log.

Any help greatly appreciated.

Relevant snippets:

In Variables region:
private int n = 0;
double[] q;

In protected override void Initialize() method:
q = new double[50];

Here's the loop:

quotientForQ = 7;
for (n = 8; n <51; n++)
{
beta = Math.Cos((360/n)*(Math.PI/180));
gamma = 1/(Math.Cos((720*delta/n)*(Math.PI/180)));
alpha = gamma - (Math.Sqrt(gamma*gamma-1));

quotientForQ += 1;
q[n] = (quocientForQ/6.283185)*(smoothHP[0] - smoothHP[1]);

l[n] = smoothHP[0];

real[n] = .5*(1 - alpha)*(l[n] - olderL[n])+ beta * (1+alpha) * oldReal[n] - alpha*olderReal[n];

lMag[n] = .5*(1-alpha)*(q[n] - olderQ[n]) + beta*(1+alpha)*oldlMag[n] - alpha*olderlMag[n];
}

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
Ninja Trader 8 Drawing Tools Wanted
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
52 thanks
NexusFi site changelog and issues/problem reporting
46 thanks
Battlestations: Show us your trading desks!
34 thanks
GFIs1 1 DAX trade per day journal
31 thanks
What percentage per day is possible? [Poll]
20 thanks

  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,319 since Jun 2009
Thanks Given: 33,139
Thanks Received: 101,474


The index of smoothHP[1] doesn't exist until after bar 1.

Add at the top of #onbarupdate

if (CurrentBar < 1) return;

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

Code removed by poster.

Problem SOLVED.

Follow me on Twitter Started this thread Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,319 since Jun 2009
Thanks Given: 33,139
Thanks Received: 101,474

Sorry, just saw the bar 6 reference.

Probably a math error, division by zero, reference to an index that doesn't exist, this kinda stuff. Hard to troubleshoot code snippets, plus I don't use NT. Hopefully someone else can help.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:





Last Updated on February 25, 2011


© 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