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

Trouble returning custom Lists as Properties

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

    Trouble returning custom Lists as Properties

    Hi, I've been having difficulty returning custom lists, calculated in Indicator "B" to Indicator "A". I've set up the List<T> in Indicator B and populated it successfully. When I debug Lndicator B, I can see all the elements in my List<T> correctly populated and Indicator B uses the contents of my List<T> correctly to draw results on my chart panel. However, when I attempt, in Indicator A to retrieve my Indicator B List<T> as a Property, the Count of List<T> always shows as 0. Is there a limitation on the types that can be exposed as Properties in the NinjaTrader Indicators?

    For instance, here's a snippet from a simple Indicator that marks bar reversal highs and lows and draws lines between them. The code adds the end points of each line, and some date information to a list of price swings ("swingList), which is a TradingList : List<T>. It then draws lines between the end point of the previous swing and the end point of the latest swing. This works fine.

    ...

    if( reversalList.Count > 1 ) {

    JimsSupportFuncs.ReversalBar rbEarlier = (JimsSupportFuncs.ReversalBar) reversalList.ElemAt(1);
    JimsSupportFuncs.ReversalBar rbLater = (JimsSupportFuncs.ReversalBar) reversalList.ElemAt(0);



    if( rbEarlier.isHighOrLow() == IS_LOW ) {
    JimsSupportFuncs.PriceSwing prs = new JimsSupportFuncs.PriceSwing( rbEarlier.getCurrentBar(), rbLater.getCurrentBar(), rbEarlier.getBarTime(), rbLater.getBarTime(), rbEarlier.getLow(), rbLater.getHigh() );
    swingList.LimitedAdd(prs);

    Draw.Line( this, "SwingLine"+CurrentBar, CurrentBar-((JimsSupportFuncs.PriceSwing)swingList.ElemAt(0)) .getStartCurrentBar(), ((JimsSupportFuncs.PriceSwing)swingList.ElemAt(0)) .getStartPrice(), CurrentBar-((JimsSupportFuncs.PriceSwing)swingList.ElemAt(0)) .getEndCurrentBar(), ((JimsSupportFuncs.PriceSwing)swingList.ElemAt(0)) .getEndPrice(), Brushes.Cyan);
    }

    }

    ...

    I attempt to make swingList available to other Indicators that might instantiate the SwingFinder Indicator, as follows:

    #region Properties
    ...

    [Browsable(false)]
    [XmlIgnore]
    public JimsSupportFuncs.TradingList<JimsSupportFuncs.Pric eSwing> SwingList
    {
    get { return swingList; }
    }

    ...
    #endregion


    When I attempt to retrieve swingList, I get "something", a TradingList of type PriceSwing, but it always has a Count of 0.

    ...

    JimsSupportFuncs.TradingList<JimsSupportFuncs.Pric eSwing> swTest = swings.SwingList; // Always has a count of 0

    ...

    Any thoughts on how I can resolve this would be greatly appreciated.

    #2
    Hello Jambo,

    Thank you for the post.

    I wanted to check, have you formed the property for the list similar to the property in the following example?



    The Update() method would need to be called in the property like shown in the sample, there can be other stipulations surrounding this type of development so if that is not the solution I would very likely need to see a working sample of the problem. If you have two dummy indicators which simply demonstrate the code you use that does not work, we can review that together.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, Jesse, for your prompt reply. I did not use use Series<T> because I didn't want the "calling" Indicator to have to evaluate whether each element in the returned List is valid, using IsValidDataPoint(0). My List<T> contains no invalid elements. I only add elements that contain intentional data, and elements in my List<T> appear at a lower frequency than Series<T> objects. Since I posted here, I've been doing some reading about trying to expose List<T> objects in C#, and it appears that it is frowned upon, as it allows calling objects to modify the exposed list, which the owning object may not want to allow. IList<T> or Collection<T> are recommended instead. I wonder if this is the source of the problem?

      Comment


        #4
        Hello Jambo,

        You can generally expose any type of property you want assuming you use the correct modifier and attributes, however, if that relies on OnBarUpdate to be called to get its values and it is not a NinjaScript type like a Plot or Series you need to use Update() method like that sample shows with its double property. There is a note in the sample:

        // We need to call the Update() method to ensure our exposed variable is in up-to-date.

        This could be the solution with your list to ensure the variables value is up to date when being accessed. You can place this in the public property like shown in the sample before returning the value.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Bless you, Jesse! Adding and Update() statement to the get method did the trick. Thanks very much!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by f.saeidi, Today, 05:56 AM
          2 responses
          8 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          36 views
          0 likes
          Last Post Pattontje  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          7 responses
          27 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Skifree, Today, 03:41 AM
          2 responses
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by trimpy, Today, 04:38 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X