How to read the last closed order?

 

Hi, just like the subject, i am having difficulties to define the last closed order. What is the code i should add?

Thanks for your help.

 
kieruwin:

Hi, just like the subject, i am having difficulties to define the last closed order. What is the code i should add?

Thanks for your help.

Have a look at the function I wrote for this other poster.

You'll need to adapt it a bit but it'll get you started.

https://forum.mql4.com/22737

 
cloudbreaker wrote >>

Have a look at the function I wrote for this other poster.

You'll need to adapt it a bit but it'll get you started.

https://forum.mql4.com/22737

Ok i will write it down, I hope you don't mind to teach me again if i am still confuse.

Thank you very much cloudbreaker.

 
cloudbreaker wrote >>

Have a look at the function I wrote for this other poster.

You'll need to adapt it a bit but it'll get you started.

https://forum.mql4.com/22737

hi, i got some problem. My EA doesn`t make trade today, i didn`t know whats wrong? after the last week last close order, it just stop and not make trade.

here some of my code :

if (TotalMikuOrders()==0&&OrdersHistoryTotal()>0){
RefreshRates();
for (i = OrdersHistoryTotal()-1; i>=0; i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true){
if(OrderClosePrice()>OrderOpenPrice()){
if(OrderMagicNumber()==Magic_Miku_B){
Print("Magic number for this order : ", OrderMagicNumber());

sendMikuUP(Bid,Magic_Miku_S,Magic_Miku_B+1,XFactor*CoA,XFactor*CoB,com+"S1",com+"B2",sl1,sl2,r1,r1,sp,sp0,tp1,tp2);
return(0);}

if(OrderMagicNumber()==Magic_Miku_B+1){

sendMikuUP(Bid,Magic_Miku_S,Magic_Miku_B+2,XFactor*CoA,XFactor*CoC,com+"S1",com+"B3",sl1,sl3,r1,r2,sp,sp0,tp1,tp3);
return(0);}

the rest is on my attachment, please help CB

thank you

Files:
 
kieruwin wrote >>

hi, i got some problem. My EA doesn`t make trade today, i didn`t know whats wrong? after the last week last close order, it just stop and not make trade.

here some of my code :

if (TotalMikuOrders()==0&&OrdersHistoryTotal()>0){
RefreshRates();
for (i = OrdersHistoryTotal()-1; i>=0; i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true){
if(OrderClosePrice()>OrderOpenPrice()){
if(OrderMagicNumber()==Magic_Miku_B){
Print("Magic number for this order : ", OrderMagicNumber());

sendMikuUP(Bid,Magic_Miku_S,Magic_Miku_B+1,XFactor*CoA,XFactor*CoB,com+"S1",com+"B2",sl1,sl2,r1,r1,sp,sp0,tp1,tp2);
return(0);}

if(OrderMagicNumber()==Magic_Miku_B+1){

sendMikuUP(Bid,Magic_Miku_S,Magic_Miku_B+2,XFactor*CoA,XFactor*CoC,com+"S1",com+"B3",sl1,sl3,r1,r2,sp,sp0,tp1,tp3);
return(0);}

the rest is on my attachment, please help CB

thank you

Anybody home, Hello??

If you had a time, please teach me how to define the last closed order.

Any Help will got a big thanks.

 
kieruwin:

Anybody home, Hello??

If you had a time, please teach me how to define the last closed order.

Any Help will got a big thanks.

Here I will show you how to get the last closed order ticket:


int last_closed_order_ticket;

int last_closed_time = 0;

for(int k=9;k>=0;k--) // Check the last 10 closed orders in history

{

if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderCloseTime()>last_closed_time)

{

last_closed_time=OrderCloseTime();

last_closed_order_ticket=OrderTicket();

}

}

}

// Now here you can select the last closed order using OrderSelect(last_closed_order_ticket, SELECT_BY_TICKET, MODE_HISTORY)


Good luck!

 
robofx.org wrote >>

Here I will show you how to get the last closed order ticket:

int last_closed_order_ticket;

int last_closed_time = 0;

for(int k=9;k>=0;k--) // Check the last 10 closed orders in history

{

if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderCloseTime()>last_closed_time)

{

last_closed_time=OrderCloseTime();

last_closed_order_ticket=OrderTicket();

}

}

}

// Now here you can select the last closed order using OrderSelect(last_closed_order_ticket, SELECT_BY_TICKET, MODE_HISTORY)

Good luck!

Ok i will try it now, Many many thanks.

Thank you master (robofx).

 
kieruwin wrote >>

Ok i will try it now, Many many thanks.

Thank you master (robofx).

what if i want to know if the last closed trade from history is a BUY or a SELL, how do i select that.

thanks

Reason: