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:
    [COLOR=#0000ff]namespace[/COLOR]NinjaTrader.NinjaScript.Indicators
    {
    [COLOR=#0000ff]public[/COLOR]partial[COLOR=#0000ff]class[/COLOR]MyMethods:Indicator
    {
    [COLOR=#008000]//Sample method which calculates the delta of two prices[/COLOR]
    [COLOR=#0000ff]public[/COLOR][COLOR=#0000ff]static[/COLOR][COLOR=#0000ff]double[/COLOR]calculateDelta([COLOR=#0000ff]double[/COLOR]firstPrice,[COLOR=#0000ff]double[/COLOR]secondPrice)
    {
    [COLOR=#0000ff]return[/COLOR]Math.Abs(firstPrice-secondPrice);
    }
     
    [COLOR=#008000]//Sample method which prints Position information[/COLOR]
    [COLOR=#0000ff]public[/COLOR][COLOR=#0000ff]static[/COLOR][COLOR=#0000ff]void[/COLOR]printPositionInfo(Positionposition)
    {
    Print(String.Format([COLOR=#800000]"{0}: {1} {2} at {3}"[/COLOR],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.



              Code attached.

              Comment


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

                Working example in attachment.

                Code:
                        
                       [COLOR=Blue]protected override void [/COLOR]OnStartUp()
                        {        
                            Print_class Print_Obj = [COLOR=Blue]new [/COLOR]Print_class();
                            Print_Obj.Print = Print;
                            
                            Print_Obj.Print_From_Class( "#1: "+ "Hello World!" );
                            Print_Obj.Print                        ( "#2: "+ "Hello World!" );
                        }
                
                        [COLOR=Blue]public class[/COLOR] Print_class
                        {
                            [COLOR=Blue]public delegate void[/COLOR] Print_delegate( [COLOR=Blue]string [/COLOR]s );
                            [COLOR=Blue]public [/COLOR]Print_delegate Print;
                            
                            [COLOR=Blue]public void[/COLOR] Print_From_Class( [COLOR=Blue]string [/COLOR]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 algospoke, Yesterday, 06:40 PM
                  2 responses
                  23 views
                  0 likes
                  Last Post algospoke  
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  46 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  23 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  181 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X