Download MetaTrader 5

help me please, how to save a value ?

To add comments, please log in or register
mrluck1
630
mrluck1  
int OnTick ()

{

if (Bid > Close [+1])

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

Thanks 
whroeder1
15900
whroeder1  
  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; }
mrluck1
630
mrluck1  
so just put a "static" before defining double? Thanks a lot
mrluck1
630
mrluck1  

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

Marco vd Heijden
Moderator
5484
Marco vd Heijden  

No.

Static values are static.

Keith Watford
Moderator
10652
Keith Watford  
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.
mrluck1
630
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 

honest_knave
Moderator
2325
honest_knave  
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.
mrluck1
630
mrluck1  
honest_knave:
The last one.
Thanks a lot 
honest_knave
Moderator
2325
honest_knave  
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
Global Variables of the Terminal - MQL4 Reference
  • docs.mql4.com
Global Variables of the Terminal - MQL4 Reference
whroeder1
15900
whroeder1  
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?
12
To add comments, please log in or register