How to return price value after EA restart.

 

I want to do this:

There is a line on the chart, I get price from it. After Ea restart I want this line get back in that price, which it was before restart.

Can I do this without saving the price in the file?

If can't do, so how to save it to file, that doesn't overwrite prices, because this EA will be in more than one file.

Thank you.

 
Eggo:

I want to do this:

There is a line on the chart, I get price from it. After Ea restart I want this line get back in that price, which it was before restart.

Can I do this without saving the price in the file?

If can't do, so how to save it to file, that doesn't overwrite prices, because this EA will be in more than one file.

Thank you.

You could use a GlobalVariable to save the price value.
 
It's what I need, it works, thanks! :)
 

I face to one problem, if I delete this line in deinit() function, after deletion, my global variable gets 0 value.

double test;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
     ObjectCreate("Entry", OBJ_HLINE, 0,0,test );
     ObjectSet("Entry", OBJPROP_COLOR, Green);    // Color          
     ObjectSet("Entry", OBJPROP_RAY,   true);     // Ray 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("Entry");   //If I add this line: when EA restarts, global variable "test" gets value 0.
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  double EntryPrice;
  EntryPrice=ObjectGet("Entry",OBJPROP_PRICE1);             
  string value=DoubleToStr(EntryPrice, Digits);               
  EntryPrice=NormalizeDouble(StrToDouble(value),Digits);
  string pav="Eggo_"+Symbol();
  test=GlobalVariableSet(pav , EntryPrice);
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
Eggo: There is a line on the chart, I get price from it. After Ea restart I want this line get back in that price, which it was before restart.
Can I do this without saving the price in the file?
  1. IF the terminal is properly shutdown and restarted (and options -> Charts -> keep personal settings,) then the line will be there on a restart.
  2. IF the terminal is properly shutdown and restarted, "You could use a GlobalVariable to save the price value." and it will be there on a restart. Sorry RaptorUK.
  3. IF the terminal is NOT properly shutdown, you can't assume the latest value will be there. You must write a file (persistent storage) when anything saved has changed, each time.

Eggo: I face to one problem, if I delete this line in deinit() function, after deletion, my global variable gets 0 value.
  ObjectDelete("Entry");   //If I add this line: when EA restarts, global variable "test" gets value 0.
What global variable "test"?
string pav="Eggo_"+Symbol();
  test=GlobalVariableSet(pav
You have a Global Variable Eggo_EURUSD and a globally declared variable that you never initialize
double test;
int init(){
     ObjectCreate("Entry", OBJ_HLINE, 0,0,test );
 
Eggo:

I face to one problem, if I delete this line in deinit() function, after deletion, my global variable gets 0 value.

Write the GlobalVariable in the deinit() and read it in the init()
Reason: