Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print within a for loop

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

    Print within a for loop

    Hallo, I would like to print the results of a loop in the output window, but my code does not work. Can anyone give me a hint. Thanks

    int count = 0;
    for (int i = 1; i <= numDays; i++)
    {
    if(Close[i] > SMA(SMAlong)[i])
    {
    count++;
    PrintWithTimeStamp ( Close[i] );
    Print ( SMA(SMAlong)[i] );
    }
    }

    #2
    Hello,

    Thank you for your note.

    What is numDays set to?

    May I have an export of this in a script?

    To export your script do the following:
    1. Click File -> Utilities -> Export NinjaScript
    2. Enter a unique name for the file in the value for 'File name:'
    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    http://www.ninjatrader.com/support/h...nt7/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea, here the script. I had to set the print statements as comment to export the script.
      Attached Files

      Comment


        #4
        Hi phadreus,

        Try:
        PrintWithTimeStamp(Close[i].ToString());

        The Close[i] is a double. PrintWithTimeStamp wants a string.

        This is mentioned in the error message that appears in the errors column (please fully expand and read this error).
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks it works

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          666 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X