order select

 

it possible to select closed trade from history but how do you chose the last closed trade out of all the trades in history.

any idea inregards to this will be very appreciated

 
adesijsig:

it possible to select closed trade from history but how do you chose the last closed trade out of all the trades in history.

any idea inregards to this will be very appreciated

u have to use MODE_HISTORY instead of MODE_POS. the below script will return the most recently closed ticket number.


int RecentTicket()
{
double LargestTicket=0;
for(int k=OrdersTotal()-1;k>=0;k--)
{
if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)== true && OrderMagicNumber() == MagicNo)
{
if(OrderTicket()>LargestTicket)
{
LargestTicket = OrderTicket();
}
}
}
return(LargestTicket);
}

 

If you are working with History, and not the pool of Pending/Open orders...

for(int k=OrdersTotal()-1;k>=0;k--)
should be

for(int k=OrdersHistoryTotal()-1;k>=0;k--)

.

Choosing the highest ticket number may or may not give you the most recently closed.

scan for OrderCloseTime() and compare that among the closed tickets.

 

Choosing the highest ticket number may or may not give you the most recently closed.

Definitely. Tickets can close in the opposite order they are created (ticket number)

Also, the latest from IBFX is to allow hedgeing but at end of day (just before swaps) one or two orders are closed and a third is created with a new ticket number.

 
WHRoeder wrote >>

Definitely. Tickets can close in the opposite order they are created (ticket number)

Also, the latest from IBFX is to allow hedgeing but at end of day (just before swaps) one or two orders are closed and a third is created with a new ticket number.

thanks evryone, got it working now.

 
adesijsig wrote >>

thanks evryone, got it working now.

one more thing guys, i need to include order modify such that once the market goes in my favour by lets say 100pips, i want the ea to put a stop loss and the opening price of that trade to breake even. there wount be a stop loss placed at the initial opening of the trade untill it goes in my favour and then it breaks even, NOT TRAILING IT. A one time stop loss at 100pips or above.

thanks for considering this one, lots and lots of thanks