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

Subscribing an event to MarketData.Update results in every trade being reported twice

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

    Subscribing an event to MarketData.Update results in every trade being reported twice

    Hello,

    Testing on an FXCM connection, though I am not sure it is relevant.

    I have been using a handler like this Bars.Instrument.MarketData.Update += OnMarketData; in some places rather than an OnMarketData override. The reason for this is that the override is not always needed and leaving in the code unused is very wasteful as it obviously causes that tick/bid/ask stream to be reported. This works fine, but I have noticed on the FXCM connection, however, that this causes every single trade to be reported twice. Can you advise as to why this might be and any way around it?

    I have attached a completely simplified example to reproduce the issue. Add to a tick chart (is what I am using) and monitor the Output. You will see 2 identical prints for each trade. What am I missing?

    Thanks.
    Attached Files

    #2
    Hello pjsmith,

    The way you are subscribing to data is not documented/supported. You would need to include the OnMarketData override when using indicators/strategies. The override is the correct way to access this data. If you don't need OnMarketData in the script then you can comment out or remove the override.

    JesseNinjaTrader Customer Service

    Comment


      #3
      The documentation specifically warns against leaving an empty OnMarketData , because it wastes significant resources. This is what I am trying to avoid. You have no idea why this does not work as expected on this connection? OnMarketData _might_ be required in the indie, depending on the options selected. Rather than write 2 different indies that have to be swapped, it's far better to programmatically enable/disable on startup, if the option is selected. It can't be commented out, because it is sometimes used, depending on options selected.

      The 'unsupported' response is not very helpful!

      Comment


        #4
        Hello pjsmith,

        We don't have documentation for that property so there is no more detail I can provide here other than to avoid using that because its not documented for use. That may be used internally but it is not documented for any type of use case so we can't help on that item. The OnMarketData override is the supported and correct way to get this data in an indicator or strategy.

        I can't provide a suggestion for using OnMarketData optionally based on user input, in general scripts are not intended to be dynamic for data use. For the described use case you would want to make two different scripts if one needs OnMarketData and one does not.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by PaulMohn, Today, 05:00 AM
        0 responses
        7 views
        0 likes
        Last Post PaulMohn  
        Started by ZenCortexAuCost, Today, 04:24 AM
        0 responses
        6 views
        0 likes
        Last Post ZenCortexAuCost  
        Started by ZenCortexAuCost, Today, 04:22 AM
        0 responses
        3 views
        0 likes
        Last Post ZenCortexAuCost  
        Started by SantoshXX, Today, 03:09 AM
        0 responses
        16 views
        0 likes
        Last Post SantoshXX  
        Started by DanielTynera, Today, 01:14 AM
        0 responses
        5 views
        0 likes
        Last Post DanielTynera  
        Working...
        X