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 rbeckmann05, Yesterday, 06:48 PM
    1 response
    12 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Working...
    X