Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question with GetCurrentBid()

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

    Question with GetCurrentBid()

    GetCurrentBid() gives me the current bid price...

    how would i get the previous bid price?

    #2
    BigDog008,

    You will have to store it yourself.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      could you suggest how to approach soemthing like that?

      Comment


        #4
        Just create a variable and store GetCurrentBid() into it. As GetCurrentBid() changes, don't change the variable along with it. Then you have your previous bid.

        Not sure why this would be useful though since bid will keep moving around and you will keep needing to update this "previous" bid variable as well.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          essentially I want to be able to start working bids if say...

          Bid[0]>Bid[1]

          working offers if say
          Ask[1]<Ask[0]

          for very small profit targets...

          Comment


            #6
            Then store the value in a variable.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh,

              Would a good approach be constantly append the CurrentBid to a text file and then read from the file?

              I'm able to write the CurrentBid to a text file, but rather than appending to the file, it's constantly overwriting the value.... how would I get around this?

              Comment


                #8
                BigDog008,

                You would not be able to read from a file fast enough. Just store it in a variable. I suggest you work with OnMarketData() instead of GetCurrentBid().



                When receive a new last event you know there was a new tick. You want to keep rolling your variable to store the value and shift it over one each time you receive a new event.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  how do we store the value of the variable in order that one previous tick gets stored? problem i am having is that the variable keeps getting changed as well. ie;

                  double lastBid = e.Price;

                  everytime e.Price changes, so does my variable.

                  Do i need to setup an array or is there a more efficient method?
                  Then as you said we would need to roll it over.
                  Should we use some count feature of 0 and 1?
                  how can we implement this?

                  thanks.

                  Comment


                    #10
                    There are many ways you can do this. Use an if statement to only change the variable if it is different to the current value, then it will always contain the previous different value. You could also use a two element array, or more if you want to store more. Or use a two element queue. etc.

                    Comment


                      #11
                      thanks for the reply, however i am having the same problem as BigDog was having which i dont think was resolved; thats the new value keeps overwriting the previous one.

                      not sure how to store the variable before it gets changed on the update.

                      Comment


                        #12
                        Something like this. I haven't checked it but you should be able to fairly easily.


                        double storeBid = -1;
                        double lastBid = -1;

                        protected override void OnMarketData(MarketDataEventArgs e)
                        {
                        if (e.MarketDataType == MarketDataType.Bid) {
                        if (storeBid != e.price) {

                        lastBid = storeBid;

                        }


                        storeBid = e.price;

                        }

                        Comment


                          #13
                          Thats it! this got it working, thanks.
                          variables needed to be put outside the method
                          cheers

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          633 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          364 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          105 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          567 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          568 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X