Setting Global Variables from OnTick() information.. (ref. Recovery planning)

 

Hello Forum,

So I recently started to think about recovery safeguards for this EA, in the event of server crash, power outage, the likes. One hint I found somewhere was to use... Global Variables of the Terminal as more permanent storage for some of items that would need recovery - mainly doubles, int variables..

The immediate problem I encountered just now is that some (all, actually) of the data I want backed-up are actually variables calculated and used within the scope of OnTick(), whereas it seems Global Variables can be set only in the Global scope - unless I am missing something?? 

So, is there any solution to transfer variables defined and calculated within the event functions such as OnTick(), into Global Variables of the Terminal ??


Any idea/alternative solutions, much appreciated!

Many thanks in advance!

Dan

 
Global Variables of the client terminal can be set anywhere in the code
 
Dannoo007: whereas it seems Global Variables can be set only in the Global scope - unless I am missing something??

Yes you are.

  1. There are globally declared variables; you can read and write them anywhere.
    int commonVariable;
    void OnTick(){
       commonVariable = 1;
    }
  2. There are terminal variables. Global Variables of the Client Terminal - MQL4 Documentation
 
WHRoeder:

Yes you are.

  1. There are globally declared variables; you can read and write them anywhere.
  2. There are terminal variables. Global Variables of the Client Terminal - MQL4 Documentation


Many thanks. So far I can set them Global Variables of the Client Terminal as per below, alright. I got a bit confused by info in "Documentation" though, as:

//this (kind of) works :

int CommonVariable = 1;
void OnTick(){
      string name = "CommonVariable"; 
      GlobalVariableSet(name,CommonVariable);
}

//this doesn't (doh! looks odd anyways, but that's how I copy/pasted the idea from "Documentation")

int CommonVariable = 1;
void OnTick(){
      string name = "CommonVariable"; 
      int GlobalVariableSet(name,CommonVariable);  // <<<< int !??
}


Still, how can you control the type of the Global Variable created, what is the correct syntax for above? The one in Documention gives errors upon compilation ("function can be declared only in the global scope"), the one I figured out only creates numbers (what if I want it bool/true/false, or string?) 

Many thanks in advance for support!!

Dan.

Reason: