NexusFi: Find Your Edge


Home Menu

 





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 3,979 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 8 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098

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

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
No book, only a stair: journaling fills where price move …
Cryptocurrency
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
What we know about Binances $6.3bn hack - BBC News
Cryptocurrency
AI for Traders — Agents, Memory, Tools & Real-Worl …
Elite Quantitative GenAI/LLM
 
  #2 (permalink)
 
wh's Avatar
 wh 
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.
Reply With Quote
  #3 (permalink)
 traderwerks   is a Vendor
 
Posts: 688 since Jun 2009
Thanks Given: 436
Thanks Received: 466



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
  #4 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098


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
  #5 (permalink)
 
wh's Avatar
 wh 
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.
Reply With Quote
  #6 (permalink)
 traderwerks   is a Vendor
 
Posts: 688 since Jun 2009
Thanks Given: 436
Thanks Received: 466


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
  #7 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098

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
  #8 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 478 since Jun 2009
Thanks Given: 1,419
Thanks Received: 404


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
Thanked by:
  #9 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098


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
Elite Membership required to download: nogapchart.zip
Started this thread Reply With Quote
Thanked by:




Last Updated on January 21, 2010


© 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