• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Passing indicator or strategy into class

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

    Passing indicator or strategy into class

    I have class called Logger... I want to use this class inside indicator or strategy (ninjatrader objects). This Logger class should write text using Time[0], Close[0], etc - properties which are as in indicator and strategy. Is there a object type which can I pass into Logger constructor, which allows me to use these common properties of Indicator or Strategy?

    Eg:
    Logger(Ninjatrader.Common ntCommon) {
    ntCommon.Print(ntCommon.Tmie[0]):
    }

    ntCommon - can be either NT Indicator or Strategy, which object type can I use?

    #2
    Hello kujista,

    Thank you for the post.

    The base classes for Indicators and Strategies are IndicatorBase and StrategyBase. Those classes will include the common properties and methods of all indicators and strategies. As an alternative, you could make a partial class of the indicator or strategy and do the logging in that partial class.

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Well.. I understand. Is there a way to define sb variable to convert strategy or indicator into "some other object" which allows me using Methods common for strategy and indicator?

      Code:
      namespace Golemator {
          public class Logger {
              private StreamWriter file;
              private string loggedObject = "";
              private bool logExists = false;
      
              private NinjaTrader.NinjaScript.NinjaScriptBase sb;
      
              // Empty constructor
              public Logger() {}
      
              // Using Logger inside Ninjatrader Strategy
              public Logger(NinjaTrader.NinjaScript.StrategyBase strategy) {
                  sb = strategy;
              }
      
              // Using Logger inside Ninjatrader Indicator
              public Logger(NinjaTrader.NinjaScript.IndicatorBase indicator) {
                  sb = indicator;
              }
      
              // This method should write text into console using sb variable and Print no matter if used in strategy or indicator
              public ShowLogLine() {
                  sb.Print("Logger constructor initiated: " + sb.O);
              }
          }
      }

      Comment


        #4
        Hello kujista,

        Thanks for the reply.

        You could make an Indicator and a Strategy that create a partial class of themselves which will include your logger.

        As an example, say you have a Logger DLL. A reference to this DLL has already been added to NinjaTrader.

        You can make a blank indicator that implements a partial Indicator class like this:

        Code:
         using Logger;
        ...
        namespace NinjaTrader.NinjaScript.Indicators
        {
            public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
            {
                public LoggerHelper MyLogger = new Logger.LoggerHelper();
            }
        }
        Then you can use MyLogger in any Indicator you make after this.

        Both Strategies and Indicators have a built-in Log that you could use as well.

        Please let me know if you have any questions.




        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Erwin Beckers, Today, 01:23 AM
        0 responses
        2 views
        0 likes
        Last Post Erwin Beckers  
        Started by Mark Taylor, Yesterday, 11:36 PM
        0 responses
        3 views
        0 likes
        Last Post Mark Taylor  
        Started by Bluebeep, Yesterday, 08:38 PM
        0 responses
        7 views
        0 likes
        Last Post Bluebeep  
        Started by stokhastic, Yesterday, 07:08 PM
        0 responses
        3 views
        0 likes
        Last Post stokhastic  
        Started by jlkramer16, Yesterday, 04:29 PM
        1 response
        4 views
        0 likes
        Last Post jlkramer16  
        Working...
        X