• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem! Spread..

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

    Problem! Spread..

    Hey! Me! Yes! Your nightmare in the virtual flesh!

    Ok, so, i'm storing every event from DOM(1&2)

    Whenever i want to get the entire ladder, I can, of course, just go back to old events... and rebuild the ladder.

    Now.. the problem comes up when the market makes 1 or more ticks of spread (example: NQ makes 1 tick of spread sometimes)
    The method that reconstructs the ladder, doesn't know this because is based in data from previous events.

    So, how do i get, let's say the "GetCurrentAsk()" and "GetCurrentBid()" inside of an AddOn? (without dependance of the calling file)
    I save the Instrument when I instance the main class. I don't know if i can access from there.


    I'm open to new ideas.

    One idea, would be to get both 0 Position...
    Code:
    double pos0 = Data.First(p => p.Position == 0);
    double Ask0 = Data.First(p => p.Position == 0 && p.MarketDataType == MarketDataType.Ask && p.Time <= pos0.Time);
    double Bid0 = Data.First(p => p.Position == 0 && p.MarketDataType == MarketDataType.Bid && p.Time <= pos0.Time);
    
    if (Ask0.Price - TickSize != Bid0.Price)
        // we have spread
    The problem is that consumes more resources.. and is a mess... if i can get it much cleaner would be awesome


    My regards.
    Fernando.
    Last edited by Fernand0; 09-23-2018, 10:56 PM.

    #2
    Hello Fernand0,

    Thank you for your note.

    So I may best answer your question would you please provide detail on what you mean by the following?

    when the market makes 1 or more ticks of spread (example: NQ makes 1 tick of spread sometimes)

    The following link to the helpguide provides an example of how you could pull the last price from an Addon,

    https://ninjatrader.com/support/help...marketdata.htm

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hey Alan!

      I mean the difference between the Ask price and the Bid price... like in the img that i uploaded

      The MarketDataEventArgs.Ask and MarketDataEventArgs.Bid can work... on every call to register the changes.. i can check the difference.. and save it apart as "Spread".. and then check it in the reconstruction of the ladder to "avoid the spread price"

      Thanks for the idea, is much cleaner and less expensive in resources
      Attached Files

      Comment


        #4
        Alan, can you check this out?

        For some reason MarketDataEventArgs Ask, returns a negative value...


        My Regards.
        Attached Files

        Comment


          #5
          I can solve it with..

          Code:
          args.Instrument.MarketDepth.Asks[0].Price
          args.Instrument.MarketDepth.Bids[0].Price
          But, why there is a negative value on MarketDataEventArgs.Ask and MarketDataEventArgs.Bid when there is spread?

          Sounds like a bug to me, it should return the values without a problem...

          So that's the problem, when there is spread, both values turn negative, god knows why...
          I didn't test it in other instrument than NQ, i leave that to you.

          Comment


            #6
            Hello Fernand0,

            Who is your data provider?

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              CQG, Sim account

              Comment


                #8
                Hello Fernand0,

                Thank you for your response.

                To be clear, you are properly calling the MarketDepth Update as detailed in the Help Guide document linked below?
                If so, then why wouldn't the following work?
                Code:
                		private double askPrice = 0;
                		private double bidPrice = 0;
                		private void OnMarketDepth(object sender, MarketDepthEventArgs e)
                		{
                			if (e.Position == 0 && e.MarketDataType == MarketDataType.Ask)
                				askPrice = e.Price;
                			if (e.Position == 0 && e.MarketDataType == MarketDataType.Bid)
                				bidPrice = e.Price;
                			
                			if (Math.Abs(askPrice - bidPrice) > 1 * TickSize)
                				Print("*** THIS IS A SPREAD LARGER THAN 1 TICK ***");
                			Print("Ask: " + askPrice);
                			Print("Bid: " + bidPrice);
                			Print("Diff: " + (Math.Abs(askPrice - bidPrice)));
                		}
                I may not understand the full scope of what you are attempting here. Please let me know if there is more to this than simply checking the difference between the Ask and Bid Price at the most recent updates at the Position of 0.

                Please let me know if you have any questions.
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Patrick, your approach is correct... but I'm not using Depth, I'm using Data... I'll show you a simple code....

                  Code:
                  protected override void OnMarketData(MarketDataEventArgs args)
                  		{
                  			
                  			Print("Ask: " + args.Ask);
                  			Print("Bid: " + args.Bid);
                  			
                  		}
                  I'm not even in the AddOn.. i tested IN the AddOn.. and i saw troubles.... so i went back to the Indicator

                  MarketDataEventArgs shows the parameters "Ask" and "Bid" to be accessible all the time. I noticed when a Spread shows up, the price goes negative sometimes.
                  It's just what i saw, i couldn't confirm it.

                  BTW. Thanks for your time and patience
                  Last edited by Fernand0; 09-28-2018, 03:46 PM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Arkadiy_B, Today, 06:43 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Arkadiy_B  
                  Started by leontancfa, Today, 06:09 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_PatrickG  
                  Started by soulfx, 12-01-2017, 08:44 AM
                  3 responses
                  1,019 views
                  0 likes
                  Last Post NinjaTrader_EricB  
                  Started by Parmenides48, 04-09-2019, 03:32 AM
                  10 responses
                  53 views
                  0 likes
                  Last Post NinjaTrader_PatrickG  
                  Started by NinjaCustomer, Today, 01:48 AM
                  1 response
                  13 views
                  0 likes
                  Last Post NinjaTrader_EricB  
                  Working...
                  X