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

Debugging with Print()

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

    Debugging with Print()

    I tried the search feature for a few examples of Print() statements used for debugging but came up with nothing useful.

    Is there a thread around somewhere with a number of examples of using Print()?

    T.I.A.

    #2
    Hello,

    Thanks for your forum post.

    Sure, Please see here:



    and also here:



    Let me know if I can be of further assistance.

    Comment


      #3
      Hello Group,

      I placed a print statement inside of the method but get an error message from the print line (CS0120). This error message says:
      An object reference is required for the nonstatic field, method, or property 'member'
      In order to use a non-static field, method, or property, you must first create an object instance.

      I belive that the method does not reconize that the print() statement belongs to the using NinjaTrader.Strategy Class. How do I fix this. I am using the print statement to test that the array is being passed to the method.

      Here is my code below.

      static double ProbLast50(ref double[] array_ClosePrice)
      {
      double P_ProbLast50 = 0;
      int[] LongORShort = new int[50];
      int i;

      for (i = 0; i < 50; i++)
      {
      LongORShort[i] =
      0;
      Print(
      "ClosePrice["+ i.ToString("00")+ "] " + array_ClosePrice[i].ToString("00.00"));
      }
      return P_ProbLast50;

      }
      // End of ProbLast500

      Why does it not recognize the print statement inside of the method. The print statement works in the OnBarUpdate() inside of the strategy.
      Thanks for your help,

      Bayes

      Comment


        #4
        Hello,

        Print is a NinjaTrader overridden function that is only able to access in OnBarUpdate() and other NinjaTrader methods. I'm not sure where your culling this method from.

        If you move this code into OnBarUpdate() does it now run?

        I look forward to assisting you further.

        Comment


          #5
          Using Print () in methods

          Hello Brett,
          Thanks for your help.
          Here is how my program code is structed below.

          Why can't the method section (marked by ***********) call to the using NinjaTrader.Strategy or Indicator where ever the Print() method is located?
          Why does it have to be in the OnBarUpdate() braces { }?
          Is not "methods" still part of the names space and class for the strategy?

          #region Using declarations
          using System;
          ......
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion


          namespace NinjaTrader.Strategy
          {

          public class Dynamic : Strategy
          {

          protected override void Initialize()
          {
          } //End of Initialize

          protected override void OnBarUpdate()
          {
          for (int i = 0; i < 50; i++)
          {
          array_ClosePrice[i] = Close[i];
          // Print("ClosePrice["+ i.ToString ("00")+ "] " + array_ClosePrice[i].ToString("00.00"));
          } //End of for loop
          P_LongORShort = ProbLast50(ref array_ClosePrice);
          Print("P_LongORShort " + P_LongORShort.ToString("0.000"));

          } // End of On Bar Update


          //********************************************
          // Methods used in Dynamic Strategy class

          static double ProbLast50(ref double[] array_ClosePrice)
          {
          //do something and print() out debug text to a window
          } // End of ProbLast500

          } // End of Dynamic Strategy Class

          } // End of namespace NinjaTrader Strategy

          Comment


            #6
            Bayesian, please simplify your string to print, perhaps by concatenating it all to a single string before printing it. I just ran this test, and everything worked as expected, showing it is actually possible to use Print() inside a helper method.
            Code:
            void PrintTest(string s)
            {
                Print(s);
            }
            protected override void OnBarUpdate()
            {
                PrintTest(Close[0].ToString());
            }
            AustinNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            9 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,235 views
            0 likes
            Last Post sidlercom80  
            Started by thread, Yesterday, 11:58 PM
            0 responses
            3 views
            0 likes
            Last Post thread
            by thread
             
            Started by jclose, Yesterday, 09:37 PM
            0 responses
            8 views
            0 likes
            Last Post jclose
            by jclose
             
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            10 responses
            1,415 views
            0 likes
            Last Post Traderontheroad  
            Working...
            X