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

Back to topics list To post a new topic, please log in or register
avatar
56
Dannoo007 2016.01.11 17:22
 

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


 


avatar
Moderator
3413
GumRai 2016.01.11 18:28 #
 
Global Variables of the client terminal can be set anywhere in the code
avatar
12995
WHRoeder 2016.01.11 22:21 #
 
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
avatar
56
Dannoo007 2016.01.13 14:43 #
 
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.


Back to topics list  

To add comments, please log in or register