Trading Articles
Article Categories
Article Tools
dumb piece of code, need better coding
Updated January 21, 2010
Top Posters
looks_one
cory
with 4 posts (1 thanks)
looks_two
wh
with 2 posts (0 thanks)
looks_3
traderwerks
with 2 posts (0 thanks)
looks_4
zeller4
with 1 posts (1 thanks)
trending_up
2,024 views
thumb_up
2 thanks given
group
3 followers
forum
8 posts
attach_file
1 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)
dumb piece of code, need better coding
(login for full post details)
#1 (permalink )
the coin hunter
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,029 since Jun 2009
Thanks: 845 given,
7,893
received
so I want to store the gap value of each session break into an array, but if I declare double array1[40] Ninja doesn't like it. Then I try to store them into a dataseries except when I go to look for the prior gap value they all get wipe out except the most current gap value, the way i store it is gap[CurrentBar] = gapValue; given gap is a dataseries.
so i end up with this dumb code, is there a better way?
Code
// do gap storing into an array
if ( Cnt == 16 ) {
gap16 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 16 ] = gap16 ;
dsGap [ 15 ] = gap15 ;
dsGap [ 14 ] = gap14 ;
dsGap [ 13 ] = gap13 ;
dsGap [ 14 ] = gap12 ;
dsGap [ 12 ] = gap11 ;
dsGap [ 11 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 15 ) {
gap15 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 15 ] = gap15 ;
dsGap [ 14 ] = gap14 ;
dsGap [ 13 ] = gap13 ;
dsGap [ 14 ] = gap12 ;
dsGap [ 12 ] = gap11 ;
dsGap [ 11 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 14 ) {
gap14 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 14 ] = gap14 ;
dsGap [ 13 ] = gap13 ;
dsGap [ 12 ] = gap12 ;
dsGap [ 11 ] = gap11 ;
dsGap [ 10 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 13 ) {
gap13 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 13 ] = gap13 ;
dsGap [ 12 ] = gap12 ;
dsGap [ 11 ] = gap11 ;
dsGap [ 10 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 12 ) {
gap12 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 12 ] = gap12 ;
dsGap [ 11 ] = gap11 ;
dsGap [ 10 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 11 ) {
gap11 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 11 ] = gap11 ;
dsGap [ 10 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 10 ) {
gap10 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 10 ] = gap10 ;
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 9 ) {
gap9 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 9 ]= gap9 ;
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 8 ) {
gap8 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 8 ]= gap8 ;
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 7 ) {
gap7 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 7 ]= gap7 ;
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 6 ) {
gap6 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 6 ]= gap6 ;
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 5 ) {
gap5 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 5 ]= gap5 ;
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 4 ) {
gap4 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 4 ]= gap4 ;
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 3 ) {
gap3 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 3 ]= gap3 ;
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 2 ) {
gap2 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 2 ]= gap2 ;
dsGap [ 1 ]= gap1 ;
}
if ( Cnt == 1 ) {
gap1 = Instrument . MasterInstrument . Round2TickSize ( Open [ 0 ] - gapLast );
dsGap [ 1 ]= gap1 ;
}
Best Threads (Most Thanked) in the last 7 days on futures io
(login for full post details)
#2 (permalink )
Neubrandenburg, Germany
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks: 298 given,
504
received
i do not know perhaps it helps ...
init from
array[0] ... array[39] has a length of 40
for(int i = 0; i < array.length; i++)
{
read me in or do somethink
}
for better understanding
Code
dsGap[ 15 ] = gap16 ; dsGap [ 14 ] = gap15 ; dsGap [ 13 ] = gap14 ; dsGap [ 12 ] = gap13 ; dsGap [ 11 ] = gap12 ; dsGap [ 10 ] = gap11 ; dsGap [ 9 ] = gap10 ; dsGap [ 8 ]= gap9 ; dsGap [ 7 ]= gap8 ; dsGap [ 6 ]= gap7 ; dsGap [ 5 ]= gap6 ; dsGap [ 4 ]= gap5 ; dsGap [ 3 ]= gap4 ; dsGap [ 2 ]= gap3 ; dsGap [ 1 ]= gap2 ; dsGap [ 0 ]= gap1 ;
Causality is the relationship between an event (the cause) and a second event (the effect), where the second event is a consequence of the first.
(login for full post details)
#3 (permalink )
Taipei Taiwan
Experience: Advanced
Platform: NinjaTrader
Broker: AMP Clearing
Trading: TW
Posts: 693 since Jun 2009
Thanks: 434 given,
464
received
cory
so I want to store the
gap value of each session break into an array, but if I declare double array1[40] Ninja doesn't like it. Then I try to store them into a dataseries except when I go to look for the prior gap value they all get wipe out except the most current gap value, the way i store it is
You can use double array1[40] , Ninja is fine with that.
(login for full post details)
#5 (permalink )
Neubrandenburg, Germany
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks: 298 given,
504
received
simple answer
private double[] array1 = new double[40];
or
private double[] array1 = null;
more information can be found here:
http://msdn.microsoft.com/de-de/library/9b9dty7d%28VS.80%29.aspx
know where it stands
Causality is the relationship between an event (the cause) and a second event (the effect), where the second event is a consequence of the first.
(login for full post details)
#6 (permalink )
Taipei Taiwan
Experience: Advanced
Platform: NinjaTrader
Broker: AMP Clearing
Trading: TW
Posts: 693 since Jun 2009
Thanks: 434 given,
464
received
cory
no it gives me a hard time as soon as I type it in
ps. I don't think I know how to declare an array properly.
I was just typing in pseudo code. I meant Ninja does not have a problem with arrays of doubles. You do have to declare/alloc arrays for your language properly before you use them. I should have been clearer.
(login for full post details)
#7 (permalink )
the coin hunter
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,029 since Jun 2009
Thanks: 845 given,
7,893
received
thanks, just what i need , I delete all those dumb code only 5 lines needed.
wh
simple answer
private double[] array1 = new double[40];
or
private double[] array1 = null;
more information can be found here:
Arrays (C#)
know where it stands
(login for full post details)
#8 (permalink )
Florida
Experience: Intermediate
Platform: NT7
Trading: CL, NQ, NG
Posts: 469 since Jun 2009
Thanks: 1,401 given,
402
received
cory
thanks, just what i need , I delete all those dumb code only 5 lines needed.
that's cool, can you please share the improved version?
kz
The following user says Thank You to zeller4 for this post:
(login for full post details)
#9 (permalink )
the coin hunter
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,029 since Jun 2009
Thanks: 845 given,
7,893
received
zeller4
that's cool, can you please share the improved version?
kz
the whole indicator NoGgapChart or just those 5 lines?
ps. I just remember you know your stuff so here is the whole thing.
The following user says Thank You to cory for this post:
Last Updated on January 21, 2010
Right now
Ongoing
Right now
February
Coming soon
March
Register to Attend
Elite only