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

OnMarketDepth and List<MarketDepthRow>

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

    OnMarketDepth and List<MarketDepthRow>

    Hi! I hope you all are having a good day.

    This code print FALSEs, it shouldn't have the same values?

    Code:
    protected override void OnMarketDepth(MarketDepthEventArgs e)
    {
    	
    	lock (e.Instrument.SyncMarketDepth)
    	{
    		
    		List<MarketDepthRow> rows;
    		if (e.MarketDataType == MarketDataType.Ask)
    			rows = e.Instrument.MarketDepth.Asks;
    		else
    			rows = e.Instrument.MarketDepth.Bids;
    		
    		if (rows.Count - 1 < e.Position)
    			return;
    		
    		if (e.Price == rows[e.Position].Price)
    			Print("true");
    		else
    			Print("FALSE");
    		
    	}
    	
    }

    Thanks for your time.

    #2
    Hello Fernand0,

    Thank you for the post.

    In this case, I wouldnt know what specifically is wrong without Printing to see what values you are actually comparing. I could suggest a print like the following to gague what is happening better:

    Code:
    Print(e.Price + " == " + rows[e.Position].Price);

    I also see this deviates from the OnMarketDepth sample we provide as you are directly assigning collections instead of checking the type and adding or removing or updating.

    You have:
    Code:
    if (e.MarketDataType == MarketDataType.Ask)
    			rows = e.Instrument.MarketDepth.Asks;
    		else
    			rows = e.Instrument.MarketDepth.Bids;
    The sample we provide instead uses:

    Code:
     List<LadderRow> rows	= (e.MarketDataType == MarketDataType.Ask ? askRows: bidRows);
    The differences is the sample uses askRows: bidRows where you use e.Instrument.MarketDepth.Asks or e.Instrument.MarketDepth.Bids;

    Later the data is added to the askRows: bidRows with logic.

    If you are trying to use the rows[e.Position] syntax, I would suggest replicating how this is done in the following sample:




    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      I wouldnt know what specifically is wrong without Printing to see what values you are actually comparing. I could suggest a print like the following to gague what is happening better:

      Code:
      Print(e.Price + " == " + rows[e.Position].Price);
      if you print the prices or if you put an if comparing them, it's the same, i don't care about the prices, i care about them being the same...

      Code:
      private class LadderRow
              {
                  public	string	MarketMaker; // relevant for stocks only
                  public	double	Price;
                  public	long	Volume;
              }
      it's not neccesary, it's just a block of information...


      The question is really simple...

      Why MarketDepth<MarketDepthRow>.List<MarketDepthRow> have different values than MarketDepthEventArgs in the overridden method: OnMarketDepth?


      Please, I request help from other NinjaTrader Customer Service. Who at least wants to try the codes that the user provides.
      Last edited by Fernand0; 09-28-2018, 10:00 AM.

      Comment


        #4
        Hello Fernand0.

        I understand this is what you want to know, and I did previously test what you provided which is why I provided the answer that I had.

        In my test I actually see some true's happening so again this is something that you can test for on your end to find the specific problem. Debugging is not a service our support provides but we can provide educational information to help you develop items on your own.

        if you print the prices or if you put an if comparing them, it's the same, i don't care about the prices, i care about them being the same...
        This is actually not correct. Printing will allow you to review what values are being used which in turn will let you know if they were or were not able to be true. Using an if comparison on two floating point numbers may not be true even if they are the same value, a Print will allow you to easily see this is the case. You can read about this subject here:



        You may need to use Floating-Point Arithmetic to do your comparison correctly but as noted you are deviating from what we provide as a sample of this concept, so using prints will be crucial to making sure what you are doing is valid.

        In your specific test, displaying false is just not enough information to know why the condition was not true. Using a Print to see what the values are, what values were being compared when the condition was false?


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          You may need to use Floating-Point Arithmetic to do your comparison correctly but as noted you are deviating from what we provide as a sample of this concept, so using prints will be crucial to making sure what you are doing is valid.
          What...?
          Your sample don't use List<MarketDepthRow>... what sample? where?
          Please, show me the line. What you provide is a SAMPLE... i don't have to make all my codes exactly the same as your samples...
          What kind of logic is that?


          I'm asking about the functionality of NT platform...
          Again you didn't answer, and you are patronizing now..

          The prices have to be the same... you think that i didn't test them...?
          I made several Prints to see what was going on... the volume is not the same either...

          So... my question remains....
          Why MarketDepth<MarketDepthRow>.List<MarketDepthRow> have different values than MarketDepthEventArgs in the overridden method: OnMarketDepth?
          Last edited by Fernand0; 09-28-2018, 10:48 AM.

          Comment


            #6
            It's pretty clear that you can't help me and you underestimate the users....

            Originally posted by Fernand0 View Post
            Please, I request help from other NinjaTrader Customer Service. Who at least wants to try the codes that the user provides.
            Originally posted by NinjaTrader_Jesse View Post
            Debugging is not a service our support provides but we can provide educational information to help you develop items on your own.
            I'm not even asking for debugging!! WTF
            Last edited by Fernand0; 09-28-2018, 10:52 AM.

            Comment


              #7
              Hello Fernand0,

              Thank you for your patience.

              I am looking into your question further on my end.

              However, e.Instrument.MarketDepth.Asks and e.Instrument.MarketDepth.Bids are not the recommended approach here for OnMarketDepth. These collections in fact are not documented. Comparisons to these collections from your own or from e.Price may not yield an exact match.

              With that said I will provide details when I have them on why exactly they do not match.

              I look forward to assisting you further.

              Comment


                #8
                Hello Patrick, thanks for your time.
                I'll wait your conclusion in this matter

                Originally posted by NinjaTrader_PatrickH View Post
                I am looking into your question further on my end.
                Thanks for your dedication. Sincerely

                Originally posted by NinjaTrader_PatrickH View Post
                However, e.Instrument.MarketDepth.Asks and e.Instrument.MarketDepth.Bids are not the recommended approach here for OnMarketDepth. These collections in fact are not documented. Comparisons to these collections from your own or from e.Price may not yield an exact match.
                Hum.... if this is true, maybe a change should be done in a comment at this example

                Code:
                protected override void OnMarketDepth(MarketDepthEventArgs e)
                        {
                			// protect [B]e.Instrument.MarketDepth.Asks[/B] and [B]e.Instrument.MarketDepth.Bids[/B] against in-flight changes
                			lock (e.Instrument.SyncMarketDepth)
                			{
                ....
                Anyway.. I'm testing it with Simulated Data Feed(market is closed by now)... There is not a single FALSE

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

                Comment


                  #9
                  Got it...

                  When OnMarketDepth starts, the MarketDepthEventArgs.Instrument.MarketDepth has already been changed

                  I upload the image.


                  Thanks for your time.
                  Attached Files

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    However, e.Instrument.MarketDepth.Asks and e.Instrument.MarketDepth.Bids are not the recommended approach here for OnMarketDepth. These collections in fact are not documented. Comparisons to these collections from your own or from e.Price may not yield an exact match.

                    DO NOT USE "Instrument.MarketDepth.Ask and Instrument.MarketDepth.Bid" as Patrick said

                    BUT.. you can keep using "marketDepth" from

                    Code:
                    marketDepth 		= new MarketDepth<MarketDepthRow>(instrument);
                    marketDepth.Update 	+= OnMarketDepth;
                    So, "marketDepth.Asks/Bids[i]" works without problems, even outside the OnMarketDepth method.

                    Regards
                    Last edited by Fernand0; 10-04-2018, 04:29 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Aviram Y, Today, 05:29 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Aviram Y  
                    Started by quantismo, 04-17-2024, 05:13 PM
                    3 responses
                    27 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by ScottWalsh, 04-16-2024, 04:29 PM
                    7 responses
                    36 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by cls71, Today, 04:45 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post cls71
                    by cls71
                     
                    Started by mjairg, 07-20-2023, 11:57 PM
                    3 responses
                    219 views
                    1 like
                    Last Post PaulMohn  
                    Working...
                    X