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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          67 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          36 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          59 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          62 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          53 views
          0 likes
          Last Post CarlTrading  
          Working...
          X