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

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 cmtjoancolmenero, Yesterday, 03:58 PM
    11 responses
    41 views
    0 likes
    Last Post cmtjoancolmenero  
    Started by FrazMann, Today, 11:21 AM
    0 responses
    5 views
    0 likes
    Last Post FrazMann  
    Started by geddyisodin, Yesterday, 05:20 AM
    8 responses
    52 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by DayTradingDEMON, Today, 09:28 AM
    4 responses
    27 views
    0 likes
    Last Post DayTradingDEMON  
    Started by George21, Today, 10:07 AM
    1 response
    22 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Working...
    X