Seeking Alpha - Basic Programming For MT4 Currency Trading

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.


While most books on trading deal with general concepts and shy away from specifics, Forex Patterns and Probabilities provides you with real-world strategies and a rare sense of clarity about the specific mechanics of currency trading. Leading trading educator Ed Ponsi will explain the driving forces in the currency markets and will provide strategies to enter, exit, and manage successful trades. Dozens of chart examples and explanations will guide you each step of the way and allow the reader to "look over the shoulder" of a professional trader hard at work at his craft.This book provides traders with step-by-step methodologies that are based on real market tendencies. The strategies in this book are presented clearly and in detail, so that anyone who wishes to can learn how to trade like a professional. It is written in a style that is easy to understand, so that the reader can quickly learn and use the techniques provided.

From the Inside Flap

In recent years, traders have turned to the foreign exchange market expecting to capture substantial profits. While the high availability of leverage within this arena can improve your chances of making money, ultimately the success of your endeavors depends upon how well you understand and operate within this market. Nobody knows this better than author Ed Ponsi. As a professional trader and leading educator of traders, Ponsi has developed a proven approach to trading today's forex market, and now, with Forex Patterns and Probabilities, he wants to share it with you.
While most books on trading deal with general concepts and shy away from specifics, Forex Patterns and Probabilities provides you with real-world strategies and a rare sense of clarity about the specific mechanics of currency trading that will allow you to take advantage of both trending and range-bound markets.
Written in a straightforward and accessible style, Forex Patterns and Probabilities will help you make the most of your time in this market. You'll be introduced to a variety of elements that are essential to forex trading success and discover the best ways to enter, exit, and manage trades. Dozens of chart examples and explanations will guide you each step of the way and allow you to "look over the shoulder" of a professional trader hard at work at his craft.
Divided into four comprehensive parts, this detailed guide:
  • Explains the playing field of the forex market, using powerful metaphors that relate trading scenarios to situations in everyday life
  • Outlines several specific trading strategies—including the FX-Ed Trend Technique—designed for trending markets
  • Delves into a variety of non-trending trading techniques—from the volatility-based Squeeze Play to the hedge fund–inspired Interest Rate Edge—which are all based on unique market tendencies
  • Offers an insider's view on how to emulate the behavioral patterns of successful professional traders—and how to escape the mindset of the amateur
  • And much more
Today's forex market contains some of the most profitable trading opportunities in the world. With the practical strategies and trading methodologies found in Forex Patterns and Probabilities you can uncover these opportunities and achieve long-term financial success along the way.

From the Back Cover

"Ed has the experience, he has the knowledge, and he has the ability to wrap it all up into one of the most useful and insightful books on trading that I've read. You're going to be a better trader with the help of this book."
—Rob Booker, independent currency trader, and author of Adventures of a Currency Trader
"This book is a must-read for any equities trader who is trying to learn the ins and outs of the forex markets. Ed has the rare gift among traders and educators to take complex trading theories and break them down into interesting and easy-to-digest trading concepts. I have personally had the benefit of studying live with Ed, and I found this book a great review of my live courses with him and now use it as my main forex reference book in my trading library. Ed you truly are the rock star of the FX markets. Well done!"
—Michael J. Di Gioia, cofounder, the Results-Driven Financial Network
"Forex Patterns and Probabilities is one of the best practical forex trading books I have read, and I have read a good many forex books! Ed thoroughly teaches those areas that cause most difficulty for new traders, from economic fundamentals to technical trading to the psychological aspects that are so important but ignored by so many new to trading. Peppered throughout with anecdotes from the trading and non-trading world, Ed's easygoing, homespun style gets his message across very effectively. This work is destined to become essential reading for both new and established traders."
—George Hallmey, Director,
"Ed Ponsi is a complete teacher! Forex Patterns and Probabilities covers it all for forex and trading in general. This book will teach you the foundations, the tactics, the pitfalls, and the 'real' world of forex. As Director of Education for the Online Trading Academy, I understand the importance of education and trading knowledge. . . Forex Patterns and Probabilities, while focused on forex, allows the reader to see the nuances of trading in general—fundamental, technical, psychological, plan management, and a strong, healthy dose of risk management and discipline."
—Mike McMahon, Director of Education, Online Trading Academy

