any variable in one EA is local to the instance of the Ea. It will not be affected by the same EA on a different chart.
Obviously this excludes terminal global variables.
Hello friends,
Please take a look at this:
If I put my expert on several pairs like EURUSD GBPUSD XAUUSD at the same time:
Does the EA dedicate BuyOrder to just last opened order(and it might be any of these pairs) so when I want select and close last opened buy order of XAUUSD, BuyOrder might be the ticket number of GBPUSD or EURUSD also?
Or the EA has different memory blocks on different charts so I don't have to check the symbol?
I did not know what should I search to review older topics.
Your advice is fully appreciated.
BuyOrder=OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage,0,0,NULL,MagicA,0,clrBlue); <---- Obviously this will open an order an put its ticket number in the integer variable BuyOrder. if(BuyOrder!=-1) <------ Then if the order has been correctly placed (ticket different -1) { Print(" Buy Opened "); <------ print a message in the status tab }
if(OrderSelect(BuyOrder,SELECT_BY_TICKET)==true) <---- This one will try to select the order based on its ticket number (int BuyOrder), it is true if such an order exists if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,clrNONE)==true) <---- if such an order exists, it will try to close it { Print(" Buy Closed "); <---- and if it succeeds closing it, it will print a message in the status tab. }
Keith Watford:
Obviously this excludes terminal global variables.
What do you mean of "terminal global variables" ? You mean variables defined in global scope of the EA? Or "terminal global variables" are different from variables defined in global scope?
I had no teacher and just learned the basics in YouTube. The MQL documentation for this, is not clear to me also, so please clarify it to me if possible.
What do you mean of "terminal global variables" ? You mean variables defined in global scope of the EA? Or "terminal global variables" are different from variables defined in global scope?
I had no teacher and just learned the basics in YouTube. The MQL documentation for this, is not clear to me also, so please clarify it to me if possible.
Yes, Terminal GVs are different to globalscope variables. It has always struck me as strange that they use the same name to describe them.
Global Variables of the Client Terminal
There is a group set of functions for working with global variables.
Global variables of the client terminal should not be mixed up with variables declared in the global scope of the mql4 program.
Global variables are kept in the client terminal for 4 weeks since the last access, then they will be deleted automatically. An access to a global variable is not only setting of a new value, but reading of the global variable value, as well.
Global variables of the client terminal are accessible simultaneously from all mql4 programs launched in the client terminal.
When testing and optimizing the Expert Advisors that use global variables, keep in mind that client terminal and the Strategy Tester share common global variables. Therefore, the names of the global variables must be different from the names of the global variables used by other mql4 programs. Otherwise, it may lead to incorrect work of mql4 programs and inaccurate testing results.
Function | Action |
Checks the existence of a global variable with the specified name | |
Returns time of the last accessing the global variable | |
Deletes a global variable | |
Returns the value of a global variable | |
Returns the name of a global variable by its ordinal number in the list of global variables | |
Sets the new value to a global variable | |
Forcibly saves contents of all global variables to a disk | |
Sets the new value to a global variable, that exists only in the current session of the terminal | |
Sets the new value of the existing global variable by condition | |
Deletes global variables with the specified prefix in their names | |
Returns the total number of global variables |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello friends,
Please take a look at this:
If I put my expert on several pairs like EURUSD GBPUSD XAUUSD at the same time:
Does the EA dedicate BuyOrder to just last opened order(and it might be any of these pairs) so when I want select and close last opened buy order of XAUUSD, BuyOrder might be the ticket number of GBPUSD or EURUSD also?
Or the EA has different memory blocks on different charts so I don't have to check the symbol?
I did not know what should I search to review older topics.
Your advice is fully appreciated.