• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData and Drawing Tools... AttachedTo is null unless chart is refreshed

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

    OnMarketData and Drawing Tools... AttachedTo is null unless chart is refreshed

    I am building a Drawing Tool that requires OnMarketdata() support. I was told by Patrick H to place this in OnStateChange() when State.Active. Something similar to this:

    if (AttachedTo != null)
    {
    marketData = new MarketData(AttachedTo.Instrument);
    marketData.Update += OnMarketData;
    }

    The problem is, "AttachedTo" is always null when you first place the drawing object on the chart. Once you refresh the chart, it runs fine.

    I believe the problem is that all the States are run/handled before the object is actually placed onto the chart. Thus, AttachedTo is null, thus it never adds the event handler. When you refresh the chart, it's already attached, so it works fine.

    Is there a better place to add the event handler other than OnStateChange()? In OnRender() (not liking this option)? OnMouseDown()?

    Thank you
    Last edited by neoikon; 12-02-2019, 12:52 PM.

    #2
    Hello neoikon,

    Thanks for your question.

    It would be appropriate to subscribe to the MarketData event in OnRender when GetAttachedToChartBars gives a valid value and can be used to fetch the instrument. I have attached an example that uses GetAttachedToChartBars in OnRender and subscribes to MarketData events on the first OnRender pass.

    Please let us know if we can be of further assistance.
    Attached Files
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Sh00tHerMcGavin, Today, 07:39 PM
    0 responses
    1 view
    0 likes
    Last Post Sh00tHerMcGavin  
    Started by Mberg, Today, 05:13 PM
    0 responses
    0 views
    0 likes
    Last Post Mberg
    by Mberg
     
    Started by Barry Milan, Today, 01:33 PM
    2 responses
    8 views
    0 likes
    Last Post marcus2300  
    Started by NW Trader, Today, 03:42 PM
    2 responses
    7 views
    0 likes
    Last Post NW Trader  
    Started by ralett, Today, 01:42 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Working...
    X