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

How to expose non-series indicator data?

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

    How to expose non-series indicator data?

    Hi
    I would like some help exposing indicator data to calling strategies. My knowledge of how properties work is not thorough enough and I'd appreciate any advice.
    My indicator creates a list of objects whose properties I want to access from one or more strategies (in addition to series values). This is what I've tried. It compiles but I don't get the data I expect.
    In the indicator file, outside the indicator class, but within the NinjaScript.Indicator namespace, I define a class SDZone, which has several properties I want strategies to access.


    Instances of SDZone are created in the indicator and added to a list of SDZone defined in the indicator.
    Code:
    List<SDZone> zoneList
    …
     zoneList.Add( new SDZone(...) );
    I have made zoneList a property of the indicator.
    Code:
    [Browsable(false)]
     [XmlIgnore]
     public List<SDZone> zoneList
     { get; set; }
    In the strategy, I create a List<SDZone> stratZoneList, and I assign it the indicator property zoneList.
    Code:
    private List<SDZone> stratZoneList;
     …
     stratZoneList = indicator.zoneList;
    Within the strategy, I hoped to be able to access the contents of the list created in the indicator like this:
    Code:
    foreach ( SDZone z in stratZoneList )
     {
    if ( z == null )
    
        Print( "z == null" );
      else
    
        Print( "This is z: " + z.sdZoneProp1.ToString() );
     }
    However, although z is never null, its count is always 0.


    Any help would be welcome.
    Cheers
    Tony

    #2
    Hi

    I have answered my own question now, and I thought it might be useful to share it.
    Note: I'm using NT8 Beta 7

    Two key points:

    1. My strategy doesn't use the series values of the indicator so I didn't call them. However, if they are not called none of the indicator data is updated. I resolved this by simply assigning the current indicator value to a temporary variable within OnBarUpdate() before any other indicator data is used.

    2. You can't just assign a list to a new one and expect the contents to be accessible. I resolved this within the strategy by using the indicator list property directly, e.g.
    Code:
    [SIZE=2]foreach ( SDZone z in indicator.zoneList )
    {
       if ( z == null )
          Print( "z == null" );
       else
          Print( "This is z: " + z.sdZoneProp1.ToString() );
    }[/SIZE]
    Cheers
    Tony
    Last edited by Jellybean; 01-05-2016, 01:50 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 04-23-2024, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    193 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,235 views
    0 likes
    Last Post xiinteractive  
    Working...
    X