Please edit your post . . .
hello, try to know the price of the last active order. For example if I have three buy orders active, only know the price of the first buy order entered, not the last, the function I use is:
.....
How can I to know the openprice for the last buy order active, if I have 3 or 4 orders buy?
Compare for all open BUY trades the OrderOpenTime() and take for the last opened trade the OrderOpenPrice()
Pulled this out of the code base - well from answering someone elses question
int num=0; int ot=0; for (int j=OrdersTotal()-1;j>=0;j--) { if (OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()<3 && ((OrderMagicNumber()==Magic) || Magic==0)) { if(OrderOpenTime()>ot) { num=OrderTicket() ot=OrderOpenTime(); } } }
Pulled this out of the code base - well from answering someone elses question
OrderType()<3So that means 0,1 or 2 As yoy can see We're not interested in the OP_SELL and the OP_BUYLIMIT trades
Constant | Value | Description |
---|---|---|
OP_BUY | 0 | Buying position. |
OP_SELL | 1 | Selling position. |
OP_BUYLIMIT | 2 | Buy limit pending position. |
OP_SELLLIMIT | 3 | Sell limit pending position. |
OP_BUYSTOP | 4 | Buy stop pending position. |
OP_SELLSTOP | 5 | Sell stop pending position. |
It was not asked but if you want to do it for a certain Symbol() you can also select the Symbol()
And also good if you select the MagicNumber() if you want select the trades with a specific OrderMagicNumber(s)
Only forgetting to the OrderOpenPrice()
int num=0; int ot=0; double OpeningPrice; for (int j=OrdersTotal()-1;j>=0;j--) { if (OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()==0 && OrderMagicNumber()==Magic) { if(OrderOpenTime()>ot) { num=OrderTicket(); //don't forget ";" ot=OrderOpenTime(); OpeningPrice=OrderOpenPrice(); } } }Think this might do it if you also want to select Opentrades for Symbol() of Chart and specific MagicNumber
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello, try to know the price of the last active order. For example if I have three buy orders active, only know the price of the first buy order entered, not the last, the function I use is:
double retorno_precio_apertura(int NMagb)
{
double resultprecioultimaorden;
RefreshRates();
if( OrdersTotal()==0 ) return;
for ( int i=0; i<OrdersTotal(); i++)
{OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
double InfASK=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
double InfBID=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
double InfPoint=MarketInfo(Symbol(),MODE_POINT);
double infStopLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL)*InfPoint;
int Slippage=((InfASK-InfBID)/InfPoint)+1;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==NMagb && OrderType()==OP_BUY)
{
resultprecioultimaorden=OrderOpenPrice();
}
return(resultprecioultimaorden);
How can I to know the openprice for the last buy order active, if I have 3 or 4 orders buy?