sngerge's  Instablog

Send Message
Hello, I support green products and actively involved in recycling movement. Currently am blogging, affiliate marketing, selling holiday gifts online and trading Forex to earn extra income to support family on top of having a full-time job. I am currently hosting a Forex review website at... More
My blog:
  • Basic Programming For MT4 Currency Trading 0 comments
    May 11, 2012 12:11 AM | about stocks: ZYXI

    Programming is a common language used in software industry and with the release of MetaTrader trading platform, it introduce a programming language with is similar to C into the Forex Trading world.

    With programming, Forex Trader can put their winning strategy into programming codes and run on MT4 trading platform to let the computer trades automatically. This is make possible using MQL or metaquotes languages to write and compile using metaeditor into executable ex files which are called expert advisor to run on MT4 trading account.

    The programming is similar to C with declaration of variables, logic comparision and executing of files and functions.


    MQL4 comes with various data types namely integer, Boolean, character, string, float, color and date & time. You can create local variable can using the standard declaration like int, double, string, etc. For global variables, you have to declare the variables before int start. To have your variable available and value retained after program ended, use static variable declaration by static int, static double, etc

    Standard Constants

    It comes with many standard constant that you can use which is already predefine by the program. One of the most important standard constants are time frame which comes with PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1 and PERIOD_MN1. This is useful in defining the currency chart to use for technical indicator trigger. Next is the OrderSend function which uses trade operations constant OP_BUY, OP_SELL, OP_BUYLIMIT, OP_SELLLIMT, OP_BUTSTOP and OP_SELLSTOP which covers all the 6 different trade execution. The last importance standard constant is price related which is PRICE_CLOSE, PRICE_OPEN, PRICE_HIGH and PRICE_LOW which is often used in technical charting.

    Predefined Variables

    Ask, Bars, Bid, Close, Digits, High, Low, Open, Point and Time are widely use thru out the programming codes. When comparing currency price, Ask, Bid, Close, Open, High and Low are often called for operand operation. Bars is used when counting the number of bars in the selected currency chart. Point is the current symbol point value in the quote currency and Digits is the number after decimal point for the current symbol price. Both are used to compute stop loss, profit take, buy and sell price.

    Account Information

    This is a group of function which provided important information about your trading account and is used for computing trading lots and money management system including calculating of margin and balance. The often used function are AccountBalance, AccountFreeMargin, AccountLeverage, AccountMargin and AccountProfit. You need to input some margin requirement and usually I use minimum 200% margin requirement for maximum open lots using account leverage for maximum drawdown to avoid margin call.

    Date and Time Functions

    The widely used functions are DayOfWeek to get the Monday to Sunday of the date, Hour and minute for time and Seconds for looping. If your strategy is time constraint, meaning it only run during 2 to 4 am and only on Monday to Wednesday, this group of function is definitely the ones that you called to compare and execute codes.

    Technical Indicators

    This is the most important functions you be calling if you are using technical charting to execute trading rules. The common indicator that I used are iMA which is moving average simple/exponential/linear weighted calculation, iRSI which is Relative Strength Index, iMACD which is Moving Average Convergence/Diverage, iBands which is Bollinger Bands, iCCI which is Commodity Channel Index, iStochastic which is Stochastic Oscillator and iADX which is Movement Directional Index.

    Trading Functions

    This is required for any trading to be successful. The widely used trade function are OrderSend, OrderSelect, OrderClose and OrderModify. You may refer to MQL4 documentation for more information of the various functions. And refer to my website for more software offers with ready to use program codes.


    Stocks: ZYXI
Back To sngerge's Instablog HomePage »

Instablogs are blogs which are instantly set up and networked within the Seeking Alpha community. Instablog posts are not selected, edited or screened by Seeking Alpha editors, in contrast to contributors' articles.

Comments (0)
Track new comments
Be the first to comment
Full index of posts »
Latest Followers

Latest Comments

Instablogs are Seeking Alpha's free blogging platform customized for finance, with instant set up and exposure to millions of readers interested in the financial markets. Publish your own instablog in minutes.