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

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,



    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.

                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 chartchart, 05-19-2021, 04:14 PM
                  3 responses
                  577 views
                  1 like
                  Last Post NinjaTrader_Gaby  
                  Started by bsbisme, Yesterday, 02:08 PM
                  1 response
                  15 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by prdecast, Today, 06:07 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post prdecast  
                  Started by i019945nj, 12-14-2023, 06:41 AM
                  3 responses
                  60 views
                  0 likes
                  Last Post i019945nj  
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  18 views
                  0 likes
                  Last Post TraderBCL  
                  Working...
                  X