Posted By:
30 Jul, 2014 10:13 pm PDT

Place orders in market by using functions in MetaTrader

We use functions like OrderSend to place the orders in market.

Syntax of OrderSend is :

int  OrderSend(
   string   symbol,              // symbol
   int      cmd                // operation
   double   volume,              // volume
   double   price,               // price
   int      slippage,            // slippage
   double   stoploss           // stop loss
   double   takeprofit,          // take profit
   string   comment=NULL,        // comment
   int      magic=0            // magic number
   datetime expiration=0,        // pending order expiration
   color    arrow_color=clrNONE  // color
   );
 

Parameters

symbol

[in]  Symbol for trading.

 

cmd

[in]  Operation type. It can be any of the Trade operation enumeration.

 

volume

[in]  Number of lots.

 

price

[in]  Order price.

 

slippage

[in]  Maximum price slippage for buy or sell orders.

 

stoploss

[in]  Stop loss level.

 

takeprofit

[in]  Take profit level.

 

comment=NULL

[in]  Order comment text. Last part of the comment may be changed by server.

 

magic=0

[in]  Order magic number. May be used as user defined identifier.

 

expiration=0

[in]  Order expiration time (for pending orders only).

 

arrow_color=clrNONE

[in]  Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart.

Attachment:None


Example of OrderSend function usage: 

//+------------------------------------------------------------------+
//| placeorders.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
extern double lot=0.01;
extern int stoploss=40;
extern int takeprofit=40;
extern int magic=38578;

int OnInit()
{
//---
OnSell();
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---

}
//+------------------------------------------------------------------+

void OnSell(){
//stoploss=.0040+.93956=.94356

OrderSend(Symbol() , OP_SELL , lot , 1.5678 , 3 , Bid+stoploss*Point , Bid-takeprofit*Point , "Sell trade", magic , Blue);
}
 
Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud