LastOpenPrice(OP_SELL) for open price of last sell.
double LastOpenPrice(int OrderType)
{
double OpenPrice;
for ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)
if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
&& OrderMagicNumber() == magic.number // my magic number // <------- what Magic Number do you use when you place a trade ? it must match ! !
&& OrderSymbol() == Symbol() // and my pair. // magic.number should be a Globally defined variable that has your Magic Numer
&& OrderType() == OrderType )
{
OpenPrice = OrderOpenprice();
break;
}
return (OpenPrice); // <------- this returns the Order Open Price NOT the ticket
}
double LastClosePrice()
{
double ClosePrice;
for ( int pos = OrdersHistoryTotal()- 1 ; pos >= 0 ; pos--)
if ( OrderSelect (pos, SELECT_BY_POS, MODE_HISTORY) // Only my CLOSED orders
&& OrderMagicNumber() == magic.number // my magic number // <------- what Magic Number do you use when you place a trade ? it must match ! !
&& OrderSymbol() == Symbol() // and my pair. // magic.number should be a Globally defined variable that has your Magic Numer
&& OrderType() < OP_BUYLIMIT )
{
ClosePrice = OrderCloseprice();
break;
}
return (ClosePrice); // <------- this returns the Order Open Price NOT the ticket
}
i think u missing something if he has more than 1 order on the same pair (& the same magic) therefore i think it's better this way
double LastOpenPrice(intOrderType)
{
double OpenPrice;
datetime lastOpen; // First line addedfor ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)
if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
&& OrderMagicNumber() == magic.number // my magic number // <------- what Magic Number do you use when you place a trade ? it must match ! !
&& OrderSymbol() == Symbol() // and my pair. // magic.number should be a Globally defined variable that has your Magic Numer
&& OrderType() == OrderType
&& OrderOpenTime() > lastOpen) // Second line added
{
OpenPrice = OrderOpenprice();
break;
}
return (OpenPrice); // <------- this returns the Order Open Price NOT the ticket
}
i think u missing something if he has more than 1 order on the same pair (& the same magic) therefore i think it's better this way
your opinion
guys,
thanks a lot,
let me tell you why i want to use LastOpenPrice(OP_BUY) and LastOpenPrice(OP_SELL) because i want to use them in some conditions like
if ( LastOpenPrice(OP_BUY) -LastOpenPrice(OP_SELL)) > 0.0090 // for that reason i need to keep the last order was open for buy and the last order was open for sell, so i need separate last order one for buy and the other for sell.
-----
for double LastClosePrice() // can i used if ( OrderType() == OP_BUY || OP_SELL) instead *** OrderType() < OP_BUYLIMIT*** to get the last close whatover buy or sell.
----
for function number 4:
4- function to get and keep the previous close price before the last close order whatover buy or sell. // i want to get the closed order before the last closed order whatover buy or sell.
So why are you returning the ticket number ? Read the code you are copying and pasting, understand it, learn . . .
i used it to do the following
if(OrderSelect(LastOpenTicketForBuy(), SELECT_BY_POS)==true)
{ order for buy= OrderOpenPrice();}
then if ( (( order for buy+ order for sell)/2))<MarketInfo("EURUSD",MODE_BID) )
close the position
if(OrderSelect(LastOpenTicketForBuy(), SELECT_BY_POS)==true)
a little change with your permission
Dear qjol
thanks a lot for your real help. but still i am not sure if it will work or not ( i think my functions a little diffecult). let us see
first function :
function to get and keep the last order open price for buy only
what i need is: 1- function to get and keep the last order open price for buy only2- function to get and keep the last order open price for sell3- function to get and keep the last order close price whatover buy or sell4- function to get and keep the previous close price before the last close order whatover buy or sell.OK, try this . . .
It will do 1 & 2 . . .
LastOpenPrice(OP_BUY) for open price of last buy.
LastOpenPrice(OP_SELL) for open price of last sell.
And this . . . .
for 3 . . .
raptor
i think u missing something if he has more than 1 order on the same pair (& the same magic) therefore i think it's better this way
your opinion
raptor
i think u missing something if he has more than 1 order on the same pair (& the same magic) therefore i think it's better this way
your opinion
guys,
thanks a lot,
let me tell you why i want to use LastOpenPrice(OP_BUY) and LastOpenPrice(OP_SELL) because i want to use them in some conditions like
if ( LastOpenPrice(OP_BUY) -LastOpenPrice(OP_SELL)) > 0.0090 // for that reason i need to keep the last order was open for buy and the last order was open for sell, so i need separate last order one for buy and the other for sell.
-----
for double LastClosePrice() // can i used if ( OrderType() == OP_BUY || OP_SELL) instead *** OrderType() < OP_BUYLIMIT*** to get the last close whatover buy or sell.
----
for function number 4:
4- function to get and keep the previous close price before the last close order whatover buy or sell. // i want to get the closed order before the last closed order whatover buy or sell.
thanks