[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 485

 
FOReignEXchange:


I don't get it? I'm just looking in the help, there OrderSelect() uses a condition. And I haven't seen it anywhere without true.

if is a condition statement. And there should be a condition in brackets. That seems more logical to me. Although there may be no difference.


specification:

bool OrderSelect( int index, int select, int pool=MODE_TRADES) 

returns true or false

see https://docs.mql4.com/ru/basis/operators/if.

If the expression is true, operator1 is executed, and control is given to the operator following operator2 (i.e. operator2 is not executed). If the expression is false, operator2 is executed.

if (expression) operator1 else operator2

The else part of the if operator can be omitted. Therefore, nested if statements with the else part omitted may cause ambiguity. In this case else is linked to the nearest preceding if operator in the same block that has no else part.

i.e. comparing OrderSelect()==true is not necessary - just use OrderSelect() or !OrderSelect() instead of OrderSelect()==false

 

That's not what I mean.

It's just that when I select an order, I always write it in full.

if(OrderSelect(count,SELECT_BY_POS,MODE_TRADES)==true)

I've never seen it without true.

abolk:
то есть сравнение OrderSelect()==true делать не обязательно - достаточно просто использовать OrderSelect() или !OrderSelect() вместо OrderSelect()==false

I got it.

 
FOReignEXchange:

I've never seen one without true.


You are looking at the wrong people's codes.
 
FOReignEXchange:

That's not what I mean.

It's just that when I select an order, I always write it in full.

I've never seen it without true.

I got it.


two perfectly equal entries - one entry is no worse or better than the other - everyone does as they please, as they understand, as they are used to
 
sergeev:

You're looking at the wrong people's codes.


By the way, I have to hand it to FOReignEXchange.

I opened "Moving Average.mq4" and saw it:

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
 
abolk:


Print() to output the value of variable global_trailing_SP directly in the function you have defined.

Where do you read the value of this variable?


Wow! )) If I print() the value ofglobal_trailing_SP variable from the presented function, I see a completely unexpected value in the log (highlighted in yellow). While before outside this function it's printed correctly (opposite the red dot).

global_trailing_SP is a global variable. It is declared outside the Start() function,

double global_trailing_SP = 0.0; 

After the trailing stop function successfully changes the value of the main position, the value of stop loss of the main position is assigned in a separate loop toglobal_trailing_SP variable.

   for(count = OrdersTotal()-1; count >= 0; count--)
      {  OrderSelect(count,SELECT_BY_POS,MODE_TRADES);
         if(OrderType() == OP_SELL && OrderMagicNumber() == Magic_Source_SP)
            {  global_trailing_SP = NormalizeDouble(OrderStopLoss(),dgt); Print("global_trailing_SP: ",DoubleToStr(global_trailing_SP,5));  }
      }
This is the value indicated by the red dot above.

This value is then passed to the function where various order modifications take place. But as a result, the log displays a value I didn't expect and the value of Stop Loss is certainly not modified. How can this problem be solved? It turns out that not everything is always as logical as it may seem at first sight)))

 

Isn't it better to do this here where the SELLSTOP is?

if((global_trailing_SP < Stp_Loss && global_trailing_SP > High_1)) 
{  OrderModify(OrderTicket(),OrderOpenPrice(),global_trailing_SP,0,0,DeepPink);
Print("Условие ModifyOrder исполнилось: global_trailing_SP: ",global_trailing_SP,", Stop Loss: ",OrderStopLoss());  }
else   Print("Условие не выполняется!");

So that everything is exactly the same as in SELL.

 
FOReignEXchange:

Isn't it better to do this here, where the SELLSTOP is?

So that everything is exactly the same as in SELL.


That seems not to be the problem in this case. Read more above.
 
tol64:


Wow! )) If I print() the value of global_trailing_SP variable from the presented function, I see an absolutely unexpected value in the journal (highlighted in yellow). While before outside this function it's printed correctly (opposite the red dot).

global_trailing_SP is a global variable. It is declared outside of the Start() function,

After the trailing stop function successfully changes the value of the main position, in a separate loop global_trailing_SP variable is assigned with the value of stop loss of the main position.

This is the value indicated by the red dot above.

This value is then passed to the function where various order modifications take place. But as a result, the log displays a value I didn't expect while the value of Stop Loss is certainly not modified. How can this problem be solved? It turns out that not everything is always as logical as it may seem at first sight)))


show how you read the global_trailing_SP variable
 

So I don't get it. Does the pending order exist at the time of modification of the main order?

If it exists, then the modification of the main order and modification of the pending order are in the same block. And if the main order is modified, the pending one should do the same, if that is your idea.

Another thing is that our idea does not work. That means a mistake in the condition. Try to do everything in the same way as in the condition for modification of the main order, as I have shown above. It seems to me that the error is in the logic. I am not surprised. Everything is very complicated. You should make it simpler.

Reason: