Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 891

 
abeiks:
Good afternoon! Always after disabling and enabling "Allow EA to trade" a position opens that should not open. I assume that this is because the variables are not reset. How can I reset all variables after enabling or disabling "Allow EA to trade", as they are after restarting the MT4 platform?
Just reset those variables at the moment when this checkbox is unchecked and do not touch them until a user activates it again. Watch for MQLInfoInteger(MQL_TRADE_ALLOWED).
 
evillive:
You just need to reset those variables at the moment when this very checkbox is unchecked and not to touch them again until a user activates it again. Watch for MQLInfoInteger(MQL_TRADE_ALLOWED).
Thank you!
 
evillive:
You just need to reset those variables at the moment when this very checkbox is unchecked and not to touch them again until a user activates it again. Watch for MQLInfoInteger(MQL_TRADE_ALLOWED).
Is there a way to ensure that after IsTradeAllowed()==false the expert is removed and reloaded ( expert: removed ; expert: load successfully)?
 
evillive:

This is the same branching as if(), it just looks neater and is easier to code if there are three or more single choices of integers to choose from. If there are only two variants, or non-integer expressions are compared, then only if(). Also, with if() you can combine several options (if( option1 && option2 || option3 ) {action;}), while switch cannot do it directly, only one at a time.

switch
if()
switch (x)
{
case 1: action on option 1; break;
case 2: action on option 2; break;
case 3: action on option 3; break;
default: default action; break;
}
if( option1 ) { action in option 1; }
else if( option2 ) { actions by option 2; }
else if( option3 ) { actions by option 3; }
else { default action; }

Thank you! I didn't see such a comparison in the tutorial, although maybe I'm just reading out of order.

Anyway, this is exactly what a beginner expects from a professional - to disclose subtleties that you won't find either in a textbook or in a reference.

 
Again with the question: is there an attachment restriction (see SRC) in the if-else loop?
if()
   {if()
      {}
      else
      {}
    }
    else
    {
    if()
      {}
      else ...и т.д....
     }             
I can't find any reason why such primitive code doesn't work.
 
rapid_minus:
Again with the question: is there an attachment restriction (see SRC) in the if-else loop? I can't find a reason why such primitive code doesn't work.
What exactly doesn't work?
 
evillive:
What exactly is wrong?


Everything :( When testing, the position opens immediately according to criteria not specified in the code, and does not close it until the end of testing, i.e. it ignores all the conditions for closing, prescribed in the code.

It is not clear whether closing conditions are specified incorrectly orthe position opened is not readable.

 
rapid_minus:


Everything :( During testing, the position is opened immediately, according to criteria not specified in the code, and does not close it until the end of testing, i.e. it ignores all the conditions for closing prescribed in the code.

It is not clear whether closing conditions are defined incorrectly or the open position is not readable.

In such cases, when it is not clear where the problem is, it is recommended to insert after each action a print with description of the action (and error output, if necessary).
 
evillive:
In such cases, where it is not clear where the problem is, it is recommended that after each action a print describing the action (and the error output if necessary) is inserted.

Thank you. It's a lot of work, but it looks like I won't be able to find the error otherwise.
 
tatianati:

Hello.

Can you tell me how to find out the distance in pips from the current price to the maximum price of the last 10 bars?

I know the distance to the high of the 10th bar:


Idon't knowhow to find the maximum high of 10 bars and remember it.

Please help me.

Look at CopyHigh and ArrayMaximum, it will be a bar with a maximum.

Just pay attention to the direction of array indexing in CopyHigh function

Reason: