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

Accessing a List<string> in an Indicator from a Strategy

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

    Accessing a List<string> in an Indicator from a Strategy

    Hello,

    I would like to access a List of strings that are built in an indicator from a strategy but I get this error message when compiling the strategy: No overload for method 'Indicator name' takes 0 arguments.
    I've been reading thru the help forum and was able to get the indicator to expose the List with:

    [Browsable(false)]
    [XmlIgnore]
    public List<string> myListOfStrings
    {
    get { Update(); return MyListOfStrings; }
    }

    In the strategy I've added "AddChartIndicator(indicator name())" below (State == State.Configure) and when trying to read the list with "foreach (string str in MyListOfStrings)" I get the error message mentioned above.

    Can this be done ? what am I missing/doing wrong ?


    Thank you.

    Anthony

    #2
    Your strategy needs to retain a reference to the indicator,
    Code:
    BigIndy [COLOR=#e74c3c]myBigIndy [/COLOR]= BigIndy(50,40,30,etc);
    and then use that reference for everything, such as when
    adding to the chart,
    Code:
    AddChartIndicator([COLOR=#e74c3c]myBigIndy[/COLOR]);
    or accessing the indicator public properties, such as when
    accessing the getter for myListOfStrings,
    Code:
    foreach (string str in [COLOR=#e74c3c]myBigIndy[/COLOR].myListOfStrings)
    Last edited by bltdavid; 07-17-2021, 02:51 PM.

    Comment


      #3
      I get error: <<'NinjaTrader.NinjaScript.Strategies.Strategy.BigInd y(50,40,30,etc)' is a 'method' but is used like a 'type'>> with: "BigIndy myBigIndy = BigIndy(50,40,30,etc);"

      and error: <<'NinjaTrader.NinjaScript.Indicators.Indicator' does not contain a definition for 'myListOfStrings' and no extension method 'myListOfStrings' accepting a first argument of type 'NinjaTrader.NinjaScript.Indicators.Indicator' could be found (are you missing a using directive or an assembly reference?)>> with : "foreach (string str in myBigIndy.myListOfStrings)"

      Any suggestions ?

      Comment


        #4
        Instead of BigIndy, why don't you try using the name of the
        actual indicator that actually has the list of strings?

        The BigIndy indicator doesn't exist, it's a just a placeholder name
        I invented out of thin air to help illustrate my code examples.

        You used the placeholder 'indicator name', right? Well, I used
        the silly made-up placeholder name 'BigIndy' -- same difference.


        Comment


          #5
          That's what I did, used the actual indicator name:
          xyc201 myIndicator = xyc(25, 100, 5000, "", false, true, 0, "a100:b2C", "22,0");

          'NinjaTrader.NinjaScript.Strategies.Strategy.am801 (int, int, int, string, bool, bool, double, string, string)' is a 'method' but is used like a 'type'

          Comment


            #6
            And the compiler is seeing it as a Strategy instead of an Indicator.

            Comment


              #7
              Originally posted by Anthony_0709 View Post
              That's what I did, used the actual indicator name:
              xyc201 myIndicator = xyc(25, 100, 5000, "", false, true, 0, "a100:b2C", "22,0");

              'NinjaTrader.NinjaScript.Strategies.Strategy.am801 (int, int, int, string, bool, bool, double, string, string)' is a 'method' but is used like a 'type'
              The parts I highlighted in the red must be the same name.

              Use the actual name of the indicator for both.
              Last edited by bltdavid; 07-18-2021, 12:31 AM.

              Comment


                #8
                Hello Anthony_0709,

                I think bltdavid is right on the money.

                I would only further suggest declaring the variable to hold the indy in the scope of the class, and calling the indicator to instantiate and assign to the variable in State.DataLoaded.


                In the scope of the class:
                private xyc201 myIndicator;

                In OnStateChange():
                else if (State == State.DataLoaded)
                {
                myIndicator = xyc201(param, param, param, param, param, param);
                }
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi,

                  I also tried: "private List<string> ListOfStrings= new Indicators.xyc201().myListOfStrings;" but got an error: "error on calling 'OnBarUpdate' method on bar 0: Object not set to an instance......" and the strategy wouldn't load. So after commenting out sections of code I was able to determine that the "foreach (string str in ListOfStrings)" was the line.
                  I left off to get some rest and now I'm going to try this approach.

                  Thank you all for your help !

                  Anthony

                  Comment


                    #10
                    Hello Anthony,

                    Adding this to a List object would increase the complexity and is likely unnecessary.

                    Were the suggestions in post #7 and #8 also causing an error? If so, what is the new error message?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I went with post #8 and the strategy didn't load. The error was: <<xyc201 tried to load additional data. All data must be loaded by the hosting NinjaScript in its configure state. Attempted to load.....

                      Comment


                        #12
                        Can you post your strategy here?

                        Comment


                          #13
                          Hello Anthony_0709,

                          This would indicate the hosted indicator is calling AddDataSeries and the host is not.
                          Add all AddDataSeries calls to the host script to resolve the additional data error.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            I was able to get it to work. After accessing the links you posted and reading I could see that my indicator was loading the same data series as the strategy. The problem was with the "private List<string> ListOfStrings= new Indicators.xyc201().myListOfStrings;" approach. So, I went with "xyc201 MyIndicator;"and in (State == State.DataLoaded) {MyIndicator = xyc201(param1, param2,...), this way I was able to get the strategy to load.
                            I have the chart saved to the workspace with the indicator and when I want to startup a strategy I the add/load it to the chart. In the (State == State.Configure) I used AddChartIndicator but noticed that two versions of the indicator would appear with one of them showing properties in the properties pane and the other absolutely nothing. I gather the one without properties is the version added by the strategy. I didn't like this so I removed AddChartIndicator. In the (State == State.Configure) I had MyIndicator = xyc201(param1, param2,...), but I got : "object no set to an instance.....".
                            In (State == State.DataLoaded) {MyIndicator = xyc201(param1, param2,...), it loads fine.
                            But now I've got another problem, the returned list has a value of "System.Collections.Generic.List`1[System.String]". What does this mean ?
                            In the indicator I have: "private List<string> MyRetList = new List<string>();" and
                            #region Properties
                            [Browsable(false)]
                            [XmlIgnore]
                            public List<string> myRetList
                            {
                            get { Update(); return MyRetList; }
                            }
                            #endregion


                            With "Update();" I get "System.Collections.Generic.List`1[System.String]" and without just an empty string.

                            Thanks again to all.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by quantismo, 04-17-2024, 05:13 PM
                            5 responses
                            32 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by proptrade13, Today, 11:06 AM
                            1 response
                            5 views
                            0 likes
                            Last Post NinjaTrader_Clayton  
                            Started by love2code2trade, 04-17-2024, 01:45 PM
                            4 responses
                            34 views
                            0 likes
                            Last Post love2code2trade  
                            Started by cls71, Today, 04:45 AM
                            2 responses
                            10 views
                            0 likes
                            Last Post eDanny
                            by eDanny
                             
                            Started by kulwinder73, Today, 10:31 AM
                            1 response
                            10 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Working...
                            X