Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Storing variables using OnMarketData...Is it a different procedure?

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

    Storing variables using OnMarketData...Is it a different procedure?

    Hi,

    I have been experimenting today with the OnMarketData code below. The code prints to the output window with no problems but I'm not sure how to save the most recent Last, Ask and Bid data as a variable, which is what I want to try doing.

    Code:
    protected override void OnMarketData(MarketDataEventArgs e)
    {
         // Print some data to the Output window
         if (e.MarketDataType == MarketDataType.Last)
              Print("Last = " + e.Price + " " + e.Volume);
         else if (e.MarketDataType == MarketDataType.Ask)
              Print("Ask = " + e.Price + " " + e.Volume);
         else if (e.MarketDataType == MarketDataType.Bid)
              Print("Bid = " + e.Price + " " + e.Volume);
    }
    Is the procedure somewhat different to using other methods like OnBarUpdate as I have tried this without any success so far?

    A small explanation would be very much appreciated.

    Regards,
    suprsnipes

    #2
    Hello,

    It would be better off in this case that you post your code that you attempted to do this with so I can spot the error. As there really shouldnt be anything special here. Just make sure you declare your variable outside of the function so that variable has scope between both OnBarUpdate() and OnMarketData(), as if you declare the variable in OnMarketData() you will only have access to it in OnMarketData(). The simply set the variable in OnMarketData().

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    594 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X