MT5 Market order Buy and sell

 //buy   trade.SetExpertMagicNumber(MagicNumber); trade.Buy(lotsize,Symbol(),NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits),0,0,"Programetix Ea");




///sell

  trade.SetExpertMagicNumber(MagicNumber); trade.Sell(lotsize,Symbol(),NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits),0,0,"Programetix Ea");


//exit buy all


void close_buy_position()

  {

   for(int i=PositionsTotal()-1; i>=0; i--)

     {

      string currencypair=PositionGetSymbol(i);

      int position_direction=PositionGetInteger(POSITION_TYPE);

      int posmagic=PositionGetInteger(POSITION_MAGIC);

      if(currencypair==Symbol() && position_direction == POSITION_TYPE_BUY&& int(posmagic) == int(MagicNumber))

        {

         int ticket=PositionGetTicket(i);

         trade.PositionClose(ticket);

        }

     }


  }



//exit sell all


void close_sell_position()

  {

   for(int i=PositionsTotal()-1; i>=0; i--)

     {

      string currencypair=PositionGetSymbol(i);

      int position_direction=PositionGetInteger(POSITION_TYPE);

      int posmagic=PositionGetInteger(POSITION_MAGIC);

      if(currencypair==Symbol() && position_direction == POSITION_TYPE_SELL&& int(posmagic) == int(MagicNumber))

        {

         int ticket=PositionGetTicket(i);

         trade.PositionClose(ticket);

        }

     }

  }


Comments

Popular posts from this blog

MQL5 : Add time to current time in mins

MQL5 : Get current trading session