NavigationUser loginWho's new
Who's onlineThere are currently 0 users and 51 guests online.
|
Appendix 2 - Trading FunctionsMQL4 COURSE By Coders’ guru (Appendix 2) Trading Functions -------------------- In this appendix you will find the description of the 25 MQL4 trading functions. I decided to write this appendix before writing the third part of “Your First Expert Advisor” lesson because you have to know these important functions before cracking the remaining of the code. OrderSend: Syntax:
Description: The OrderSend function used to open a sell/buy order or to set a pending order. It returns the ticket number of the order if succeeded and -1 in failure. Use GetLastError function to get more details about the error. Note: The ticket number is a unique number returned by OrderSend function which you can use later as a reference of the opened or pending order (for example you can use the ticket number with OrderClose function to close that specific order). Note: GetLastError function returns a predefined number of the last error occurred after an operation (for example when you call GetLastError after OrderSend operation you will get the error number occurred while executing OrderSend). Calling GetLastError will reset the last error number to 0. You can find a full list of MQL4 errors numbers in stderror.mqh file. And you can get the error description for a specific error number by using ErrorDescription function which defined at stdlib.mqh file. This function takes 11 parameters: string symbol: Note: Use Symbol() function to get currently used symbol and OrderSymbol function to get the symbol of current selected order. int cmd:
Note: You can use the integer representation of the value or the constant name. For example: But it's recommended to use the constant name to make your code clearer. double volume: double price: int slippage: Note: slippage is the difference between estimated transaction costs and the amount actually paid. double stoploss: double takeprofit: string comment: Note: Default value of a parameter means you can leave (don’t write) it out, and MQL4 will use a predefined value for this parameter. For example we can write OrderSend function with or without comment parameter like this: OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-25*Point,Ask+25*Point,"My order comment",12345,0,Green); Or like this: int magic: Note: Magic number is a number you assign to your order(s) as a reference enables you to distinguish between the different orders. For example the orders you have opened by your expert advisor and the orders have opened manually by the user.
Figure 1 - Comment
datetime expiration: The time you want your pending order to expire at. The default time is 0 which means there's no exportation.
Note: The time here is the server time not your local time, to get the current server time use CurTime function and to get the local time use LocalTime function.
color arrow_color: The color of opening arrow (Figure 2), the default value is CLR_NONE which means there's no arrow will be drawn on the chart.
Figure 2 – Arrows color
Example:
|