dumb piece of code, need better coding - futures io
futures io futures trading



dumb piece of code, need better coding


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one cory with 4 posts (1 thanks)
    2. looks_two wh with 2 posts (0 thanks)
    3. looks_3 traderwerks with 2 posts (0 thanks)
    4. looks_4 zeller4 with 1 posts (1 thanks)
    1. trending_up 2,024 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 8 posts
    2. 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)

 
Search this Thread
 

dumb piece of code, need better coding

(login for full post details)
  #1 (permalink)
the coin hunter
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
 
cory's Avatar
 
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;
            } 

Started this thread Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(167 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(116 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #2 (permalink)
Neubrandenburg, Germany
 
Experience: Advanced
Platform: R
Trading: Stocks
 
wh's Avatar
 
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.
Reply With Quote
 
(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 View Post
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.

Reply With Quote
 
(login for full post details)
  #4 (permalink)
the coin hunter
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
 
cory's Avatar
 
Posts: 6,029 since Jun 2009
Thanks: 845 given, 7,893 received


traderwerks View Post
You can use double array1[40] , Ninja is fine with that.

no it gives me a hard time as soon as I type it in
https://content.screencast.com/users/coryng/folders/Jing/media/9ca0301c-004a-42eb-ac7e-867f5c574a0d/2010-01-20_1022.png

ps. I don't think I know how to declare an array properly.

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Neubrandenburg, Germany
 
Experience: Advanced
Platform: R
Trading: Stocks
 
wh's Avatar
 
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.
Reply With Quote
 
(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 View Post
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.

Reply With Quote
 
(login for full post details)
  #7 (permalink)
the coin hunter
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
 
cory's Avatar
 
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 View Post
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


Started this thread Reply With Quote
 
(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 View Post
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

Reply With Quote
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
 
cory's Avatar
 
Posts: 6,029 since Jun 2009
Thanks: 845 given, 7,893 received


zeller4 View Post
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
Register to download File Type: zip nogapchart.zip (3.6 KB, 13 views)
Started this thread Reply With Quote
The following user says Thank You to cory for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > dumb piece of code, need better coding


Last Updated on January 21, 2010


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

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

March
 

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

Elite only
     



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