Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print from AddOns

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

    Print from AddOns

    Hello,

    NT8 documentation states that the NT7 UserDefinedMethods concept has been moved to the AddOns and the following provided as a template.

    Code:
    namespaceNinjaTrader.NinjaScript.Indicators
    {
    publicpartialclassMyMethods:Indicator
    {
    //Sample method which calculates the delta of two prices
    publicstaticdoublecalculateDelta(doublefirstPrice,doublesecondPrice)
    {
    returnMath.Abs(firstPrice-secondPrice);
    }
     
    //Sample method which prints Position information
    publicstaticvoidprintPositionInfo(Positionposition)
    {
    Print(String.Format("{0}: {1} {2} at {3}",position.Instrument,position.Quantity,position.MarketPosition,position.AveragePrice));
    }
    A wizard is now provided and the generated code is now using NinjaTrader.NinjaScript.AddOns and the class now inherits from NinjaTrader.NinjaScript.AddOnBase.

    I have added the required "using" statement in my Indicators to enable calling of the methods but I am not able to use the Print Method as above. I am getting an error on compile stating "An object reference is required for the non-static ... method .. NinjaTrader.NinjaScript.NinjaScript.Print(object)" .

    What do I need to modify to be able to use the Print method from within classes that inherit from AddOnBase?

    Thanks,

    #2
    Hello,

    when the Print method is not available, you can use this:

    Code:
    NinjaTrader.Code.Output.Process(  mystring, PrintTo.OutputTab1 );
    or
    Code:
    NinjaTrader.Code.Output.Process(  mystring, PrintTo.OutputTab2 );

    Comment


      #3
      Hello tornadoatc,

      Thank you for writing in. In your particular case I would recommend using the method cls71 described. More information is available in our help guide here: http://ninjatrader.com/support/helpG...ightsub=output

      Please let me know if you experience any difficulties or if I may be of further assistance.
      Michael M.NinjaTrader Quality Assurance

      Comment


        #4
        Is the way to do this in NT7 ?
        fx.practic
        NinjaTrader Ecosystem Vendor - fx.practic

        Comment


          #5
          Originally posted by fx.practic View Post
          Is the way to do this in NT7 ?
          This should not be an issue in NinjaTrader 7, as you can use Print() directly in UserDefinedMethods. This trick applies to NinjaTrader 8 only, and relates to printing output when you are outside of the namespace containing the NinjaScript Print() method.
          Dave I.NinjaTrader Product Management

          Comment


            #6
            Thank You.
            fx.practic
            NinjaTrader Ecosystem Vendor - fx.practic

            Comment


              #7
              Hi, I worked on this with NT8 and works nicely.

              http://ninjatrader.com/support/forum...013#post426013

              Code attached.

              Comment


                #8
                It looks, there is way to do it in NT7 using delegate.

                Working example in attachment.

                Code:
                        
                       protected override void OnStartUp()
                        {        
                            Print_class Print_Obj = new Print_class();
                            Print_Obj.Print = Print;
                            
                            Print_Obj.Print_From_Class( "#1: "+ "Hello World!" );
                            Print_Obj.Print                        ( "#2: "+ "Hello World!" );
                        }
                
                        public class Print_class
                        {
                            public delegate void Print_delegate( string s );
                            public Print_delegate Print;
                            
                            public void Print_From_Class( string s )
                            {
                                Print( s );
                            }
                        }
                Attached Files
                Last edited by fx.practic; 01-07-2016, 03:02 AM.
                fx.practic
                NinjaTrader Ecosystem Vendor - fx.practic

                Comment


                  #9
                  The Delegate is a nice option. Thanks for that.

                  When I moved from NT7 to NT8, I had a lot of issues because of Print, and because of a lot of custom routines I had put in UserDefinedMethods (like converting ticks to price... .). I am attaching the code that NT Support help me figure out. It utilizes an AddOn to provide the same kind of functionality like UserDefined Methods.

                  I have put my print routine in there too - this allows you to print to either output logs.
                  Attached Files

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Lando Calrissian, Today, 08:10 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post Lando Calrissian  
                  Started by FatCanary, Today, 08:09 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post FatCanary  
                  Started by chartchartchart, Today, 08:08 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post chartchartchart  
                  Started by andreslazor7, Today, 08:08 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post andreslazor7  
                  Started by vantojo, 01-12-2021, 02:13 PM
                  15 responses
                  195 views
                  0 likes
                  Last Post FatCanary  
                  Working...
                  X