Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Line length limitations, coding an indicator??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Line length limitations, coding an indicator??

    Hi all - I have an indicator that sends a string of moving average numbers over to excel. I'm expanding my testing and ran into some kind of limitation, maxing out at six numbers.

    Here are code excerpts, representing the problem and a possible workaround. What I'd like to know is exactly what am I running into that's limiting me to six numbers passed? Could be the length of the string(doubtful), some kind of line length limit(?) or something else.

    Help!

    Here's the original code that builds a string of moving averages and
    passes it over to Excel. 'xxx'-'aaa' are various moving averages, the
    length of which don't pertain to my questions. Multi-line formatting
    for readability. Max of six of these moving average numbers in a single statement.

    excelSheet.Cells[rownum,3] = SMA(BarsArray[0], 50)[0].ToString("N2")+" "+
    SMA(BarsArray[0],100)[0].ToString("N2")+" "+
    SMA(BarsArray[0],xxx)[0].ToString("N2")+" "+
    SMA(BarsArray[0],yyy)[0].ToString("N2")+" "+
    SMA(BarsArray[0],zzz)[0].ToString("N2")+" "+
    SMA(BarsArray[0],aaa)[0].ToString("N2");

    Workaround: stash groups of six moving averages into variables, then pass those variables to Excel:

    d1 = SMA(BarsArray[0], 50)[0].ToString("N2")+" "+
    SMA(BarsArray[0],100)[0].ToString("N2")+" "+
    SMA(BarsArray[0],xxx)[0].ToString("N2")+" "+
    SMA(BarsArray[0],yyy)[0].ToString("N2")+" "+
    SMA(BarsArray[0],zzz)[0].ToString("N2")+" "+
    SMA(BarsArray[0],aaa)[0].ToString("N2");

    d2 = SMA(BarsArray[1], 50)[0].ToString("N2")+" "+
    SMA(BarsArray[1],100)[0].ToString("N2")+" "+
    SMA(BarsArray[1],xxx)[0].ToString("N2")+" "+
    SMA(BarsArray[1],yyy)[0].ToString("N2")+" "+
    SMA(BarsArray[1],zzz)[0].ToString("N2")+" "+
    SMA(BarsArray[1],aaa)[0].ToString("N2");

    excelSheet.Cells[rownum,5] = d1+" "+d2+" ";

    So, by assigning no more than six moving averages to a variable, I can stack these up, concatenate the variables together and successfully pass them to Excel.

    I have many strings, consisting of many, many numbers I want to pass to Excel, so can you tell me what I'm up against here?

    Thanks...

    P.S. I accidentally posted this in the NT8 section. I'm still running NT7, but instead of moving this post around a bunch, can you still help me out? Or, maybe move it to NT7 section for me...
    Last edited by AMATX; 03-14-2018, 02:17 PM.

    #2
    Hello AMATX,

    Thanks for opening the thread.

    I am not sure what your approach is to output data to Excel, so I can't be entirely sure where the issue is coming from.

    We could troubleshoot the issue further by using Print() to display the strings in the output window to see if they are complete. If they are complete, then we can be sure that we are hitting a limitation issue with how you are outputting data to Excel, and perhaps another approach should be considered.

    We don't have any example code that demonstrates streaming data into Excel, but we do offer examples to write to a file with a StreamWriter and support integration with Excel based on this approach.

    SampleStreamWriter - https://ninjatrader.com/support/foru...ead.php?t=3475

    Without the full code and testing on my end, I do not have enough context to determine if your workaround would be a valid solution.

    If there is anything else I can do to provide further input, please let me know.
    JimNinjaTrader Customer Service

    Comment


      #3
      How are those being written to excel? Is that 1 column of 6 moving avgs?
      Attached Files

      Comment


        #4
        I used this NT thread as the basis for connecting Ninja to Excel:



        See bottom of post #3, where I've lifted his syntax for loading up Excel cells, such as:
        excelSheet.Cells[rowcount,1] = ToDay(Time[0]);


        I build the string of moving averages and move it into -one- cell in Excel. I then use VBA to process the data and go from there.

        From above, here is an example of loading up -one- Excel cell with data:

        excelSheet.Cells[rownum,5] = d1+" "+d2+" ";

        If rownum = 3, then cell E3 will contain all of the numbers passed across. There's not a problem with cell 'width' on the Excel side, so I assumed the problem was something on the Ninja side.

        Per your comments, I may try using some display statements on the Ninja side to debug it.

        Since the max appears to be six moving averages, I did try moving the following string across and it worked(!):

        "1 2 3 4 5 6 7 8"

        As you can see, more than six numbers, but not nearly as long as say, 132.77 140.33 192.33, etc.

        Therefore, I got to wondering if I encountered some sort of line length issue, as I have code converting the MovAves to string numbers. Maybe it's a multi-line length issue?

        Ideas ??
        Last edited by AMATX; 03-14-2018, 07:09 PM.

        Comment


          #5
          Hmm, interesting about the column width max of 255 chars.

          I'm using Excel 2007.

          However, regardless of Excel widths, when I concat the two Ninja variables(each having six MovAve numbers) together and send to Excel, it shows up fine in the one cell. Nowhere close to 255 chars, either. Therefore, doesn't look like an Excel issue.

          Comment


            #6
            Something I'll try tomorrow if I have time is passing across a simple string, such as:

            "102.11 222.11 333.11 444.11 444.21 484.22 111.23 211.33"

            More than six numbers. No formatting NT code, just send across a dummy string of numbers.

            If this works, it might indicate that the problem has to do with all of the formatting code I'm using in NT to build the string, or the fact I'm doing this via multi-line vs. one long line of code. Could be there's a limit on how much manipulation I can do to the numbers before sending them to Excel. When I exceed six numbers, all I get in Excel is a blank cell.

            Comment


              #7
              Got it fixed. Turned out to be a problem with the call to load up Excel.

              Fix was to define a constant/variable that contains all of the MovAve calculated values, then supply that variable to the call to Excel. Basically, split it all up into two lines/chunks, instead of doing it all in one statement.

              Works just fine, now.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jclose, Today, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,413 views
              0 likes
              Last Post Traderontheroad  
              Started by firefoxforum12, Today, 08:53 PM
              0 responses
              11 views
              0 likes
              Last Post firefoxforum12  
              Started by stafe, Today, 08:34 PM
              0 responses
              11 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by sastrades, 01-31-2024, 10:19 PM
              11 responses
              169 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X