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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    54 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    25 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    17 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    24 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X