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 & Multiinstruments

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

    OnMarketData & Multiinstruments

    As far as I know there is no way to associate an event to the instrument that generated.
    When using multiple time frames for the same instrument, you get as many events as add(instrument) you put. A consequence of this multiply the results unnecessarily

    I think Barinprogress does not work outside of onbarupdate At least do not .Into OMD

    Maybe add an implementation with an argument more or increase the DataType enumeration.

    In my opinion this is necesary

    Thank you very much,

    #2
    Hello Ramon,
    Thanks for writing in and I am happy to assist you.

    BarsInProgress can be called from the OnMarketData method.

    If you have a multi-instrument indicator BarsInProgress will be unique for each instrument.
    But in case of a multi time frame indicator, BarsInProgress will return the first BarsInProgress that matches the instrument i.e. if you have ES 03-12 one minute chart as the primary series and ES 03-12, five minute chart as the secondary series then BarsInProgress will return 0 only.



    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Something like that:
      Code:
          protected override void Initialize()
              {
                  Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
       //           Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
      //            Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
      
                   Add("NQ 03-12", PeriodType.Tick, 1, MarketDataType.Last); // nasdaq
      
              }
               protected override void OnMarketData(MarketDataEventArgs e) 
              {
                  if(e.MarketDataType==MarketDataType.Last)
                  {
                      if (BarsInProgress == 0)
                      {
                      Print("BIP==0  Time    = " + e.Time);
                      Print(" BIP==0 Price    = " + e.Price);
                      Print("BIP==0  Volume = " + e.Volume);
                      }
                      else if (BarsInProgress == 1)
                        {
                      Print("BIP==1  Time    = " + e.Time);
                      Print(" BIP==1 Price    = " + e.Price);
                      Print("BIP==1  Volume = " + e.Volume);
                      }
                     else if (BarsInProgress ==2)
                        {
                      Print("BIP==2  Time    = " + e.Time);
                      Print(" BIP==2 Price    = " + e.Price);
                      Print("BIP==2  Volume = " + e.Volume);
                      }
               
                          }
              }
      give that results:
      BIP==0 Time = 16/02/2012 23:59:53
      BIP==0 Price = 1355,25
      BIP==0 Volume = 2
      BIP==2 Time = 16/02/2012 23:59:53
      BIP==2 Price = 2593,75
      BIP==2 Volume = 2
      BIP==0 Time = 16/02/2012 23:59:54
      BIP==0 Price = 1355,25
      BIP==0 Volume = 252
      BIP==0 Time = 16/02/2012 23:59:54
      BIP==0 Price = 1355,25
      BIP==0 Volume = 252
      BIP==2 Time = 16/02/2012 23:59:54
      BIP==2 Price = 2593,75
      BIP==2 Volume = 3
      BIP==0 Time = 16/02/2012 23:59:55
      BIP==0 Price = 1355
      BIP==0 Volume = 3
      BIP==0 Time = 16/02/2012 23:59:55
      BIP==0 Price = 1355
      BIP==0 Volume = 3
      BIP==0 Time = 16/02/2012 23:59:56
      BIP==0 Price = 1355
      BIP==0 Volume = 1
      BIP==0 Time = 16/02/2012 23:59:56
      BIP==0 Price = 1355
      BIP==0 Volume = 1
      BIP==0 Time = 16/02/2012 23:59:57
      BIP==0 Price = 1355
      BIP==0 Volume = 6
      BIP==0 Time = 16/02/2012 23:59:57
      BIP==0 Price = 1355
      BIP==0 Volume = 6
      All of BIP==0 are duplicated.
      Attach complete indicator if you want to check
      Attached Files

      Comment


        #4
        Right now I'm just interested in BID / ASK / LAST both on-line and historical. This led me to try to add instruments BID / ASK / LAST to basically treat them in back-test.
        Finding that OnMarketData going on, I realized that arrived four repeated events and could not distinguish them by BIP. This led me to a wrong conclusion and that is that BIP did not work at OMD. I apologize for this.

        If you want you can move this thread to general programming or another forum. I have a lot of questions about these issues and I would like to develop in the future.
        Last edited by Ramon; 02-17-2012, 03:40 AM.

        Comment


          #5
          Hello Ramon,
          Glad you could understand the concept.

          Also please note OnMarketData is a real time data stream, and is not called on backtest.

          For backtest you have to create a multi-series strategy, with the Bid/Ask price as the additional data series.

          Also as per your request the thread had been moved to general programming.

          I look forward to assist you further.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Here I am, again with the same problem. I'm using multiseries to backtest and although data are not very reliable, it serves my purposes.

            The problem is that when indicator comes to the present, OMD receives an event for each instrument and all are classified as BIP = 0.

            OMD is able to distinguish between instruments with different names, ie ES or NQ, but is not able to do so whith same name but different time frames.

            I can only do the following:

            protected override void OnMarketData(MarketDataEventArgs e)
            (if (dLastPrice==e.Price && lLastVolume==e.Volume && tStamp==e.Time)
            return;
            )
            I don't now if I'm doing the right thing. Is there any native way to distinguish events? TThere are a lot of unexplored stuff like : "Bars." , "Instrument." , "BarsPeriod." etc.
            Can you eliminate instruments with something like Dispose() or other methods? So I can do something like:
            Code:
             
            if (Historical)
                use it;
            else dispose it;
            Thanks
            Last edited by Ramon; 03-01-2012, 05:18 AM.

            Comment


              #7
              Hello Ramon,
              OnMarketData is a realtime stream only. It cannot be backtested.

              From the help files
              This method is not called on historical data (backtest)
              http://www.ninjatrader.com/support/h...marketdata.htm

              Since it is a realtime stream, only one stream will be created for each instrument.

              Unfortunately Bars etc classes which are not documented in the help file are not supported.

              We would not recommend Disposing any BarsArray as this can adversely affect the functioning of the NinjaScript and can break NinjaTrader.

              Please let me know if I can assist you any further.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Joydeep View Post
                Hello Ramon,
                OnMarketData is a realtime stream only. It cannot be backtested.
                .
                omg. How hard is to explain things properly:
                Can I add a bid ,ASK, last series and then access their historical values in a indicator ?

                Can I use OnMarketData() for realtime use ?

                Code:
                if (Can I use historical series && OnMarketData)
                    How can you do that if BIP into OMD  doesn't work?
                else
                    Good bye. It was a pleasure. I think I 'll know how to manage matters into my own hands

                Thanks

                Comment


                  #9
                  omg. How hard is to explain things properly: [Brett] No problem you explain just fine.

                  Can I add a bid ,ASK, last series and then access their historical values in a indicator ?
                  http://www.ninjatrader.com/support/h....html?add3.htm

                  [Brett] - Yes you can do that, considering your provider supports ask and bid data or you have recorded this data yourself.

                  Can I use OnMarketData() for realtime use ?

                  [Brett] Yes

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Barry Milan, Today, 10:35 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Barry Milan  
                  Started by DJ888, Yesterday, 06:09 PM
                  2 responses
                  9 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  40 views
                  0 likes
                  Last Post jeronymite  
                  Started by bill2023, Today, 08:51 AM
                  2 responses
                  16 views
                  0 likes
                  Last Post bill2023  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  167 responses
                  2,260 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X