How to get the nearest Bid price (to the current Bid price) ?

 

We use "Bid" to get the current bid price of every quote

So, How to get the previous bid price ?

Thanks for your guide !

 
You store it in a variable and it's there when you need it.
 

Hi RaptorUK, thanks for your attention, but you mistook my idea,


if you assign "x=Bid;"

The variable x just stores the value of the newest Bid price.

How to get the value of the previous Bid price (the bid price just beside the current quote)

Example:

If at 00:00:00 there is a price quote, with Bid=1645.25

and then, 2 seconds later, at 00:00:02, a new quote comes, with Bid=1645.31

I want a function as this: if called at 00:00:02 it returns 1645.25, instead of 1645.31

I hope you get my idea, and can help me.

 

I want a function as this: if called at 00:00:02 it returns 1645.25, instead of 1645.31

There is no such a built-in function, I think Raptor's variable is the best you can do, like this:

double PrevBid; // a globally defined variable keeps it's value between ticks

int init() {
    PrevBid = 0.0;
    // ...
    return(0);
}

int start() {
    if (PrevBid == 0.0) {
        PrevBid = Bid;
        return(0);
    }
    
    // here you can use Bid and PrevBid
    // ...
    
    PrevBid = Bid;
    return(0);
}
 
Or use a static
int start() {
    static double PrevBid; if (PrevBid == 0.0) { PrevBid = Bid; return(0); }
    
    // here you can use Bid and PrevBid
    // ...
    
    PrevBid = Bid; // Update for next tick.
    return(0);
}
 

I agree with Raptor's idea as explained and expounded upon by erzo and WHRoeder.

I might also suggest that you could use an array to store several (your choice on the size of "several") past bid prices.

 
WHRoeder:
Or use a static
Be careful with static (I never use them), because it will not be reinited after user changes extern variables, timeframe or symbol. I had several bugs because of this. For example, here the static PrevBid will keep it's value from ticks before, because ticks are stopped while user sets the externs. (Or worst case PrevBid stores a value from another symbol).
 

Thanks to all,

I do know how !

Reason: