Errors, bugs, questions - page 1886

 
Vladimir Karputov:


So what is the question?

Where can you see that under the number "i" there is a position with such-and-such ticket, for such-and-such symbol? In general, apart from the simple output of the sequence number, you also output the ticket and the symbol.


Is it normal that for different situations, one function gives the same value?

ZS: by the way there was a question in the post.

The point is, if I select buy, the function(PositionGetInteger(POSITION_TYPE)) returns 0

And if you select a non-existing position, the function will also return 0

 
Alexandr Bryzgalov:
Is it normal that for different situations one function gives the same value?


What is "different situations"? And do as I recommended above:

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Vladimir Karputov, 2017.05.12 11:15

...

In general, apart from the simple output of the sequence number, you also output the ticket and the symbol.


 
Alexandr Bryzgalov:

I know I need to check, but things can happen...

PositionGetInteger

The function returns the requested property of an open position, previously selected using thePositionGetSymbol orPositionSelect function. The position property should be of datetime, int type. There are 2 variants of the function.

1. Directly returns the value of the property.

longGetInteger(
ENUM_POSITION_PROPERTY_INTEGERproperty_id// property identifier
);

2. Returns true or false depending on success of the function. If successful, the property value is placed in the target variable, which is passed by reference to the last parameter.

boolPositionGetInteger(
ENUM_POSITION_PROPERTY_INTEGERproperty_id,// property identifier
long&long_var//take the value of the property
);

Parameters

property_id

The [in] identifier of the position property. The value can be one of the values of enumENUM_POSITION_PROPERTY_INTEGER.

long_var

[out] Variable of the long type, taking the value of the requested property.

Returned value

Value of typelong. In case of unsuccessful execution returns 0.

The situation with the majic is thinner. Therefore it is logical to do a check (PositionGetInteger(POSITION_TICKET) > 0).
Документация по MQL5: Торговые функции / PositionGetInteger
Документация по MQL5: Торговые функции / PositionGetInteger
  • www.mql5.com
Торговые функции / PositionGetInteger - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
fxsaber:
The situation is more subtle with magic. So it is logical to do a check (PositionGetInteger(POSITION_TICKET) > 0).

Yes, it's good to do a check.

But when you write a function, you always try to make sure that it returns a different value in different situations.

I think it is incorrect that the same value comes out of the function under different situations.
 
Alexandr Bryzgalov:

but when you write a function, you always try to get a different value for different situations.

This is the reason why Magic is mentioned. What to return in case of error PositionGetInteger(POSITION_MAGIC) ?
 
fxsaber:
This is the reason why Magic mentioned it. What to return in case of error PositionGetInteger(POSITION_MAGIC) ?
0 - position opened manually. correct?
 
Alexandr Bryzgalov:

Is it OK if one function gives the same value for different situations?

ZS: there was a question in the post by the way.

the point is, if I select buy, the function(PositionGetInteger(POSITION_TYPE)) returns 0

and if you select a non-existing position, the function will also return 0


So the first call is used when you GUARANTEED a position (like you have in the loop). And here is the second form of call

bool  PositionGetInteger( 
   ENUM_POSITION_PROPERTY_INTEGER  property_id,     // идентификатор свойства 
   long&                           long_var         // сюда примем значение свойства 
   );

for cases where the position is selected out of the blue.


Do that and believe what you get in the "result" variable - everything falls into place:

//+------------------------------------------------------------------+
//|                                                         posi.mq5 |
//|                                                      sanyooooook |
//|                                                 http://sn-bot.ru |
//+------------------------------------------------------------------+
#property copyright "sanyooooook"
#property link      "http://sn-bot.ru"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int tot=PositionsTotal();
   for(int i=0;i<tot;i++)
     {
      ulong OrderTicket_=PositionGetTicket(i);
      long cmd=PositionGetInteger(POSITION_TYPE);
      if(OrderTicket_>0 && cmd<=POSITION_TYPE_SELL)
         Print("N",i,"cmd=",cmd);

     }
   ulong OrderTicket_=PositionGetTicket(100);
   long cmd=-3;
   bool result=PositionGetInteger(POSITION_TYPE,cmd);
   if(result)
      Print("N100 cmd=",cmd);
  }
//+------------------------------------------------------------------+
 
Alexandr Bryzgalov:
0 - the position is opened manually. correct?
Yes. But any other value will also be misleading.
 
Vladimir Karputov:


So the first call is used when you GUARANTEED a position (like you have in the loop). And here is the second form of call

for cases where the position is selected out of the blue.


Do this and believe what you get in the "result" variable - everything falls into place:

that's not the question, it's that the function returns the same value for different situations.

I know how to check it.

the original question was whether it's normal at all?

SZY: an error can be made unintentionally and then in 100000 code you'll get tired of looking for it.

What? You don't have to make mistakes? )

 
Alexandr Bryzgalov:

this is not the question, but the function returns the same value for different situations.

I know how to check it

The question was originally about whether this is normal at all?


You, as I see it, have not checked the code I showed you. How about this: you check it first, then ask the question again.
Reason: