Download MetaTrader 5

No new order if last ORder was a buy/sell order

To add comments, please log in or register
akuh
56
akuh  

Dear Mql5 community,

 

Im working on an EA and i want to put the command:

 

I want the EA to put no new buy order, if the last order was a buy order, and the other way round with the sell order. therefore i found the following command to get the type of last closed order:

 

int LastOrderType()

{

    datetime TicketTime = 0;

    int TicketN,

        LastOT;

    for (int ix = 0; ix < OrdersHistoryTotal(); ix++)

    {

        if(OrderSelect(ix, SELECT_BY_POS, MODE_HISTORY) 

            && OrderMagicNumber() == Magic 

            && OrderSymbol() == Symbol())

        {

            if (OrderCloseTime() > TicketTime)

            {

                TicketTime = OrderCloseTime();  //For testing

                TicketN = OrderTicket();        //For testing

                LastOT = OrderType();

            }   

        }

        else

            Print("OrderSelect returned the error of ",GetLastError());

    }

    Print("Last closed order: ",TicketN,"  ",TicketTime,"  ",LastOT);   //For testing

    return(LastOT); // Buy==0, Sell==1, Others==2 through 5

}// End Last Order Type

Now i want to put "LastOT" in my buy/sell condition. The EA shall only open an Buy Order if the last Order was Sell order and the other way round. If i put LastOT in my buy sell condition i get the message "undeclared identifier". Why do i get this message ?

 

akuh 

Carl Schreiber
Moderator
7944
Carl Schreiber  
Would you mind to edit your post and put your code in the source box - use the SRC-button in the edit line!
whroeder1
17063
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. akuh: If i put LastOT in my buy sell condition i get the message "undeclared identifier". Why do i get this message ?
    LastOT is declared inside LastOrderType() therefor it's not available outside. You call your function and it returns a int. What do you do with the value?
akuh
56
akuh  
Carl Schreiber:
Would you mind to edit your post and put your code in the source box - use the SRC-button in the edit line!

Ok i think i have solved the problem !

To add comments, please log in or register