Help with Arrays not DataSeries Compiles won't run - futures io
futures io futures trading



Help with Arrays not DataSeries Compiles won't run


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
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

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

 
Search this Thread
 

Help with Arrays not DataSeries Compiles won't run

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

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

Journal Challenge February 2021 results:
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(173 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(120 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(35 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #3 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,764 since Jun 2009
Thanks: 32,302 given, 97,536 received


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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #4 (permalink)
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
 
Crassius's Avatar
 
Posts: 14 since Jan 2011
Thanks: 5 given, 3 received

Code removed by poster.

Problem SOLVED.

Follow me on Twitter Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 49,764 since Jun 2009
Thanks: 32,302 given, 97,536 received

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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > Help with Arrays not DataSeries Compiles won't run


Last Updated on February 25, 2011


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

New Challenge (TBD)

April
     



Copyright © 2021 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