• 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

  • kujista
    started a topic Passing indicator or strategy into class

    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?

  • NinjaTrader_ChrisL
    replied
    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.




    Leave a comment:


  • kujista
    replied
    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);
            }
        }
    }

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by TazoTodua, Today, 01:26 AM
0 responses
1 view
0 likes
Last Post TazoTodua  
Started by TazoTodua, Today, 01:21 AM
0 responses
1 view
0 likes
Last Post TazoTodua  
Started by TikDaddy, Yesterday, 02:08 PM
3 responses
11 views
0 likes
Last Post TikDaddy  
Started by Brillo, Yesterday, 01:52 PM
1 response
16 views
0 likes
Last Post NinjaTrader_Jim  
Started by TazoTodua, 02-09-2018, 08:40 AM
10 responses
884 views
0 likes
Last Post NinjaTrader_JoshG  
Working...
X