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

issue calling indicators list class from strategy

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

    issue calling indicators list class from strategy

    hi everyone,

    Problem : would anyone be able to spot and tell us what is causing the issue below ? from the quick description below :

    A public list is created in a copy of the ZigZag indicator like so :
    Code:
    public List<MyList> myList = new List<MyList>();
    protected override void OnBarUpdate()
    {
    // some code adding things to MyList
    }
    public class MyList
    {
    private double myDouble;
    private int myInt;
    
    public myList(double myDouble, int myInt) {this.myDouble = myDouble; this.myInt = myInt}
    
    public double MyDouble { get { return myDouble; } set { myDouble = value; } }
    public int MyInt { get { return myInt; } set { myInt = value; } }
    }
    this list works well in the indicator.

    When we try to print MyList values from a strategy, we find troubling results :
    Code:
    // zzW2 is the ZigZag copy containing the list
    
    // case A :
    Print("");
    Print("BarsInProgress is : " + BarsInProgress);
    Print("CurrentBars[BarsInProgress] is : " + CurrentBars[BarsInProgress]);
    //Print("zzW2.HighBar(1,1,100) is : " + zzW2.HighBar(1,1,100)); // note this is commented on purpose, we will uncomment it next case
    Print("zzW2.MyList.Count() is : " + zzW2.MyList.Count());
    // above code outputs :
    // BarsInProgress is : 1
    // CurrentBars[BarsInProgress] is : 53234
    // zzW2.MyList.Count() is : 0
    
    // case B :
    Print("");
    Print("BarsInProgress is : " + BarsInProgress);
    Print("CurrentBars[BarsInProgress] is : " + CurrentBars[BarsInProgress]);
    Print("zzW2.HighBar(1,1,100) is : " + zzW2.HighBar(1,1,100)); // note this is uncommented
    Print("zzW2.MyList.Count() is : " + zzW2.MyList.Count());
    // above code outputs :
    // BarsInProgress is : 1
    // CurrentBars[BarsInProgress] is : 53234
    // zzW2.HighBar(1,1,100) is : 5
    // zzW2.MyList.Count() is : 7718
    Is it zzW2 that is not adding things to the list in case A or is the issue from the strategy ? Can we allready conclude about it from the given examples ?
    Why would they both appear to work great if we call zzW2.HighBar() in case B ? and not in case A.
    Should the indicator not add things by itself without HighBar() beeing called ?

    #2
    Hello Amedeus,

    Thank you for your post.

    When you're calling the HighBar method, that includes a call to Update() which needs to be done prior to accessing a public variable like your list. Since this gets called there, you don't need to call it again to have MyList populated.

    I'd take a look at how the example on this page of our help guide calls Update before returning the public variable:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3

      hi Kate, thank you very much !

      Since it creates complications (cs0038 error) to add Update() in the getter of MyList,
      I just checked if HighBar() is not null early in the strategy's code (wich is very similar to what we were trying to do in the first place : check MyList.Count()>someInt)
      and it appears to work well.


      For educational puposes :
      Could it be worth to work around the cs0038 error and add Update() in the indicators code near MyList somehow ? then in the strategy only check for MyList.Count().
      If yes, why, and what somehow could look like ? I dont think we can have MyList static, it is all public allready and I was not able to figure this out.

      Comment


        #4
        Hello Amedeus,

        Thank you for your reply.

        I'm not sure what error CS0038 is off the top of my head. What's the full text of that error message?

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          hi Kate, thank you,

          the error message is : Cannot access a nonstatic member of outer type 'type1' via nested type 'type2'
          this happens when we try to implement the getter of the list with the Update(); syntax like the getters of the series, like the help Guide example... it just appears not to work the same.

          the msdn suggestion is :
          A field in a class is not automatically available to a nested class. To be available to a nested class, the field must be static. Otherwise, you must create an instance of the outer class. For more information, see Nested Types.

          My question was : would it be worth to create an instance of the outer class and what would it look like ? would it be added in the indicator or the strategy ? would it help regarding the code efficiency (compared to calling HighBar()), the neatness of it ?

          Comment


            #6
            Hello Amedeus,

            Thank you for your reply.

            If you can implement just the part you are having trouble with in a separate script, and share it with us, that would be extremely helpful. I would hazard a guess that you're trying to call Update() from a nested class, but would need further detail to know.

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            147 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            5 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Started by tkaboris, Today, 05:13 PM
            0 responses
            4 views
            0 likes
            Last Post tkaboris  
            Started by GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,282 views
            0 likes
            Last Post Leafcutter  
            Working...
            X