how I code?

 
int orders= OrdersHistoryTotal();
if( OrderSelect(orders,SELECT_BY_POS,MODE_HISTORY==true))
    {
     if(OrderType()==OP_BUY) //Month()==12 Year==2013  )
        {
      OrderSend(Symbol(),OP_SELL,,Bid,1,,,"",MAGICMA,0,Red);
     
      return;
        }
  else if(OrderType()==OP_SELL) 
         {
      OrderSend(Symbol(),OP_BUY,,Ask,1,,,"",MAGICMA,0,Blue);
      return;
         }

      }

Hi Coders, How I can code following: if the last closed order is sell then send buy order? or vise versa, so if the last closed order is buy then send sell order?

thanks.

 
What have you attempted. We cannot just write codes here for you. If you're looking for someone to write your code then look toward the Job_Section. Otherwise post your attempt using the SRC button above.
 
ok wrt down some codes but of course doesnt work.
int orders= OrdersHistoryTotal();
if( OrderSelect(orders,SELECT_BY_POS,MODE_HISTORY==true))
    {
     if(OrderType()==OP_BUY) //Month()==12 Year==2013  )
        {
      OrderSend(Symbol(),OP_SELL,,Bid,1,,,"",MAGICMA,0,Red);
     
      return;
        }
  else if(OrderType()==OP_SELL) 
         {
      OrderSend(Symbol(),OP_BUY,,Ask,1,,,"",MAGICMA,0,Blue);
      return;
         }

      }
    
 
ensark:
ok wrt down some codes but of course doesnt work.
OrderHistoryTotal() gives the total number of orders in the history pool, the positions start at 0 and go to OrdersHistoryTotal() - 1
 
ensark: ok wrt down some codes but of course doesnt work.

I'll strongly recommend the Book. Below are some codes to help you get started.

void start(){
    //First Time Running And Nothing In History
    if(HisLstOpnTyp()==Wrong_Value) OrderSend(RandomOrder()...);
    
    //Non_First Order ... Reverse Order Logic Using History
    if(HisLstOpnTyp()==OP_BUY) OrderSend(OP_SELL,...);
    
    //Non_First Order ... Reverse Order Logic Using History
    if(HisLstOpnTyp()==OP_SELL) OrderSend(OP_BUY,...);
}


int HisLstOpnTyp(){
//Returns The OrderType Of The Last Closed Order In History.
//Standard For_Loop Counting Down So That You Get The Last Order First.
//Remember That History Is Sorted By Close Time By Default.
        //Select Order By Position From The History Pool. 
        //If OrderSelect Fails Check The Next Order.
        //I Should Probably Use Return Instead Of Continue.
        //Anyways You Can GetLastError() And Ignore Results
        //If Order Magic Number Does_Not Match Then 
        //Move On To The Next Order In The Pool
        //If Order Symbol Does_Not Match My Symbol Then
        //Move On To The Next Order In The Pool
        //Returns OrderType As In OP_BUY or OP_SELL
    //Should The For Loop Find Nothing Which Matches
    //Return Wrong Value Which Is Usually Negative_1

    for(int i=OrdersHistoryTotal()-1; i>=0; i--){
        if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){continue;}
        if(OrderMagicNumber()!=SystemMagic1){continue;}
        if(OrderSymbol()!=CurSetSymbol){continue;}
        return(OrderType());
    }
    return(Wrong_Value);
}