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

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by StockTrader88, 03-06-2021, 08:58 AM
    45 responses
    3,992 views
    3 likes
    Last Post johntraderuser2  
    Started by TAJTrades, Today, 09:46 AM
    0 responses
    7 views
    0 likes
    Last Post TAJTrades  
    Started by rhyminkevin, Yesterday, 04:58 PM
    5 responses
    62 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by realblubb, Today, 09:28 AM
    0 responses
    8 views
    0 likes
    Last Post realblubb  
    Started by AaronKoRn, Yesterday, 09:49 PM
    1 response
    19 views
    0 likes
    Last Post Rikazkhan007  
    Working...
    X