[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 365

 
nadya:
Tell me more about it, do you have the code ready? What extension is it in?

Yes, it's ready! I don't know about the extension, how can I find out?!
 
Chekh:

Yes, I'm ready! I don't know about the extension!

MQL4 Code Base
 
Chekh:

Yes, I'm ready! I don't know about the extension!

See all the links in the second post of this page, especially the section

"TERMINAL "
How do I install an EA in MetaTrader 4?

...

 
Roman.:


Define the concept according to you "... which is closest to the buy and sell price simultaneously..." - how do you mean simultaneous?

replace this penultimate line with return(t); with this


no help,

to choose the order closest to the buy and sell price, maybe it is not quite correct at the same time, but this function chooses either buy or sell, depending on which is closest

 
forexnew:

Good afternoon!

A question has arisen: the Expert Advisor has been configured to trade on several dozens of currency pairs (in a single pair window). If any of the pairs is not displayed in the Market Watch window, it causes a glitch. How can I programmatically check if these currency pairs are available to trade, or maybe they are just not displayed in the Market Watch?


There will be different errors

ERR_HISTORY_WILL_UPDATED4066Requested history data in update state

ERR_UNKNOWN_SYMBOL4106Unknown symbol
 
vilard:


did not help,

to select the order closest to the buy and sell price, maybe it is not quite correct at the same time, but this function selects either buy or sell, depending on which is closest

What this function returns with this line at the end

return(OrderType());
 
vilard:


did not work,

to select the closest buy and sell order to the price, maybe it is not quite correct at the same time, but this function selects either buy or sell, depending on which is closest


Try it like this

...
t=OrderType();
 }
 }
 }
 }
 }
 }
 return(t);
 }
 
vilard:

how to select a position closest to the Buy and Sell price at the same time?

//+----------------------------------------------------------------------------+
//| Возвращает тикет ближайшей к рынку позиции по цене открытия или 0 |
//| Параметры: |
//| sym - наименование инструмента ("" - текущий символ) |
//| op - операция (-1 - любая позиция) |
//| mn - MagicNumber (-1 - любой магик) |
//+----------------------------------------------------------------------------+
int TicketNearPosOnOpen(string sym="", int op=-1, int mn=-1) {
double di=10000, pp;
int i, k=OrdersTotal(), t=0;

if (sym=="") sym=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sym && (op<0 || OrderType()==op)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (mn<0 || OrderMagicNumber()==mn) {
if (OrderType()==OP_BUY) pp=MarketInfo(sym, MODE_BID);
if (OrderType()==OP_SELL) pp=MarketInfo(sym, MODE_ASK);
if (di>MathAbs(OrderOpenPrice()-pp)) {
di=MathAbs(OrderOpenPrice()-pp);
t=OrderTicket();
}
}
}
}
}
}
return(t);
}

I can't change the order, it only selects the one, which was last triggered, but it doesn't select sell (or buy) position. Please help me to complete this function
It's not clear what exactly you need. To select the closest open position to the current price (either Buy or Sell)?

Or to select two positions (both Buy and Sell), which are close to the current price?

When you tell us what you need, we will help you :)

 
vilard:

How do I select the position closest to the buy and sell price at the same time?

Maybe this will work for you.

DistMarketAndPos - Returns distance in pips between market and nearest position