About the Author

Ed Ponsi is the President of and is the former chief trading instructor for Forex Capital Markets. He is an experienced professional trader and money manager who has advised hedge funds, institutional traders, and individuals of all levels of skill and experience. Ponsi is featured on the DVD series, Forex Trading with Ed Ponsi. He is a dynamic public speaker who has appeared on numerous television and radio programs, and is a frequent guest lecturer at trading conventions and seminars around the world.

 Forex Patterns and Probabilities: Trading Strategies for Trending and Range-Bound Markets (Wiley Trading) Click here for more amazon customer reviews and rating... 

How did trader, John W. Henry, start out as a farmer and end up a billionaire and owner of, first the Florida Marlins and now, the Boston Red Sox? How do traders like Bill Dunn, Ed Seykota and Keith Campbell continually pull profits in the hundreds of millions from both bull and bear markets? The answer is that they are trend followers. Trend following is the only strategy to consistently make money in the markets. Leading expert Michael Covel reveals the underground network of these little-known traders and hedge fund managers who have practiced trend following for years. He pulls back the veil on their strategies by introducing the basic concepts/techniques of trend following such as why the market price contains all the information a trader needs. Covel rigorously reviews and analyzes years of detailed performance data to prove without question that trend following works. He breaks down trend following strategies including how to make volatility work; how to control risk; and how to make successful trading decisions "from the gut."Covel shows why trend following is ideal for individual traders who self-manage their portfolios or for the individual investor searching for a new type of investment advisor. Along the way he debunks an immense amount of misinformation/failed advice from pros who ought to know better. This timely book capitalizes on today's massive move back into the markets and investors' renewed determination to find strategies that really work.


A recent interview with Michael Covel on Bloomberg Radio (6.5 MB MP3 audio file) about trend following.
"Please read [Trend Following] whether you think you have an interest in trend following or are not quite sure. I guarantee you will be happy that you took the time. It, of course, covers how trend following works, how it's done, and who can do it, and it doesn't beat around the bush with generalities. Again, get this book. Covel has hit a homerun with it."
Gail Osten, Editor-in-Chief
Stocks, Futures & Options Magazine
Official Journal for Personal Investing in Stocks, Futures and Options

"A mandatory reference for anyone serious about alternative investments."
Jon Sundt, President and CEO of Altegris

"Michael Covel does an excellent job of educating his readers about the little-known opportunities available to them through one of the proven best hedge fund strategies. This book is like gold to any smart investor."
Christian Baha, CEO, Superfund

"A most interesting book -- definitely a 'must have' on your shelf. Pull out the plastic and get it!...Trend Following is well constructed, well written and an excellent distillation of the research undertaken by the author. Backed up by trading 'legends' like Ed Seykota, it convincingly argues that the most successful trading systems are based on trend following...While you may read the book in bed, especially the first time, it is best read at a desk with a notepad handy. While seeming to come from the perspective of technical analysis it is still a very good book on trading psychology...The book is both a great read and an insightful textbook for all traders and investors."
Garnett Znidaric
Your Trading Edge Magazine/strong>

"Michael Covel's Trend Following: Essential."
Ed Seykota
Trend Follower for 35 years, Incline Village, NV
The Trading Tribe
Ed was originally profiled in The Market Wizards by Jack Schwager

"Michael Covel's book is the definitive guide to trend trading. Backed by real world results from some of the biggest and best money managers in the United States, his book will put you on the path to successful trend trading."
Larry Connors

"Covel has created a very rare thing - a well-documented and thoroughly researched book on trend following that is also well-written and easy to read. It touches on a wide variety of the principles and practices which make for successful trend following. This is one book that traders at all levels will find of real value."
John Mauldin
Millennium Wave Investments, Arlington, TX
Author of Bull's Eye Investing and editor of Thoughts from the Frontline

