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.

    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.




        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        599 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        344 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        557 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X