# help me please, how to save a value ?

630

int OnTick ()

{

if (Bid > Close [+1])

{ (Bid value saved forverer) } // How can i save Bid value that specific time?

Thanks
15900

1. Close[-1] is the future, it doesn't exist.
2. Close[0] is equal to Bid always.
3. Just save it (static or global.)
int OnTick(){
static double Bid_value_saved_forverer;
if (Bid > Close[1]){ Bid_value_saved_forverer = Bid; }
630

so just put a "static" before defining double? Thanks a lot
630

Just 1 more question, if i put another If condition, the Static value will update if last condition is checked?

Moderator
5484

No.

Static values are static.

Moderator
10652

mrluck1:

Just 1 more question, if i put another If condition, the Static value will update if last condition is checked?

If you give the static variable a new value, then it will retain that value until you assign a new value to it.
630

I still don't undertstand, mql4 book doesn't explain about this, and i really need to know this, for example:

int OnTick()

static double Bid_value_saved_forverer;

{

if (Bid > Close[1])

{ Bid_value_saved_forverer = Bid; } // happen...

if (Bid > Close[1])
{ Bid_value_saved_forverer = Bid;} // happen too

}

If the first condition happen, then next happen too, the static will save only the first one, or the last?

Thanks

Moderator
2325

mrluck1:

I still don't undertstand, mql4 book doesn't explain about this, and i really need to know this, for example:

int OnTick()

static double Bid_value_saved_forverer;

{

if (Bid > Close[1])

{ Bid_value_saved_forverer = Bid; } // happen...

if (Bid > Close[1])
{ Bid_value_saved_forverer = Bid;} // happen too

}

If the first condition happen, then next happen too, the static will save only the first one, or the last?

Thanks

The last one.
630

honest_knave:
The last one.
Thanks a lot
Moderator
2325

mrluck1:
Thanks a lot

const can only be set once.

If you want to remember it between calls, you can try static const

Or look into Global Variables of the Terminal - https://docs.mql4.com/globals

Global Variables of the Terminal - MQL4 Reference
• docs.mql4.com
Global Variables of the Terminal - MQL4 Reference
15900

 mrluck1: I still don't undertstand, mql4 book doesn't explain about this, and i really need to know this, I gave you links (#1.) Did you bother to read them?