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

 
Limita:

And of course when we open the next buy, we immediately roll over (StopLoss equals our average price + 50 pips) on all positions .

This is the scoundrel who sometimes does not take the last position. We had 3 positions, but 4 of them opened. I forgot to put StopLoss on the fourth position.

DedZone should be held:

DedZone is in initialization of the Expert Advisor.

StopLevel = (MarketInfo(Symbol(), MODE_STOPLEVEL)*Point);       // текущий уровень стопов
FreezeLevel = (MarketInfo(Symbol(), MODE_FREEZELEVEL)*Point);        // уровень заморозки
DedZone = MathMax(StopLevel,FreezeLevel);              // Зона запрета розмещения ордеров

And when both are equal to zero, what? Alpari uses spread*2 in such a case.

And you haven't answered my question about the logic of those lines.

 
ALXIMIKS:

it's better to do it this way (someone wrote that he had problems with your way of doing it when modifying or deleting orders) :

And why oil and butter ??? (leave something alone).


Thank you!

Seems to agree with the expert :))

 
artmedia70:

And you haven't answered my question about the logic of those lines.


artmedia70:

The entire logic of an EA's behaviour can be divided into logical blocks, which, depending on the conditions, are either executed or not.

For your own purposes, you can see that this block can be a number of strings enclosed in curly braces:

If (condition) {if the condition is true, the block enclosed in those braces is executed}

Otherwise {if the condition above is not true, the block enclosed in those braces is executed}

If there are no curly brackets after the condition, the block executed when the condition is true is a single line immediately after the condition:

If (condition) This line is executed

Otherwise this line is executed.

In my examples If is if and Otherwise is else.

Taken here

 
artmedia70:

And when both are zero, then what? Alpari uses spread*2 in that case.

And you did not answer my question about the logic of those strings.



Thank you for the information regarding Alpari.

As for the Line Logic, ALXIMIKS answered it.

I should add for myself that modification should be done only if all the conditions are true. If at least one of them fails, we go on.

 
Limita:


Thank you for the information regarding Alpari.

Regarding String Logic, ALXIMIKS replied.

I should add that in that case modification should take place only if all conditions are true. If at least one of them fails, we move on.

He showed me for some reason my own words written once to someone.

I wanted to get an answer to my question about logic. All the ifs () in that code block go one after another. It means that if the first condition is true, the second will also be true, if the second is true, the third will be true and so on, but... If the first condition is not true, the second will not be executed, but the third will be checked again.

Maybe that's the way it should be, after all:

bool ProfitManagement() {
   double StopLossBuy = BuyAP+Profit*Point;                             //Вычисляем StopLoss
   double TakeProfitBuy = BuyAP + Profit*Point;                  //Вычисляем цену TakeProfit
   double StopLossSell = SellAP-Profit*Point;
   double TakeProfitSell = SellAP - Profit*Point;
   RefreshRates();
   for(int good = 0; good < OrdersTotal(); good ++) {
      if(OrderSelect (good, SELECT_BY_POS)) {            
         if (OrderMagicNumber()!=MagicNumber)   continue;
         if (OrderSymbol()!=Symbol())           continue;
//-------------------------Order Buy-----------------------------------------------------  
         if (OrderType()==OP_BUY) {                             
            if (BuyAP < Bid) { 
               if (MathAbs(OrderStopLoss() - StopLossBuy) >= Tick) { // Профит не равен нужному
                  if (Bid-StopLossBuy>DedZone) {                     // Уровень достаточно удален от цены
                     if (WaitForTradeContext()) {                    // Свободен ли торговый поток?
                        if (!OrderModify(OrderTicket(), 0, NP(StopLossBuy), 0, 0, Lime)) {
                           Alert (Symbol()," Хрень со стопами! ",   GetLastError());
                           return(false);
                           }
                        }
                     }
                  }
               }
            }
//-------------------------Order Buy-----------------------------------------------------  
         if (OrderType()==OP_SELL) {                             
            // вся та же хрень...
            }
//-------------------------Order Buy-----------------------------------------------------  
         }
      }
   return(true);
}

This is just my guess, as I have absolutely no idea what logic you have in mind and don't know what some of the variables and functions do and contain/return.

 
artmedia70:

1) He showed me for some reason my own words once written to someone.

2) That's what I wanted you to say about the logic. You have all the if () in that block of code going one after another. Which means that if the first condition is true, the second condition will also be true, if the second condition is true, the third condition will also be true, etc., but... If the first condition is not true, the second will not be executed, but the third will be checked again.

1) well that was for everyone, not just you.

2) you once already made this statement, a few days ago, only I forgot to double-check this information on my part at the time.

Now I made a simple script:

int start(){
 if (3>3)
 if (5>3)
 if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAA");}
} 

And it turned out you were wrong: NO ALERT !!!

 
ALXIMIKS:

1) well that was for everyone, not just you.

2) You made that statement once before, a few days ago, but I forgot to double-check the information at the time.

Now I made a simple script:

And it turned out you were wrong: NO ALERT !!!

int start(){
 if (3>3)
 if (5>3)
 if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAA");}
} 

Well, I agree. In this case, I was a bit hasty when I wrote earlier about what and how the nested conditions would be enforced without braces. You are right in this situation. Do you know why?

Try to get else executed in your code.

 
artmedia70:

Well, I agree. In this case, I was a bit hasty when I wrote earlier about what and how the nested conditions would be enforced without braces. You are right in this situation. Do you know why?

Try to get else executed in your code.


int start(){
 int a=0;
 if (3>3)
 if (5>3)
 if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAA"); a=5;}
 else Alert ("a=", a);
}

No Alert from this script. Else refers to the condition " if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAAAAA"); a=5;} "

Acknowledgments :

int start(){
 int a=0;
 if (5>3)
 if (5>3)
 if (3>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAA"); a=5;}
 else Alert ("a=", a);
}

have anAlert: "a=0".

Result - condition fail handling is only possible for the last condition when the curly brackets "{" are not used during the enumeration of a certain series of conditions.

 
ALXIMIKS:

no Alert from this script. Else refers to the condition " if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAAAAA"); a=5;} "

Acknowledgments :

have anAlert: "a=0".

The result is that the non-condition handling is only possible for the last condition, when the curly brackets "{" are not used during the enumeration of a certain series of conditions.


I.e. parentheses are needed to organize logical branches. Without them, the first condition is prime. If it is not true, other conditions will not be executed.

Try to work it out:

 if (a>b)
    if (b>c) 
        Alert(" условие if (a>b && b>c) выполнено ");
if (d>e) 
    if (e>f) 
         Alert(" условие if (d>e && e>f) выполнено");

And after that, figure out what else it refers to:

if (a>b)
    if (b>c) 
        Alert(" условие if (a>b && b>c) выполнено ");
else if (d>e) 
    if (e>f) 
         Alert(" условие if (d>e && e>f) выполнено");
 
int start(){
 int a=0;
 if (5>3)
 if (5>3)
 if (5>3){Alert ("AAAAAAAAAAAAAAAAAAAAAAA"); a=5;}
 else Alert ("a=", a);
 else Alert ("a=", a+1);
 else Alert ("a=", a+2);
}

If the first condition is not met, we have an alert: "a=2"

If the second condition is not met, we have an alert: "a=1"

When the third condition is not met, we have an alert: "a=0".

Yeah, at first it was unexpected at all))

Reason: