how to swap between funcions ?

 

Hello,

I am new in programming :-)  I want to write a program like below I want to know how can I swap between functions


function a()

{

if ( ------ )

buy;

else if ( ------- )

sell;

}

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.


thanksss

 

If you have too many 'if'-s on a single variable the switch operator might be better:

https://www.mql5.com/en/docs/basis/operators

These are the main functions in indicators and experts:

https://www.mql5.com/en/docs/basis/function/events

And this is the most precious link of all the MQL5 documentation:

https://www.mql5.com/en/docs/function_indices

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.

Documentation on MQL5: List of MQL5 Functions
Documentation on MQL5: List of MQL5 Functions
  • www.mql5.com
Reads from the file of the CSV type a string of one of the formats: "YYYY.MM.DD HH:MM:SS", "YYYY.MM.DD" or "HH:MM:SS" - and converts it into a datetime value
 
kypa:

If you have too many 'if'-s on a single variable the switch operator might be better:

https://www.mql5.com/en/docs/basis/operators

These are the main functions in indicators and experts:

https://www.mql5.com/en/docs/basis/function/events

And this is the most precious link of all the MQL5 documentation:

https://www.mql5.com/en/docs/function_indices

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.

Thank you very much I will read them
 

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

}

return (0);

}

void function_a (int &condition2) // here is the function, you pass the condition value by reference

{

if (Buy happens)

condition2=1;

}
 

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.

Reason: