Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
dumb piece of code, need better coding
Updated January 21, 2010
Top Posters
looks_one
cory
with 4 posts (1 thanks)
looks_two
traderwerks
with 2 posts (0 thanks)
looks_3
wh
with 2 posts (0 thanks)
looks_4
zeller4
with 1 posts (1 thanks)
trending_up
2,715 views
thumb_up
2 thanks given
group
3 followers
forum
8 posts
attach_file
1 attachments
dumb piece of code, need better coding
January 19th, 2010, 09:07 PM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
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 ;
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
January 20th, 2010, 02:37 AM
Neubrandenburg, Germany
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks Given: 298
Thanks Received: 512
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.
January 20th, 2010, 06:53 AM
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465
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.
January 20th, 2010, 11:13 AM
Neubrandenburg, Germany
Experience: Advanced
Platform: R
Trading: Stocks
Posts: 538 since Jun 2009
Thanks Given: 298
Thanks Received: 512
simple answer
private double[] array1 = new double[40];
or
private double[] array1 = null;
more information can be found here:
https://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.
January 20th, 2010, 11:39 AM
Posts: 692 since Jun 2009
Thanks Given: 436
Thanks Received: 465
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.
January 20th, 2010, 07:43 PM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
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
January 21st, 2010, 02:45 PM
Orlando Florida
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404
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
January 21st, 2010, 02:56 PM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
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.
Attached Files
Elite Membership required to download: nogapchart.zip
Last Updated on January 21, 2010