"I think the book did a superb job of covering the philosophy and thinking behind trend following (basically why it works). You might call it the Market Wizards of Trend Following."
Van K. Tharp, Ph.D.
Author of Trade Your Way to Financial Freedom
President, International Institute of Trading Mastery, Inc.
Van was originally profiled in The Market Wizards by Jack Schwager.
--This text refers to an out of print or unavailable edition of this title.

From the Back Cover

About the Author

Excerpt. © Reprinted by permission. All rights reserved.


"Men wanted for hazardous Journey. Small wages. Bitter cold. Long months of complete darkness. Constant danger. Safe return doubtful. Honor and recognition in case of success."1
This book is the result of an eight-year "hazardous journey" for the truth about Trend Following. It fills a void in a marketplace inundated with books about finance and trading but lacking any resource or, for that matter, practically any reference to what we believe is the best strategy to consistently make money in the markets. That strategy is known as Trend Following:
"Let's break down the term 'Trend Following' into its components. The first part is 'trend.' Every trader needs a trend to make money. If you think about it, no matter what the technique, if there is not a trend after you buy, then you will not be able to sell at higher prices . . . 'Following' is the next part of the term. We use this word because trend followers always wait for the trend to shift first, then 'follow' it."2
When it is a question of money, everyone is of the same religion.
Trend Following seeks to capture the majority of a trend, up or down, for profit. It trades for profits in the major asset classes—stocks, bonds, currencies, and commodities. However simple the basic concepts about Trend Following are, they have been widely misunderstood. Our desire to correct this state of affairs is what, in part, launched our research. We wanted to be as objective as possible, so we based our writing on the available data:
  • Trend followers' month-by-month performance histories.
  • Trend followers' published words and comments over the last 30 years.
  • News accounts of financial disasters.
  • News accounts of the losers in those financial disasters.
  • Charts of markets traded by trend followers.
  • Charts of markets traded by losers in the financial disasters.
Education rears disciples, imitators, and routinists, not pioneers of new ideas and creative geniuses. The schools are not nurseries of progress and improvement, but conservatories of tradition and unvarying modes of thought.
Ludwig von Mises
If we could have developed a book comprised of only numbers, charts, and graphs of Trend Following performance data, we would have. However, without any explanation, few readers would have appreciated all of the ramifications of what the data showed. Therefore our approach to writing Trend Following became similar to the one Jim Collins describes in Good to Great, in which a team of researchers generated questions, accumulated data in their open-ended search for answers, and then energetically debated it.
Trend followers we studied form a sort of underground network of relatively unknown traders who, except for an occasional article, the mainstream press has virtually ignored. What we have attempted to do is lift the veil, for the first time, on who these enormously successful traders are, how they trade, and what is to be learned from their approach to trading that we might apply to our own portfolios.
Trend Following challenges much of the conventional wisdom about successful trading. We were determined to avoid being influenced by knowledge institutionalized and defined by Wall Street. We were adamant about fighting "flat earth" thinking. During our research, we tried to avoid starting with an assumption and then finding the data to support it. Instead we asked the question and then, objectively, doggedly, and slowly, let the answer reveal itself.
If there was one factor that motivated us to work in this manner, it was simple curiosity. The more we uncovered about trend followers, the more we wanted to know. For example, one of our earliest questions was who profited when Barings Bank collapsed in 1995. Our search unearthed Barings Bank–related performance data including that of trend follower John W. Henry (now the majority owner of the Boston Red Sox). His track record generated new questions, such as, "How did he discover Trend Following in the first place?" and "Has his approach changed in any significant way in the past 20 years?"
We were also curious about who won the $1.9 billion Long Term Capital Management lost during August and September 1998. We wanted to know why the biggest banks on Wall Street would invest $100 billion in an options pricing model, Nobel prize–winning or not. Further, considering what mutual fund managers have lost in the past few years and what successful trend followers have earned during the same time period, we could not understand why so few investors know anything about Trend Following. We also became interested in:
  • How trend followers win in the zero-sum game of trading.
  • Why Trend Following has been the most profitable style of trading.
  • The philosophical framework of trend followers' success.
  • Timeless principles of Trend Following.
  • The Trend Following worldview of market behavior.
  • Reasons why Trend Following is so enduring.
