Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

problem with getcurrentbid / getcurrentask

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

    problem with getcurrentbid / getcurrentask

    hi,

    I'm having a problem with a script that is intended to select one of multiple instruments. I have a loop as below, that is intended to ensure only executing a trade when the spread is beneath a threshold. I understood that getcurrentbid and getcurrentask are overloaded such that if I put in i as a parameter it would get the bid and ask of the instrument that corresponds with the bar series i.

    When I run the loop below and examine the output, I find that irrespective of whether it's bar 1 or 2 (two futures of same instrument, different maturity), it will display the spread of the near future.

    Could you please assist ?

    for (i=1; i<Instruments.Length; i++)
    {
    Bid = GetCurrentBid(i);Ask = GetCurrentAsk(i);
    if(Bid > 0 && Ask > 0 &&
    GetCurrentBidVolume(i) > 0 &&
    GetCurrentAskVolume(i) > 0)
    if(Ask/Bid < ( 1.0+maxSpreadTrade)) okToTradeInst[i]=true;
    else okToTradeInst[i]=false;
    else okToTradeInst[i]=false;
    Print(now+" bar "+i+" ask="+Ask+" bid="+Bid+" ok is "+okToTradeInst[i]);
    }

    #2
    curmudgeon,

    What instruments are you using here along with their expiries?

    Using this example, we are getting different prices.
    Attached Files
    Last edited by NinjaTrader_AdamP; 07-09-2012, 07:53 AM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hello, I'm not sure if it matters, but this is running as a strategy and not as an indicator.

      Bar0 is $AUDUSD
      Bar1 is M6A 12-12 <== there should be no quote on this guy right now according to the market analyzer
      Bar2 is M6A 09-12

      It's connecting to Interactive Brokers. It's intended to help me deal with roll dates better (and since we're far from the next roll date the logic is to do this check and then not look at the far instrument).

      Thanks

      Comment


        #4
        Curmudgeon,

        This may have something to do with the non-liquid nature. Here is an output I got from Kinetick using M6A using that reference sample I sent you :

        Instruments length : 3
        M6A 09-12 BID : 1.0142
        M6A 12-12 BID : 1.0143
        Instruments length : 3
        M6A 09-12 BID : 1.0142
        M6A 12-12 BID : 1.0143
        Instruments length : 3
        M6A 09-12 BID : 1.0142
        M6A 12-12 BID : 1.0143

        This was after about a minute. Please try running my test script again and let me know if it works on your end, or if you notice the same behavior.
        Attached Files
        Last edited by NinjaTrader_AdamP; 07-09-2012, 02:31 PM.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          hi, Adam

          yes, that's consistent with my run. if you look at the liquid big futures (6A) then the Dec is almost a cent less than the Sep one , which makes the AUD futures contract a good test case. It shows you're actually getting the mini September contract quotes when you query the mini December one

          I would have thought the checking of the bid and ask volumes would have also warned me that there's effectively no quote, but that seems to give me the ones for the more liquid contract...

          Is there another trick to use ? I want to be trading out of the near one into the far one when certain conditions are met with regards to the bid and ask, but it would only make sense if I have the right bids and asks !

          Comment


            #6
            Curmudgeon,

            I am not sure if I understand. Right now I was using BID prices only. Are you saying because the bid price is close it shows we are getting the September quotes when we query December or is it because its 1 greater than the September query?

            Here is some more output after I waited a bit longer :

            Instruments length : 3
            M6A 09-12 BID : 1.0141
            M6A 12-12 BID : 1.0144
            Instruments length : 3
            M6A 09-12 BID : 1.0141
            M6A 12-12 BID : 1.0144
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              I think the fact that the Sep and Dec quotes are close are strongly indicative that you are getting the September quotes. I think you should be getting no quote whatsoever for the December contract at this time on the mini (M6A) contract.

              If you got right quotes for M6A it should be quite close to the big (6A) contract, i.e. with a gap between Sep and Dec. 6A is equivalent to ten M6A but is much more liquid.

              Recent bids: 1.0142 for the 6A Sep , 1.0141 for the M6A Sep, 1.0064 for 6A Dec - whether I use the script or look at it in the Market Analyzer.

              The problem comes from the M6A Dec which shows no current quote on the Market Analyzer but shows the Sep M6A quote in the script [I know it's not $AUDUSD because that one is above 1.02 at the same time]

              I'm using this futures contract as a test case because it's badly behaved and want to make sure my script is robust.
              Last edited by curmudgeon; 07-09-2012, 03:16 PM.

              Comment


                #8
                Curmudgeon,

                If I do this :

                if(BarsInProgress == 0)
                {
                Print ("Instruments length : "+Instruments.Length);
                Print ( "M6A 09-12 BID : " + GetCurrentBid(1));
                Print ( "M6A 12-12 BID : " + GetCurrentBid(2));
                }

                Its guaranteed to only call GetCurrentBid(1) and GetCurrentBid(2) at the exact same time.

                Here is the output from doing so with the DebugIndicator I attached earlier.

                Instruments length : 3
                M6A 09-12 BID : 1.0142
                M6A 12-12 BID : 1.0143

                So one instrument is 1 tick higher on its bid than the other, and since they were called at the exact same time they must be different prices. I am also not getting a quote on the MarketAnalyzer for M6A 12-12.

                GetCurrentBid() will return the last reported Bid for the instrument you are requesting it for. There is no crossover between bid/ask/last with two separate instruments.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  hi Adam,

                  I think I understand now

                  GetCurrentBid(1) will get the most recent bid that hit the exchange on that instrument, irrespective of whether that was recent or whether that bid is no longer effective and not replaced by a new bid price. Is that correct ?

                  Is there a command that would either show me only the bid that is on exchange right now and return 0 or something when there isn't one ? Or can I filter using another field to ensure that the quote was still live (barring system delay)

                  Thank you
                  Last edited by curmudgeon; 07-10-2012, 01:53 PM.

                  Comment


                    #10
                    Hello,

                    Yes, you are correct. This was how it was explained to me by our Tech lead.

                    I am not aware of any such function unfortunately. You could maybe add a Bid/Ask tick dataseries in a multi-series indicator and compare. if your data provider supports it.

                    You could also use OnMarketData() to get Level1 pricing information, and if the Bid/Ask didn't occur in the last X time frame then you could have your code set to 0.

                    Adam P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by sjsj2732, Yesterday, 04:31 AM
                    0 responses
                    33 views
                    0 likes
                    Last Post sjsj2732  
                    Started by NullPointStrategies, 03-13-2026, 05:17 AM
                    0 responses
                    286 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    285 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    133 views
                    1 like
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    91 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Working...
                    X