HELP WHO CAN !!!

 

Stuck in a problem

for(int i = 0; i < OrdersTotal(); i++)
  {
    
    if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if(OrderSymbol() != Symbol()) continue;
    if(OrderMagicNumber() != MAGA) continue; 
    if(OrderType() == OP_BUY)DS=1;


The selector finds an order if there is an open position but if there are no open positions, how can I find it ? the selector will still show the last closed position...
 
sllawa3:

Stuck in a problem


The selector finds an order if it is open, but if there are no open positions, how can I find it? The selector will still show the last closed position...
with the flag
MODE_TRADES
the "Selector" will not show closed positions at all, only open ones. If there are zero open positions the loop will not even start because the condition will be false
 
Techno:
with the flag
The "selector" will not show closed positions at all, only open positions. If there are zero open positions the loop will not even start because the condition will be false

i know it won't start and will save the last position already closed... that's what i have written... you can check opened positions using a Select order but how should i check absence of positions?
 
sllawa3:

Exactly, it won't start and will save the last pose already closed... that's what it says...
I don't understand what it says. Even now, what do you mean by "saves a closed position"? If we are talking about calculating positions, as I can only guess, all variables (for storing the number of orders) must be zeroed out at the beginning of the start function. I.e. before the loop. If they remain empty after the loop, it means there are no positions.
 
a piece of code at the beginning of the topic... if there is no position then DS stays =1 until a new order appears... even though the order has closed... just selection and will not start... what's not to understand...
 
Techno:
something is not clearly written. Even now, what does it mean to "keep the position closed"? If we are talking about calculating positions, as I can only guess, then all variables (for storing the number of orders) must be reset to zero at the beginning of the start function. I.e. before the loop. If they remain empty after the loop, it means there are no positions.

DS is initially written as int = 0 before the loop
 
Techno:


so it won't reset if the cycle doesn't start, and it won't start if there are no poses
 
sllawa3:

DS is initially prescribed as int = 0 before the cycle
Ah, well, if it's prescribed and 0 is assigned, then it can't be a problem, otherwise why would it be equal to one? Is it assigned zero in the start function or above?
 
above
 
There may not be a problem, but there is... try it for yourself and see for yourself
 
How about this?
DS=0;
for(int i = 0; i < OrdersTotal(); i++)
  {
    if (DS==0) DS=-1;
    if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if(OrderSymbol() != Symbol()) continue;
    if(OrderMagicNumber() != MAGA) continue; 
    if(OrderType() == OP_BUY)DS=1;
}
if (DS==0) // поз никаких нет
if (DS==-1) // позы есть, но нету БАЙ
if (DS==1) // есть БАЙ