Questions from Beginners MQL5 MT5 MetaTrader 5 - page 926

 
Seric29:
What operator can be used from which 2 results can be returned? I use the if statement to find this condition, but it cannot return multiple results in which case I have to write the same condition 2 times, which is why I am writing with this question.

It's not quite clear what conditions are checked, but maybe switch will work for you. And at TRUE assign the values you need.

 
Is there a function for swapping values of two variables ?
 
pivomoe:
Is there a function for swapping values of two variables ?

Forum on trading, automated trading systems and trading strategies testing

Features of mql5 language, subtleties and tricks

fxsaber, 2018.08.26 19:02

The English part of the forum showed
// Обмен значениями между двумя числовыми переменными
#define  SWAP(A, B) { A += B; B = A - B; A -= B; }

 
Artyom Trishkin:

Thank you. I'll have to get to grips with these definitions.

 
Hello! Why does the Bars() function have different values when called from the indicator and expert and HOW TO MAKE THE MATCH?
 
Tango_X:
Hello! Why does the Bars() function have different values when called from the indicator and the Expert Advisor and HOW TO MAKE THE MATCH?

Show code from EA and indicator.

 
Alexey Viktorov:

Show code from EA and indicator.

Just call the function Bars(_Symbol,_Period)

 
Tango_X:

Just call the function Bars(_Symbol,_Period)

Do I have to ask for a printout of the result separately?

I don't get a difference. Although in the tester this variant is not excluded due to availability of history about which I know little, only vague recollections of what I read some time ago. After all, it turns out the total number of available bars. But if you ask from time to time, there can't be any difference.

 
Alexey Viktorov:
The if statement does not return any value.

There are two options for assigning values to certain variables in a separate function:

1. Variables must be visible in all parts of the program. That is, they must be declared at the global variable level (at the beginning of the code).

2. To pass variables declared locally to the user function by reference. That is, put & before the variable name

It means that if a condition is true, two identical actions must be performed, e.g.

        if
        (Bar_Op[qt+2]>=Bar_Lo[qt+1]&&Bar_Cl[qt+2]<=Bar_Hi[qt+1]&& 
        Bar_Cl[qt+2]>=Bar_Lo[qt+1]&&Bar_Op[qt+2]<=Bar_Hi[qt+1]&&
        Bar_Op[qt+3]>=Bar_Lo[qt+1]&&Bar_Cl[qt+3]<=Bar_Hi[qt+1]&&
        Bar_Cl[qt+3]>=Bar_Lo[qt+1]&&Bar_Op[qt+3]<=Bar_Hi[qt+1]&&
        Bar_Op[qt+4]>=Bar_Lo[qt+1]&&Bar_Cl[qt+4]<=Bar_Hi[qt+1]&&
        Bar_Cl[qt+4]>=Bar_Lo[qt+1]&&Bar_Op[qt+4]<=Bar_Hi[qt+1])
         {
          int iHgCL=iHighest(_Symbol,PERIOD_D1,MODE_CLOSE,4,qt+1); int iHgOP=iHighest(_Symbol,PERIOD_D1,MODE_OPEN,4,qt+1);
         Price_UrNij = Bar_Cl[iHgCL]>Bar_Op[iHgOP] ? Bar_Cl[iHgCL]:Bar_Op[iHgOP];//провести нижний уровень
         int iLwCL=iLowest(_Symbol,PERIOD_D1,MODE_CLOSE,3,qt+1); int iLwOP=iLowest(_Symbol,PERIOD_D1,MODE_OPEN,3,qt+1);
         Price_UrVerh = Bar_Cl[iLwCL]<Bar_Op[iLwOP] ? Bar_Cl[iLwCL]:Bar_Op[iLwOP];//провести верхний уровень я перепутал записи местами и условие перевёрнуто задом на перёд но для примера вопроса пойдёт

         string Line_TR="Ln_TRUr"+DoubleToString(qt,0);
         vs_Line_TR( Line_TR, iTime(_Symbol,PERIOD_D1,qt+2),  Price_UrNij, iTime(_Symbol,PERIOD_D1,qt), Price_UrNij, clrGreen, DRAW_LINE, 2, false, false);
}

Variables I have declared and nothing is done except this actionPrice_UrNij = Bar_Cl[iHgCL]>Bar_Op[iHgOP] ? Bar_Cl[iHgCL]:Bar_Op[iHgOP]; or this actionPrice_UrVerh = Bar_Cl[iLwCL]<Bar_Op[iLwOP] ? Bar_Cl[iLwCL]:Bar_Op[iLwOP]; how to make it perform 2 identical actions with both top and bottom levels by condition. Can someone tell me how to write it shorter?

 
Konstantin Nikitin:

It's not quite clear what conditions are checked, but maybe switch will work for you. And at TRUE assign the values you want.

 if
        (Bar_Op[qt+2]>=Bar_Lo[qt+1]&&Bar_Cl[qt+2]<=Bar_Hi[qt+1]&& 
        Bar_Cl[qt+2]>=Bar_Lo[qt+1]&&Bar_Op[qt+2]<=Bar_Hi[qt+1]&&
        Bar_Op[qt+3]>=Bar_Lo[qt+1]&&Bar_Cl[qt+3]<=Bar_Hi[qt+1]&&
        Bar_Cl[qt+3]>=Bar_Lo[qt+1]&&Bar_Op[qt+3]<=Bar_Hi[qt+1]&&
        Bar_Op[qt+4]>=Bar_Lo[qt+1]&&Bar_Cl[qt+4]<=Bar_Hi[qt+1]&&
        Bar_Cl[qt+4]>=Bar_Lo[qt+1]&&Bar_Op[qt+4]<=Bar_Hi[qt+1])
         {
          int iHgCL=iHighest(_Symbol,PERIOD_D1,MODE_CLOSE,4,qt+1); int iHgOP=iHighest(_Symbol,PERIOD_D1,MODE_OPEN,4,qt+1);
         Price_UrNij = Bar_Cl[iHgCL]>Bar_Op[iHgOP] ? Bar_Cl[iHgCL]:Bar_Op[iHgOP];//провести нижний уровень
         int iLwCL=iLowest(_Symbol,PERIOD_D1,MODE_CLOSE,3,qt+1); int iLwOP=iLowest(_Symbol,PERIOD_D1,MODE_OPEN,3,qt+1);
         Price_UrVerh = Bar_Cl[iLwCL]<Bar_Op[iLwOP] ? Bar_Cl[iLwCL]:Bar_Op[iLwOP];//провести верхний уровень я перепутал записи местами и условие перевёрнуто задом на перёд но для примера вопроса пойдёт

         string Line_TR="Ln_TRUr"+DoubleToString(qt,0);
         vs_Line_TR( Line_TR, iTime(_Symbol,PERIOD_D1,qt+2),  Price_UrNij, iTime(_Symbol,PERIOD_D1,qt), Price_UrNij, clrGreen, DRAW_LINE, 2, false, false);

You need to executePrice_UrNij = Bar_Cl[iHgCL]>Bar_Op[iHgOP] ? Bar_Cl[iHgCL]:Bar_Op[iHgOP]; andPrice_UrVerh = Bar_Cl[iLwCL]<Bar_Op[iLwOP] ? Bar_Cl[iLwCL]:Bar_Op[iLwOP];.

Reason: