I am new in programming :-) I want to write a program like below I want to know how can I swap between functions
if ( ------ )
else if ( ------- )
if any of the condition happend and it sell or buy, go to function b () and
the fanction a() condition does'nt check again.
I want to know how to swap between functions and how can I stop a function if any of the conditions inside was true.
If you have too many 'if'-s on a single variable the switch operator might be better:
These are the main functions in indicators and experts:
And this is the most precious link of all the MQL5 documentation:
You will need it later.
Function a() may depend on number of open positions, symbols and so called 'magic number' (whether the deals were made by this expert or something else), if 'yes' - skip the check for opening conditions.
There are several ways to do this, you can use flags, to do that.
int condition = 0; // global variable
int start ()
if ( condition==0) // here its a flag
function_a(condition); // when condition 1 becomes=1, this flag will close
void function_a (int &condition2) // here is the function, you pass the condition value by reference
if (Buy happens)
You can even put a whole third function which chooses between a() and b() as 'condition'. A check for open trades, their symbols and magic numbers most likely.
The check for open positions should be independent of previous expert operations so it's secured against power outages, reboots, etc.