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

OnMarket* does not fire on market replay

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

    OnMarket* does not fire on market replay

    Hello everybody,

    I recently downloaded the DepthReferenceSample provided herein by Ray and tried to run it on replay. The indicator shows nothing, so I put it to debug in Visual studio and to my surprise the breakpoints in OnMarketData() and OnMarketDepth() are never hit since the code never enters these methods. The breakpoints are valid (I'm debugging correctly) so I wonder what this might be caused by, i.e. why the events never fire.

    Any help is much appreciated,
    Daniel.

    #2
    Daniel, can you please clarify which example you attempt running?

    There would be specific updated one to use for the recent NT7 :

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand, my apologies, I am blind. The NT7 version fires them all.
      Regards,
      Daniel

      Comment


        #4
        Bertrand, just to be on the safe side.

        OnMarketData() goes through the L1 data (i.e. executed trades) and within each call I can get the Bid+Ask+Last price which belong to each other, right? I'm basically asking whether I can access the Bid/Ask prices of each trade in OnMarketData.

        Thank you,
        Daniel.

        Comment


          #5
          Hi Daniel, OnMarketData() is called for each Level 1 data change, so you decide whatever it 'listens' to http://www.ninjatrader.com/support/h...aeventargs.htm

          Those are all individual events though and the trade is not stored with associated bid / ask data at that time.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Bertrand,
            thank you for the reply. So, if I receive a e.MarketDataType == MarketDataType.Last type of event notifying of a trade, can I access the Bid/Ask valid at the time of trade via GetCurrentBid/Ask()?

            Daniel

            Comment


              #7
              Hi Daniel, those methods event timing would be tied to the OnBarUpdate() - you can store the last known bid / ask values in the OnMarketData() and then you would have access to those as the Last event is seen.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Hello Bertrand,

                this is what you meant? The code fires OnMarketData() only sometimes meanwhile there are lots of bid/ask changes that do not result in an OnMarketData(). What am I doing wrong?

                Best regards,
                Daniel

                protected override void OnMarketData(MarketDataEventArgs e){
                if (e.MarketDataType == MarketDataType.Last){
                Print("");
                Print("Ask = " + LastAsk + "@" + LastAskContracts );
                Print("Bid = " + LastBid + "@" + LastBidContracts );
                }
                else if (e.MarketDataType == MarketDataType.Ask){
                LastAsk = e.Price;
                LastAskContracts = e.Volume;
                Print("Updating Ask = " + LastAsk + "@" + LastAskContracts );
                }
                else if (e.MarketDataType == MarketDataType.Bid){
                LastBid = e.Price;
                LastBidContracts = e.Volume;
                Print("Updating Bid = " + LastBid + "@" + LastBidContracts );
                }
                }

                Comment


                  #9
                  Eubie, I would rather use this slightly changed logic :

                  Code:
                  protected override void OnMarketData(MarketDataEventArgs e)
                  		{
                  			if (e.MarketDataType == MarketDataType.Last)
                  			{
                  				Print("");
                  				Print("Ask = " + LastAsk + "@" + LastAskContracts );
                  				Print("Bid = " + LastBid + "@" + LastBidContracts );
                  			}
                  			
                  			if (e.MarketDataType == MarketDataType.Ask)
                  			{
                  				LastAsk = e.Price;
                  				LastAskContracts = e.Volume;
                  				Print("Updating Ask = " + LastAsk + "@" + LastAskContracts );
                  			}
                  			
                  			if (e.MarketDataType == MarketDataType.Bid)
                  			{
                  				LastBid = e.Price;
                  				LastBidContracts = e.Volume;
                  				Print("Updating Bid = " + LastBid + "@" + LastBidContracts );
                  			}
                  		}
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Bertrand thank you for the reply. However, the problem persists. The first entry to the function OnMarketData() happens 25 minutes after midnight (using yesterdays CL 11-11 data) after several non-empty bars were drawn with volume in tens of contracts. I'm using market replay. Any hints?

                    Regards,
                    Daniel.

                    Comment


                      #11
                      Eubie, was this data self recorded or downloaded from our server? If you right click in the replay control - what availability for Level 1 data is the shown for it?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        The data was downloaded from your server. As for the timestamps, see the included screen.

                        Daniel.
                        Attached Files

                        Comment


                          #13
                          Thanks, checked into here and it seems to work for me - are you working from an indicator or strategy here? Can you please ensure there are historical bars on the chart you replay from before you start it?
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Ah, that seems to be the cause, I don't have any historical data. Could I ask you Bertrand about what steps I need to do in order to run the discussed script on all market replay data on e.g. CL contracts (say 02-11)? I don't know how to load historical prices for days before the date on which first market replay is available for the given instrument. Say, I have market replay for CL 02-11 from 14th Sep 2010 till 20th Jan 2011 and I would like for each tick that occured to export the Bid/Ask/Last value. How can I start this export from the 14th Sep as there is no historical data reaching before that date? Any hint is highly appredicated.

                            Best regards,
                            Daniel.

                            Comment


                              #15
                              Hi Daniel, you would need to load each day separately for your contracts / expiries of interest via File > Utilities > Download Replay Data and then you could run the replay across day / session breaks seamlessly.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              31 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,282 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Working...
                              X