The important thing in science is not so much to obtain new facts as to discover new ways of thinking about them.
Sir William Bragg
Many of the trend followers we studied are reclusive and extremely low key. Some discovered Trend Following on their own and used it to make their fortunes out of home offices. Bill Dunn, a successful trend follower who has beaten the markets for over 25 years, works out of a quiet, spartan office in a Florida coastal town. For Wall Street, this approach to trading is tantamount to sacrilege. It goes against all the customs, rituals, trappings, and myths we have grown accustomed to associating with Wall Street success. In fact, it is our hope that our profiles of trend followers will correct the public's misconception of a successful trader as a harried, intense workaholic who spends 24/7 in the labyrinth of a Wall Street trading firm, surrounded by monitors and screaming into a phone.
We've assembled the first comprehensive look at Trend Following, but this is neither a course nor the only resource you will ever need. It is to be used in conjunction with our Web site at We have tried to be comprehensive with our definitions. However, if we mention an unfamiliar word, name or reference a source you haven't heard of, please go to Google (
Fish see the bait, but not the hook; men see the profit, but not the peril.
Chinese Proverb
We have tried to make the material accessible and interesting enough so it might give you an occasional "aha" experience. However, if you're looking for trading "secrets," you need to look elsewhere. There are none. If you're in the mood for stories about what it's like inside a typical Wall Street firm or how greedy traders sow the seeds of their destruction, like in Den of Thieves, or Barbarians at the Gate, we will not meet your needs.
You may have noticed that I use "we" instead of "I" when describing the process of writing this book. That's because it could not have been written without the generosity of the traders, professors, investors, colleagues, and friends who graciously shared their wisdom and trading experiences with me. Without their support, hard work, long hours, and creativity, Trend Following would still be an ongoing hazardous journey. So if there is any "honor and recognition" to be given, it is to everyone who participated, not just the person whose name appears on the cover.
To be aware how fruitful the playful mood can be is to be immune to the propaganda of the alienated, which extols resentment as a fuel of achievement.
Eric Hoffer

 Trend Following: How Great Traders Make Millions in Up or Down Markets (Financial Times Prentice Hall Books) Click here for more amazon customer reviews and rating...

Money management may very well be the most important piece of the trading puzzle. In A Trader's Money Management System, expert Bennett McDowell provides time-tested techniques that can turn a losing trader into a winning one?and take the winning trader to an entirely new level. In revealing his personal approach to staying out of trouble in the financial markets and maximizing profits, he offers comprehensive insights into:
  • The psychology of risk control as well as the finer aspects of setting stop-loss exits
  • The value of managing trade size and consistent record keeping
  • The process of putting together your own personal money management system
Unlike other books that focus on the complex mathematical theories behind money management, this book presents its system in straightforward, easy-to-understand terms that will allow you to quickly see how these concepts work and immediately benefit from the value of effectively managing risk.

From the Inside Flap

Risk control tends to be the last thing that most traders focus on, perhaps because of the popular belief that it's their trading strategy that will generate great fortunes. But ultimately, a strategy alone won't create riches. A trader or investor needs to develop discipline, a strong financial psychology, and a sound money management system to maximize profits and keep them out of financial danger. In A Trader's Money Management System, veteran trader Bennett McDowell offers readers an expert guide to the most important elements of money management in trading.McDowell shares his personal money management system, with the ultimate goal of helping you design your own system, customized to fit your risk tolerance, your experience level, and financial needs. He identifies the six types of risk to consider every time you make a trade—trade risk, market risk, margin risk, liquidity risk, overnight risk, and volatility risk—covering each in detail.
In easy-to-understand terms, the author then breaks down his system into five key elements. He first explains the psychology of risk control, telling what issues to look for and how to address them in order to more effectively implement your money management system. McDowell then details a variety of stop-loss approaches and gives you tips on how to make sure you adhere to them when they're hit. He follows with a discussion of trade size, showing how to determine how large or small your trade size should be so that you are not overextending your risk. McDowell then covers the crucial element of record keeping, and explains how it pays significant dividends. Finally, he shows how to design a realistic personal plan—one that you will continue to use and profit from.
This book also equips readers with two valuable tools: A one-month free trial of Trade Size Calculator software and The Trader's Assistant recordkeeping materials. The trial Trade Size Calculator software is downloadable at (see Appendix A for details), and The Trader's Assistant recordkeeping materials can be photocopied directly from the book. These two tools complement the text and together provide a complete package that will deliver better results to your bottom line.

From the Back Cover

Praise for A Trader's Money Management System"I am pleased to strongly recommend this excellent book, A Trader's Money Management System. If you are picking up this book, congratulations, since you have taken the first steps in following in the footsteps (by using proper money management) of successful traders."
—Steve Nison, President,, and author of Japanese Candlestick Charting Techniques
"Bennett McDowell demystifies money management for traders in his new book. With these simple, time-tested strategies, a trader will decrease the time it will take to become profitable."
—Adrienne Toghraie, President,
"Bennett McDowell does traders a HUGE favor in this valuable book by emphasizing the extreme importance of risk control and its vital place in a sound trading plan. Further, he provides knowledge of and access to specific tools, which enable the trader to implement his ideas simply and effectively. His simple straightforward treatment of a complex and often boring subject is a breath of fresh air and a worthwhilecontribution to this important element so crucial to the achievement of successful trading results."
—Edward D. Dobson, President, Traders Press Inc.
The best-kept secret to trading success: money management
Money management may very well be the most important piece of the trading puzzle. In A Trader's Money Management System, expert Bennett McDowell provides time-tested techniques that can turn a losing trader into a winning one—and take the winning trader to an entirely new level. In revealing his personal approach to staying out of trouble in the financial markets and maximizing profits, he offers comprehensive insights into:
  • The psychology of risk control as well as the finer aspects of setting stop-loss exits
  • The value of managing trade size and consistent record keeping
  • The process of putting together your own personal money management system
Unlike other books that focus on the complex mathematical theories behind money management, this book presents its system in straightforward, easy-to-understand terms that will allow you to quickly see how these concepts work—and immediately benefit from the value of effectively managing risk.

About the Author

Bennett A. McDowell is the founder of® and an expert in technical analysis and complex trading platforms. Earlier in his career as a financial advisor, McDowell used his own proprietary trading system to serve a community of high-net-worth clients. This system is now known as Applied Reality Trading®, or ART®, and is used by traders around the world in over forty countries. McDowell lectures nationally and writes articles for many leading trading publications, including Technical Analysis of Stocks & Commodities magazine. He is a recognized leader in trading education and is honored to be included as a member of the eSignal “Trading with the Masters” team. McDowell is also the author of The ART® of Trading, which is published by Wiley.

A Trader's Money Management System: How to Ensure Profit and Avoid the Risk of Ruin (Wiley Trading) Click here for more amazon customer reviews and rating...

No comments:

Post a Comment

Top Forex Automated Trading Expert Advisor (EA)

Forex EAROI (Monthly)Profit FactorMax Draw DownS3 ScoresStar
FAP Turbo207%31.770.32%280 points5 starsRank 31,123
GPS Forex Robot28%3.935.68%260 points4 starsRank 283,290
Forex MegaDroid19.8%NANA250 points4 starsRank 72,310
Leo Trader Pro32%2.855.84%250 points4 starsRank 213,570

Fully editable *.mq4 files that compile successfully with no errors (3MB zip file with 200+ EA codes. Including 40+ strategies from the Strategy Book. You can download the Free Strategy Book by joining my email newsletter on the right side of this website. Click "Buy Now" to make payment and instant down the Best Forex Ranking Cook Book at USD $79 (One time payment only) Click here for more info

Please inform me if unable to purchase or download (send to