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

If my indicator's variable is preset to "public"

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

    If my indicator's variable is preset to "public"

    I should be able to access it in my strategy, correct? Or do the variables need to be placed in the "Properties" region for strategies to access the variables?

    Under Initialize(), I have an "ADD (T*******tial());"
    This is the message I get an error message referring to it:-
    CS1501
    No overload for method 'TDSequential' takes '0' arguments

    Under "OnBarUpdate()", I have the following code:-
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
    if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (Position.MarketPosition = MarketPosition.Flat)[/COLOR]
    {
    [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (TDSequential.tdsetupiscompleted)
    {
    [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (TDSequential.tdsetupdirection == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
    {
    Print = String.Format( [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"highesthigh {0}"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], TDSequential.highesthigh );
    [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}
    }
    }
    [/SIZE][/FONT][/SIZE][/FONT]
    And these are the following error messages I am getting:-
    CS0029
    Cannot implicitly convert type 'NinjaTrader.Cbi.MarketPosition' to 'bool'
    and
    CS0119
    'NinjaTrader.Strategy.Strategy.TDSequential(System .Drawing.Color, System.Drawing.Color, double, bool)' is a 'method', which is not valid in the given context

    Could anyone please help? Thx much in anticipation!

    Regards

    Kay Wai

    #2
    Under Initialize(), I have an "ADD (T*******tial());"
    This is the message I get an error message referring to it:-
    CS1501
    No overload for method 'TDSequential' takes '0' arguments
    You MUST specify all the inputs for an indicator signature. Intellisense sometimes shows overrides, implying that some of the parameters are optional. In my experience, I can never get it to compile that way. You must specify every parameter, even if you are not going to use it in your strategy.

    And these are the following error messages I am getting:-
    CS0029
    Cannot implicitly convert type 'NinjaTrader.Cbi.MarketPosition' to 'bool'
    if (Position.MarketPosition = MarketPosition.Flat) is an assignment. You want a test for equality, which is: if (Position.MarketPosition == MarketPosition.Flat). ie., double up on the equality sign.

    CS0119
    'NinjaTrader.Strategy.Strategy.TDSequential(System .Drawing.Color, System.Drawing.Color, double, bool)' is a 'method', which is not valid in the given context
    At this point, it is hard to say where this comes from, but it is probably a side effect of not specifying all the indicator's parameters when you added the indicator to the strategy.
    Last edited by koganam; 04-11-2011, 01:19 AM.

    Comment


      #3
      If my indicator's variable is preset to "public"
      I should be able to access it in my strategy, correct? Or do the variables need to be placed in the "Properties" region for strategies to access the variables?
      Always keep in mind that NinjaTrader is basically setting up a Class per file. (You can code additional classes into one file, though that is generally considered poor practice in OOP. The tendency is to recommend one class per file, as it makes referencing and maintenance so much easier, when we have a one-to-one mapping of classes to files).

      Given that basis, accessing a variable in one class from another class requires the variable to have a getter, so yes, you need to set up properties if you want to access the variable from another class/file/indicator/strategy.

      Comment


        #4
        Hi Koganam,

        I have 2 classes set up in my indicator, one for a buy setup and the other for a sell setup AND both with identical properties (names). It seems to work fine.

        I have some variables which are doubles and bools which I have classified as public double xyz or public bool abc.

        I was under the impression that when I classify these variables as "public", I should be able to access them. Is my belief incorrect?

        Regards

        Kay Wai

        Comment


          #5
          Kay, please ensure to follow along this sample's way of exposing a variable or custom series for access from another script, this would be the only supported approach here - http://www.ninjatrader.com/support/f...ead.php?t=4991

          Thanks,
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi Bertrand, That's exactly what I'm trying to do - to expose a variable! I will refer to the code that I've attached.


            On Lines 488 to 491 and line 515, I have a set of public double variables. On Lines 503 and 504, I have a pair of public integer variables AND on line 506, I have a public double variable.

            The values to these public variables are obtained at the end of a process from their respective "definition" at lines 659 to 679. Aren't these variables exposed? How can I call them to a strategy?

            WRT the strategy, the problem begins at the Initialize() portion when I try to "ADD" the indicator. I get a CS1501 No overload for method 'T*****ential' takes '0' arguments error. What can I do here?

            And when I want to call the public variables to my strategy, I get a CS0119
            'NinjaTrader.Strategy.Strategy.TDSequential(System .Drawing.Color, System.Drawing.Color, double, bool)' is a 'method', which is not valid in the given context error. I'm not sure what this means but I would assume it is caused by the error message at the Initialize() region.


            Hope you can assist.

            Kay Wai



            Last edited by kaywai; 04-12-2011, 08:13 AM.

            Comment


              #7
              Originally posted by kaywai View Post
              Hi Koganam,

              I have 2 classes set up in my indicator, one for a buy setup and the other for a sell setup AND both with identical properties (names). It seems to work fine.

              I have some variables which are doubles and bools which I have classified as public double xyz or public bool abc.

              I was under the impression that when I classify these variables as "public", I should be able to access them. Is my belief incorrect?

              Regards

              Kay Wai
              Declaring a variable as public is not the same as exposing the variable. To expose the variable for other classes to access, you must define the properties of the variable: specifically, you MUST define the getter. That is the property/function that another class calls to get the value of the exposed variable.

              Comment


                #8
                Thanks Koganam. I understand what you are saying. Lemme try to make it work in the code. Kay Wai

                Comment


                  #9
                  Guys,

                  Would you mind telling me what I am doing wrong here?

                  Under a region called "private abstract class TDSeq", I have this variable called "public bool tdsetupiscompleted = false;"

                  Under the region "Properties", I have tried to expose the above bool like so:-
                  Code:
                  [FONT=Courier New][SIZE=2]
                  [SIZE=2][FONT=Courier New][Browsable([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])][/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New][XmlIgnore()][/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TDsetupiscompleted[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] { Update(); [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] tdsetupiscompleted; }[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT]
                  On compiling the code, I get this error message:-
                  " The name 'tdsetupiscompleted' does not exist in the current context" CS0103

                  What do I need to do to expose this bool? I have a few more bools, doubles and integers which I also need to expose. Hopefully with some guidance on the error, this issue which I am experiencing will be resolved.

                  Regards

                  Kay Wai

                  Comment


                    #10
                    The properties of a variable must be defined within the scope of the class. That means that if you have more than one class in the file, there will be more than one properties region: one for each class, and contained within the class which holds the relevant variable.

                    That is part of the reason that I prefer the preferred practice of one class per file.

                    Comment


                      #11
                      Hi Koganam, Thanks for your reply. You are correct that I have more than 1 class in my code ( I wouldn't really call it my code but a helpful samaritan who has since disappeared, designed this code based on my conditions).

                      I have 2 private classes - one to address the Buy and the other to address the Sell - which are brought together in what my coder calls a private abstract class. Both classes have their "members' named indentically. Why these 2 classes are in one indicator is because there are rules within the indicator that requires the Buy to cancel the Sell and vice versa.

                      I have tried disecting the code but it is a nightmare as there are some codes in there that I do not understand. So I have run into all sorts of trouble.

                      In the end, I've managed to get the unfinished code to the point where I can get a strategy to operate but exposing the variables that I need is proving to be formidable for me, at least. Need help from guys like you and the people at NT to see me to the next phase. I've actually posted the code yesterday in a zip file. Hopefully you could take a look when you have a moment and give me some pointers.

                      Thanks again Koganam!

                      Kay Wai

                      Comment


                        #12
                        Kay, I would suggest you check with your coder then - we could unfortunately not debug this code for you, in addition the concept of exposing internal series / variables is supported via the structures of our sample which does unfortunately not include the use of abstract classes in C#.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Without knowing much of what is in your code file, I might be able to explain some things that might shed some light.

                          The code "private abstract class TDSeq" is defining a new class, similar to an indicator or strategy class. The keyword "abstract" makes the TDSeq class a little special in that TDSeq cannot be used directly, but can only be used to create another class (which can be used). An abstract class acts like a template and is used by a developer to store code that is common to multiple other classes (indicators/strategies). I suspect that within your class file, you have other classes which use TDSeq as a base class like this:
                          public class MyIndicator : TDSeq
                          Which defines a class (MyIndicator) that uses TDSeq as a base class (or template). In code-speak this is called inheritance.

                          It may be possible that the problem you are having is that the TDsetupiscompleted property is declared within the abstract class and not in one of the inherited classes (e.g. MyIndicator). Try moving this definition into one of the inherited classes and see if that helps. You can still call "Update()" or anything else you need from TDSeq. It's just that TDSeq can never be created on its own, it can only be used as a base class (template).

                          Actually, the more I think about it, the more I think that NT is trying to instantiate (create an instance of) TDSeq. This will fail and could possibly lead to some of the errors you are getting. I'm curious to see if this works. :-)

                          Comment


                            #14
                            I'm doing something similar. I have a private class with several properties and methods declared inside an indicator. Here's what works for me:

                            Everything in the indicator scope should be declared private, including any classes.

                            Within the custom classes, declare things you want to expose later as public. This won't conflict with any serialization or anything because everything in the indicator scope is private.

                            In the properties section, create a public property that returns a handle to your private class.

                            Then anything that accesses that public property gets access to all pubic things within your class.

                            -Alex

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Barry Milan, Today, 10:35 PM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by WeyldFalcon, 12-10-2020, 06:48 PM
                            14 responses
                            1,428 views
                            0 likes
                            Last Post Handclap0241  
                            Started by DJ888, Yesterday, 06:09 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            40 views
                            0 likes
                            Last Post jeronymite  
                            Started by bill2023, Today, 08:51 AM
                            2 responses
                            16 views
                            0 likes
                            Last Post bill2023  
                            Working...
                            X