NexusFi: Find Your Edge


Home Menu

 





Help with Arrays not DataSeries Compiles won't run


Discussion in NinjaTrader

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




 
Search this Thread
  #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 X Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Without Pulisic, USA 61.5% Live vs. Australia -- France …
Prediction Markets & Event Contracts
Daytrading to swingtrading
Traders Hideout
Would a node-based workflow for automated trading be useful?
Traders Hideout
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
Trump Media to sell instant access to market-moving soci …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,586


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 X 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 X Started this thread Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,586

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 X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on February 25, 2011


© 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