Navigation:Home > Content >

Trading.mqh

Time: 2016-08-10 | Download file:Trading.mqh

//+------------------------------------------------------------------+
//|                                                      Trading.mq4 |
//|                          Copyright © 2008, Empryean Software Ltd |
//|                                      http://finance.empryean.com |
//|                                                                  |
//|  19 Feb 2008 1.1 Tinashe B Chipomho                              |
//|                  Initial version                                 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Empryean Software Ltd"
#property link      "http://finance.empryean.com"

#define TRAILING_STOP_NONE 0
#define TRAILING_STOP_SIMPLE 1
#define TRAILING_STOP_HIGH_LOW 2
#define TRAILING_STOP_CUSTOM 3

#define TAKEPROFIT_NONE 0
#define TAKEPROFIT_SIMPLE 1
#define TAKEPROFIT_STEPPED 2
#define TAKEPROFIT_CUSTOM 3


#define ORDER_OPENPRICE 0
#define ORDER_COMMISION 1
#define ORDER_EXPIRATION 2
#define ORDER_LOTS 3
#define ORDER_CLOSEPRICE 4
#define ORDER_CLOSETIME 5
#define ORDER_COMMENT 6
#define ORDER_MAGICNUMBER 7
#define ORDER_OPENTIME 8
#define ORDER_PROFIT 9
#define ORDER_STOPLOSS 10
#define ORDER_SYMBOL 11
#define ORDER_TAKEPROFIT 12
#define ORDER_TICKET 13
#define ORDER_TYPE 14

#import "Trading.ex4"

  /**
   * Returns a string representation of the Order Type
   * @param type - Order Type
   */
  string Trading.OrderType2String(int type);
  
  /**
   * Closes an order given the ticket, using the specified lots, takeprofit and slippage.
   * @param type - Order Type
   * @param ticket - Order Ticket to close.
   * @param lots - The number of lots to close. The order can be closed partially if OrderLots is than lots.
   * @param slippage - slippage.
   */
  int Trading.Close(int type,int ticket, double lots, int Slippage=3);
  
  /**
   * Creates a new order based on given price, lots, stop loss and take profit. The method uses a 
   * number safe steps to ensure the order is created. If the Trade  context is busy it will attempt
   * to wait for 30seconds.
   * @param type - Order Type.
   * @param lots - Order Lots.
   * @param price - Order open price.
   * @param stoploss - order stop loss.
   * @param takeprofit - Order take profit.
   * @param comment - Order comment.
   * @param magicnumber - order magic number.
   * @param slippage - slippage defaults to 3.
   * @param expiration - order expiration date time.
   * @return the order ticket or -1 if the order creation failed.
   */
  int Trading.CreateOrder(int type,  double lots, double price,
                  double stoploss, double takeprofit,
                  string comment, int magicnumber,
                  int slippage=3,datetime expiration=0);
  /**
   * Delete all pending order for a given magicnumber and given symbol. Pending orders include stop loss Orders
   * and limit order, (orders that have not yet been filled).
   * @param mn - magic number
   * @param symbol - the symbol.
   *
   */
  void Trading.DeletePendingOrders(int mn, string symbol);
  
  /**
   * Closes open orders (filled orders) of a given type and given magic number for a 
   * given symbol.
   * @param type - order type
   * @param mn - magic number
   * @param symbol - order symbol.
   * @param slippage
   *
   */
  void Trading.CloseOrders(int type, int mn, string symbol, double slippage);
  
  /**
   * Checks the trading context or all open order and returns true if
   * there is an order of a given type, symbol with the specified magic number, otherwise
   * it returns false.
   * @param type - order type
   * @param symbol - symbol
   * @param mn - magic number.
   * @return true if an open order is found meeting the criteria otherwise false.
   *
   */
  bool Trading.HasOpenOrder(int type, string symbol, int mn);
  
  /**
   * Checks all orders to see if there is a sell order at a given price.
   * The price check is in the range of price + or - slippage.
   * This method check all sell type orders (sell, sell limit and sell stop)
   * 
   * @param price - sell price to check.
   * @param magicnumber - magic number 
   * @param slippage - slippage
   * @return true if there is a sell order at the given price otherwise false.
   */
  bool Trading.HasSellOrder(double price,int magicnumber,int slippage);
  
  /**
   * Checks all orders to see if there is a buy order at a given price.
   * The price check is in the range of price + or - slippage.
   * This method check all buy type orders (buy, buy limit and buy stop)
   * 
   * @param price - buy price to check.
   * @param magicnumber - magic number 
   * @param slippage - slippage
   * @return true if there is a buy order at the given price otherwise false.
   */
  bool Trading.HasBuyOrder(double price,int magicnumber,int slippage);
  
  /**
   * Modifies an existing order and updates price, stoploss, take profit and expiration datetime.
   * 
   * @param ticket - Order ticket to modify.
   * @param price - new price.
   * @param stoploss - new stop loss
   * @param takeprofit - take profit.
   * @param expiration - expiration date time
   * @param arrow_color - new color to be used.
   * @return true if the order is successfully updated otherwise false.
   */
  bool Trading.ModifyOrder(int ticket, double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE);
  
  /**
   * Checks the History for a closed buy order at a given price with a specific magic number.
   *
   * @param price - order price
   * @param magicnumber - order magic number.
   * @param slippage
   * @return true if the closed buy order is found, otherwise false.
   *
   */
  bool Trading.HasClosedBuyOrder(double price,int magicnumber,int slippage);
  
  /**
   * Checks the History for a closed sell order at a given price with a specific magic number.
   *
   * @param price - order price
   * @param magicnumber - order magic number.
   * @param slippage
   * @return true if the closed sell order is found, otherwise false.
   *
   */
  bool Trading.HasClosedSellOrder(double price,int magicnumber,int slippage);
  
  /**
   * Reads a named property from the configuration file given by config. The value
   * is read as a double and "Account.Pips.Factor" property is applied to it.
   * @param config - configuration property file with name=value pairs
   * @param name - name of the property in the file.
   * @return the value as a double, account multication factor is applied. if not property
   *         is found it returns 0.
   */
  double Trading.GetPips(string config, string name);
  
  /**
   * Deletes all pending orders with a given magic number and given symbol.
   * @param type - pending order types
   * @param mn - magic number
   * @param symbol - currency symbol.
   */
  void Trading.DeletePending(int type, int mn, string symbol);
  
  /**
   * Checks the precision of the double numbers for a given 
   * currency. All JPY pairs will return 2 otherwise 4
   * @param symbol - currency symbol
   * @return precision.
   */
  int Trading.CheckPrecision(string symbol);  
  
  /**
   * Manages Trailing stops using the settings given in the configuration file 
   * @param config - configuration file with settings
   */
  void Trading.ManageTSLevel(string config);
  
  /**
   * Manages Profit levels using the settings given in the configuration file 
   * @param config - configuration file with settings
   */
  void Trading.ManagePL(string config);
  
  void Trading.GetOrderData(int ticket, string& data[]);
  
#import

Recommend