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, 01: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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X