Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Passing indicator or strategy into class

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

  • 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:


  • 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?

Latest Posts

Collapse

Topics Statistics Last Post
Started by rhyminkevin, Today, 04:58 PM
3 responses
48 views
0 likes
Last Post Anfedport  
Started by iceman2018, Today, 05:07 PM
0 responses
5 views
0 likes
Last Post iceman2018  
Started by lightsun47, Today, 03:51 PM
0 responses
7 views
0 likes
Last Post lightsun47  
Started by 00nevest, Today, 02:27 PM
1 response
14 views
0 likes
Last Post 00nevest  
Started by futtrader, 04-21-2024, 01:50 AM
4 responses
50 views
0 likes
Last Post futtrader  
Working...
X