what's wrong with my code?

ziyang2048  
MqlTradeRequest Request;
MqlTradeResult Result;
MqlTick Tick;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   for(int i = 1; i<2; i++)
     {
      if(SymbolInfoTick(Symbol(),Tick))
        {
         Request.action = TRADE_ACTION_DEAL;
         Request.volume = 0.01;
         Request.order = ORDER_TYPE_BUY;
         Request.symbol = Symbol();
         Request.price = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
         Request.type_filling = ORDER_FILLING_IOC;
         OrderSend(Request,Result);
         Sleep(1000);
         ZeroMemory(Request);
         ZeroMemory(Result);
        }

      if(SymbolInfoTick(Symbol(),Tick))
        {
         Request.action = TRADE_ACTION_SLTP;
         Request.position = PositionGetTicket(0);
         Request.symbol = PositionGetString(POSITION_SYMBOL);
         if(Request.type == ORDER_TYPE_BUY)
           {
            Request.sl = 21222.00;
            Request.tp = 26261.00;
           }
         else
            if(Request.type == ORDER_TYPE_BUY)
              {
               Request.sl = 26261.00;
               Request.tp = 21222.00;
              }
         OrderSend(Request,Result);
         ZeroMemory(Request);
         ZeroMemory(Result);
        }

      if(SymbolInfoTick(Symbol(),Tick))
        {
         Request.action = TRADE_ACTION_DEAL;
         Request.position = PositionGetTicket(0);
         Request.volume = PositionGetDouble(POSITION_VOLUME);
         Request.symbol = PositionGetString(POSITION_SYMBOL);
         ENUM_POSITION_TYPE Pos_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
         if(Pos_type == POSITION_TYPE_BUY)
           {
            Request.order = ORDER_TYPE_SELL;
            Request.price = Tick.bid;
           }
         else if(Pos_type == POSITION_TYPE_SELL)
           {
            Request.order = ORDER_TYPE_BUY;
            Request.price = Tick.ask;
           }
          OrderSend(Request,Result);
        }
     }
  }

Hi guys, I have some question

May I ask what's wrong with my code, it successfully place an order and modify position sltp,

but it can't close the position, why?

_MAHA_  
ziyang2048:

Hi guys, I have some question

May I ask what's wrong with my code, it successfully place an order and modify position sltp,

but it can't close the position, why?

Did you check the retcode?


Btw change 

else
            if(Request.type == ORDER_TYPE_BUY)
              {
               Request.sl = 26261.00;
               Request.tp = 21222.00;
              }

to 

else
            if(Request.type == ORDER_TYPE_SELL)
              {
               Request.sl = 26261.00;
               Request.tp = 21222.00;
              }
ziyang2048  
_MAHA_ #:

Did you check the retcode?


Btw change 

to 

I'll check now and change,

thanks, MAHA

Reason: