简体   繁体   English

在C#Ninjatrader中访问另一个类的对象

[英]Accessing object of another class in c# Ninjatrader

I have a question regarding class object in C# in Ninjatrader. 我对Ninjatrader中C#中的类对象有疑问。 To begin with, I am trying to build the class that will managed the MACD indicator and method that will return true value if certain conditions are met. 首先,我正在尝试构建将管理MACD指标的类,如果满足某些条件,该方法将返回真值。 Now, I declare my class inside the strategy class(at the bottom): 现在,我在策略类中声明我的类(在底部):

private class MACD_test: MACD{

        public MACD_test(){

        }
        public int down(){
            Print(MACD(14, 28, 10).Diff[0]);
            Print(MACD(14, 28, 10)[0]);
            return 0;
        }

    }

It is just a simplifid example, but my problem is the line: 这只是一个简单的示例,但我的问题是这行代码:

Print(MACD(14, 28, 10).Diff[0])

where I refer to macd method Diff. 我指的是macd方法Diff。 I am getting an error: Object Reference not set to an instance of an object 我收到一个错误:“对象引用”未设置为对象的实例

Wierd thing is that I can refer to Macd value in the line below without an error: 奇怪的是,我可以在下面的行中引用Macd值,而不会出现错误:

Print(MACD(14, 28, 10)[0]);

Now, I thought that this is some kind of inheritance issue but after researching the topic for a while I didn't find any working answer. 现在,我认为这是某种继承问题,但是在研究了一段时间之后,我没有找到任何有效的答案。 I udnerstand that MACD is also a class, but as far as I know it doesn't need cosntructor. 我知道MACD也是一类,但据我所知它不需要cosntructor。 I am not very fluent in C# so I would appreciate your help on how to access: MACD(14, 28, 10).Diff 我不太精通C#,因此感谢您对如何访问MACD(14,28,10)的帮助。

Thanks 谢谢

You would need to initialize an object of the class with new MACD(); 您将需要使用new MACD();初始化该类的对象new MACD();

The Diff method is not static, and thus won't be able to be called without an instance of the class MACD Diff方法不是静态的,因此如果没有MACD类的实例,将无法调用Diff方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM