[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 155

 
todem:
in the definition of a trend?

In a trend change over a period of time... See https://www.mql5.com/ru/forum/131277/page148 and https://www.mql5.com/ru/forum/131277/page149
 

Can you tell me why OrderSelect returns TRUE even if the order with this ticket does not exist (it is deleted)?


   if(OrderSelect(tickethigh1, SELECT_BY_TICKET, MODE_TRADES)==false)
 
100yan:

in a change of trend on a section of time...


Please tell me if Tp and Slossa function works here

if (total > 0) AveragePrice = NormalizeDouble(AveragePrice / Count, Digits);
if (NewOrdersPlaced) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
PriceTarget = AveragePrice + TakeProfit * Point;
BuyTarget = PriceTarget;
Stopper = AveragePrice - Stoploss * Point;
flag = TRUE;
}
}
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_SELL) {
PriceTarget = AveragePrice - TakeProfit * Point;
SellTarget = PriceTarget;
Stopper = AveragePrice + Stoploss * Point;
flag = TRUE;

 
todem:
it compiled fine for me

Sorry, the Indicator works - that's how it was originally, and the error is in the tcht file - it doesn't compile.

Files:
 

Can I use init to make calculations for the indicator buffer?

I wanted to recalculate in init all bars except the zero bar and in start zero bar - it doesn't count...

 
Pyro:

Can you tell me why OrderSelect returns TRUE even if there is no order with such a ticket (it has been deleted)?

Have you read the function reference well?

Let's read it again:

---------------------------------------------------------------------------------------------------------------------------------------------------------------

bool OrderSelect( int index, int select, int pool=MODE_TRADES)
The function selects an order for further manipulation. Returns TRUE if the function completes successfully. Returns FALSE if the function fails. To get information about the error, call the GetLastError() function.
The pool parameter is ignored if the order is selected by the ticket number. The ticket number is a unique identifier for the order. To determine from which list an order is selected, we should analyze its closing time. If the time of closing of the order is 0, then the order is open or pending and is taken from the list of open positions of the terminal. An open position can be distinguished from a pending order by its type. If the time of closing is not equal to 0, then the order is closed or pending and has been selected from the history of the terminal. The distinction between a closed order and a deleted pending order can also be made by order type.
Parameters:
index - Order position or order number depending on the second parameter.
select - The flag of the selection method. Can be one of the following values:
SELECT_BY_POS - the index parameter contains the index number of the position in the list,
SELECT_BY_TICKET - the index parameter contains the ticket number.
pool - Data source for the selection. It is used when theselect parameter is equal to SELECT_BY_POS. It can be one of the following values:
MODE_TRADES (default) - order is selected among open and pending orders,
MODE_HISTORY - the order is selected among closed and deleted orders.


---------------------------------------------------------------------------------------------------------------------------------------------------------------

This one:

The pool parameter is ignored if the order is selected by the ticket number. The ticket number is the unique identifier of the order. To determine from which list an order is selected, its closing time must be analysed. If the time of closing of the order is 0, then the order is open or pending and is taken fromthe list of open positions of the terminal.

You do what?

if(OrderSelect(tickethigh1, SELECT_BY_TICKET, MODE_TRADES)==false)

I have shown in red the parameter pool, which is ignored when choosing by ticket and an order is taken from any list (open or closed) of positions of the terminal. That's why it returns the truth. After all, such a ticket exists and an order is selected, but from the list of closed orders...

We should do it that way:

   if (OrderSelect(tickethigh1,SELECT_BY_TICKET))
   if (OrderOpenTime()==0) {
      // ... код при успешном выборе ордера по тикету в списке рыночных ордеров
   }

... or:

if (OrderSelect(tickethigh1,SELECT_BY_TICKET))
   if (OrderOpenTime()>0) {
      // ... код при успешном выборе ордера по тикету в списке закрытых ордеров
   }

... ...or:

   if (OrderSelect(tickethigh1,SELECT_BY_TICKET)) {
      if (OrderOpenTime()>0) {
         // ... код при успешном выборе ордера по тикету в списке закрытых ордеров
      }
      if (OrderOpenTime()==0) {
         // ... код при успешном выборе ордера по тикету в списке рыночных ордеров
      }
   }

I think I have explained it very well... :)

 

artmedia70


Thank you for such a detailed and comprehensive reply. Really as clear as possible :) THX!!!

 
Pyro:

artmedia70


Thanks for such a detailed reply. Really clear as possible :) THX!!!

:) Thank you. You're welcome.

I would like to warn about some "insidiousness" of selecting open positions by their ticket. The thing is that at the end of a trading day when a position is moved to the next day, the brokerage company re-opens the order. That is, the current position is closed and another position is opened with the same volume, but with a new ticket including the swap. Therefore, your Expert Advisor must keep track of re-opened orders and take into account their new tickers, otherwise everything will "flow" - the order with the old ticker will appear in the list of closed orders, and you will not be able to open an existing position moved to the next trading day using the old ticker. Partially closed positions will meet the same fate - a new ticket will also be assigned to them.

Therefore, keep your own strict record of all EA orders and keep track of all such "insidious" changes in time.

 
artmedia70:


I would like to warn about a certain "insidiousness" of selecting open positions by their ticket. The point is that at the end of the trading day when a position is transferred to the next day, the DC reopens the order.

In some brokerage companies this is done, but the vast majority do not suffer from such a thing.
 
sergeev:
I don't know if this is true for some brokerage companies, but most of them don't do this shit.

Isn't it a "good manners" rule to consider this behaviour of the DC as well? After all ... yeah, never mind... I just try to consider everything, well... or what I am aware of.

Caution is forearmed, eh? ;)