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
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by theleptous, Yesterday, 10:46 PM
    0 responses
    4 views
    0 likes
    Last Post theleptous  
    Started by theleptous, Yesterday, 10:44 PM
    0 responses
    5 views
    0 likes
    Last Post theleptous  
    Started by bumkhgbdqwop, Yesterday, 10:42 PM
    0 responses
    6 views
    0 likes
    Last Post bumkhgbdqwop  
    Started by Uhnahwpfs, Yesterday, 09:41 PM
    0 responses
    6 views
    0 likes
    Last Post Uhnahwpfs  
    Started by traderdanny, Yesterday, 08:33 PM
    0 responses
    25 views
    0 likes
    Last Post traderdanny  
    Working...
    X