how would i get the previous bid price?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Question with GetCurrentBid()
Collapse
X
-
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
-
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
-
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
-
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
-
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
-
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
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment