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

OnMarketData ,Historical prints.

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

    OnMarketData ,Historical prints.

    About OnmarketData ,Help Guide Says: This method is not called on historical data.

    i'm codifying an indicator about deltas , actually is quite simple but enough to my needs. It use OnMarketData but only gets data for the last bar, even that are lost when reload ninjascript.

    I can see as indicators like Volume Foot prints has different behavior from NT 6,5 to 7. Now a days can fill whole the chart from several bars ago and I am wondering if there is a new way in NT 7 to get historical prints as well as the bid/ask positions

    Thanks

    #2
    Hi Ramon, the OnMarketData() workings in NT7 would still be for realtime use only - what we've added in NT7 is multiseries indicator support, so you could for example add a bid / last series and then access their historical values in your code.



    BertrandNinjaTrader Customer Service

    Comment


      #3
      It sounds fantastic. I'll try it (if i know how to)

      Comment


        #4
        I don't know if i understand the correct use of multiseries.

        I'm trying something like the next:
        Code:
               protected override void Initialize()
                {
                CalculateOnBarClose    = false;  
                Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
                Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
                Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
                   BarsRequired = 2;
                }
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress == 0)
                    {
                        if (FirstTickOfBar)
                        {
                            dLastPrice = 0;
                            dAskPrice = 0;
                            dBidPrice = 0;
                            lBidVolume=0;
                            lAskVolume=0;
                            lDeltas=0;
                        }
                    }
                     if (Historical)
                     {
                        HistoricalBranch();
                    }
        
                }
                protected override void OnMarketData(MarketDataEventArgs e) 
                {
                if (BarsInProgress == 0)
                {    
                    CalcDeltas( e.MarketDataType,  e.Price, e.Volume);
                }    
        
                private void HistoricalBranch()
                {
                if (CurrentBars[0] <= BarsRequired)       return;
                    if (BarsInProgress == 0)
                    {
                    }
                    else if (BarsInProgress == 1)
                    {
                    DataType=MarketDataType.Last;
                    }
                    else if (BarsInProgress ==2)
                    {
                    DataType=MarketDataType.Bid;
                    }
                    else if (BarsInProgress == 3)
                    {
                     DataType=MarketDataType.Ask;
                    }
                    CalcDeltas( DataType,  Close[0], (long) Volume[0]);
        
                }
                private void CalcDeltas(MarketDataType DataType, double dPrice, long lVolume)
                {    
                if (DataType == MarketDataType.Last)
                {
                    if ((dPrice > dBidPrice ) && (dPrice >= dAskPrice))
                        //  ASK  => BUY
                        {
                            lAskVolume +=  lVolume;
                            lDeltas += lVolume;
                        }
                     else
                        //  BID  => SELL
                        {
                             lBidVolume +=  lVolume;
                            lDeltas -= lVolume;
                        }
        
                     // Do things like draw text , diamonds, etc.
                        DrawThings(dPrice,lAskVolume,lBidVolume,lDeltas);
                 }
                   else if (DataType == MarketDataType.Ask)
                        dAskPrice = dPrice;
                    
                else if (DataType == MarketDataType.Bid)
                        dBidPrice = dPrice;
            
                }
        ]Historical data doesn't bear any resemblance with online data and when ONMARKETDATA starts , data are exactly correct but multiply by four.

        After uncountable variations i've got into a deep rut
        Any suggestion?

        Comment


          #5
          Could you please contact me at support at ninjatrader dot com Attn Bertrand with a script I could run here to understand better?

          The BIP call is OnMarketData() is meant for distinguishing between different instruments, it would return BIP0 for all series if you only deal with one instrument.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            done.

            Thanks in advance
            Ramon

            Comment


              #7
              Thanks, I received the script and will take a look shortly.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Hello I am facing same issue, could please provide piece of code, that solves this on historical data?

                Comment


                  #9
                  Hello kujista, thanks for your post.

                  My test script is not multiplying anything by 4. If you do this it will give you a stream of bid, ask, and last prices in the style of the T&S window:

                  Code:
                          protected override void Initialize()
                          {
                              CalculateOnBarClose    = false;  
                              Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
                              Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
                              Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
                              BarsRequired = 2;
                              Overlay                = true;
                          }
                  
                          protected override void OnBarUpdate()
                          {
                              if(BarsInProgress == 1)
                              {
                                  Print("DataType.Last " + Close[0]);
                              }
                              if(BarsInProgress == 2)
                              {
                                  Print("DataType.Bid " + Close[0]);
                              }
                              if(BarsInProgress == 3)
                              {
                                  Print("DataType.Ask " + Close[0]);
                              }
                  
                          }
                  If there is a specific problem you would like to look into, please provide details on that.

                  Kind regards.
                  Chris L.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  16 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  106 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  609 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X