Maximize the use of indicators in day trading

Best Binary Options Brokers 2020:
  • Binarium

    The Best Binary Broker 2020!
    Perfect For Beginners!
    Free Trading Education!
    Free Demo Account!
    Get Your Sign-up Bonus Now!

  • Binomo

    Good Broker For Experienced Traders!

MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors


In this article, the Expert Advisor will be enhanced with indicators whose values will be used to check position opening conditions. To spice it up, we will create a drop-down list in the external parameters to be able to select one out of three trading indicators.

Please be reminded, just in case: we continue to modify the Expert Advisor we have been working on throughout the preceding articles of the MQL5 Cookbook series. The last version of the Expert Advisor can be downloaded from the article entitled “MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties”.

In addition, this article will feature a function that we will create to check whether trading operations can or cannot be performed. The position opening function will be modified so as to enable the Expert Advisor to determine the trade mode (Instant Execution and Market Execution).

Since the code of the Expert Advisor, following all the enhancements and improvements made in the previous articles, already exceeds 1,500 lines, it will be getting less and less convenient with every new feature added. So, the logical solution is to divide it into several categories as separate library files. Now that the objectives have been set, let’s start.

Expert Advisor Development

We place the source code of the Expert Advisor (*.mq5) from the previous article into a separate folder, TestIndicatorConditions, in which we need to create the Include sub-folder. This is the folder where we will be creating include files (*.mqh). They can be generated using the MQL5 Wizard (Ctrl+N) or created manually in the required directory as standard text files (*.txt) and further renamed to *.mqh.

Below are the names of and comments to all the include files created:

  • Enums.mqh will contain all enumerations;
  • InfoPanel.mqh will feature functions for setting the info panel, creating and deleting graphical objects;
  • Errors.mqh will cover all functions that return error codes and deinitialization reasons;
  • TradeSignals.mqh will feature functions that fill arrays with prices and indicator values, as well as signal block;
  • TradeFunctions.mqh will contain trading functions;
  • ToString.mqh will cover functions that convert numerical values to string values;
  • Auxiliary.mqh will be used for other auxiliary functions.

To include these libraries to the main file, we use the #include directive. Since the main file of the Expert Advisor and the include file folder (Include) are located in the same folder, the code for including files will be as follows:

Then, we will be able to open and modify them and move a part of the source code from the main file of the Expert Advisor.

To correctly navigate through the code, references to the adjacent header files, as well as to the main file of the Expert Advisor will be added to each header file. For example, for our library of trading functions, TradeFunctions.mqh, this will look like this:

For files at the same nesting level, it is sufficient to simply specify the name. In order to go one level up, you need to put two dots before the back slash in the path.

Let’s add enumeration for indicators in the Enums.mqh file. For illustrative purposes, in this Expert Advisor we will use two standard indicators (Moving Average and Commodity Channel Index) and one custom indicator (MultiRange_PCH). The enumeration will be as follows:

Best Binary Options Brokers 2020:
  • Binarium

    The Best Binary Broker 2020!
    Perfect For Beginners!
    Free Trading Education!
    Free Demo Account!
    Get Your Sign-up Bonus Now!

  • Binomo

    Good Broker For Experienced Traders!

The external parameters are modified as follows:

As mentioned above, you will be able to select one out of the three indicators in the drop-down list of the Indicator parameter.

There is only one parameter applicable to all indicators where the indicator period can be set – IndicatorPeriod. The NumberOfBars parameter from the previous version of the Expert Advisor has been renamed to IndicatorSegments and now denotes the number of bars during which a given indicator must be going up/down to satisfy the position opening condition.

Further, we have added another external parameter, VolumeIncreaseStep, that can be used to set the step for volume increase in points.

The value of the AllowedNumberOfBars variable (now AllowedNumberOfSegments) used to be adjusted in the GetBarsData() custom function. It will now be placed into a separate function and only called at initialization.

Since the position opening condition will now be checked using indicator values, the value to be assigned will always be greater by two. In other words, if the IndicatorSegments external variable is assigned the value of 1, the AllowedNumberOfSegments variable will be assigned the value of 3, since in order to satisfy the condition (e.g. for a BUY), the indicator value on the completed bar must be greater than that on the previous bar. For this purpose, we need to get the last three indicator values.

Below is the CorrectInputParameters() function code:

Before we start dealing with the indicators, let’s create a function that will check whether trading is allowed – CheckTradingPermission(). If trading is not allowed for any of the reasons listed in the function, zero value will be returned. This will mean that the next try will have to be made on the next bar.

Let’s now get down to the main point of the article. To get access to values of the indicator, we need to first get its handle. This is done using special functions whose names are made of the short name of the indicator and the ‘i‘ symbol preceding it.

For example, the Moving Average indicator has the corresponding function iMA(). All standard indicator handles in the MetaTrader 5 terminal can be obtained using these functions. The full list is available in the MQL5 Reference section called Technical Indicators. If you need to get a handle of a custom indicator, use the iCustom() function.

We will implement the GetIndicatorHandle() function where depending on the indicator selected in the Indicator parameter the handle value of the corresponding indicator will be assigned to the indicator_handle global variable. The function code can be found in our library of trading signal functions (the \Include\TradeSignals.mqh file), while the variable with the indicator handle is located in the main file of the Expert Advisor.

Further, we create the GetDataIndicators() function where using the obtained indicator handles, we can get their values. This is done using the CopyBuffer() function in the way similar to getting bar values using the CopyTime (), CopyClose (), CopyOpen (), CopyHigh () and CopyLow () functions considered in the article called “MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester”.

Since the indicator can have several buffers (rows of values), the buffer index is passed to the CopyBuffer () function as the second parameter. Buffer indices for standard indicators can be found in MQL5 Reference. For custom indicators, buffer indices can be found in the code, provided the source code is available. If there is no code, you will need to find the index by way of experiment, by observing how conditions are satisfied in the visualization mode of the Strategy Tester.

Prior to that, we need to create dynamic arrays for indicator buffer values in the main file of the Expert Advisor:

The code of the GetIndicatorsData() is provided below:

The GetTradingSignal() function has substantially changed. The conditions are different in the absence of the position and where the position exists. For the Moving Average and CCI indicators, the conditions are the same. For MultiRange_PCH, they are arranged in a separate block. To make the code more readable and to avoid repetitions, we create an auxiliary function, GetSignal(), that returns a signal for position opening or reversal, provided that such position exists and the relevant action is allowed by the external parameter.

Below is the code of the GetSignal() function:

The GetTradingSignal() function code is now as follows:

Now, we only need to see into the Instant Execution and Market Execution modes that are part of symbol properties and to modify the code of the OpenPosition() position opening function accordingly. The modes whose names are self-explanatory can also be found in MQL5 Reference:

Please be reminded that when dealing with the Market Execution mode, you cannot open a position with the set Stop Loss and Take Profit levels: you need to first open a position and then modify it, by setting the levels.

Let’s add the execution mode to the structure of symbol properties:

Accordingly, we need to modify the ENUM_SYMBOL_PROPERTIES enumeration

and the GetSymbolProperties() function:

As a result, the OpenPosition() function code is now as follows:

We still have to add the final, very important touch to the event handling functions:

Now that all functions are ready, we can optimize the parameters. Keep in mind that you need to compile the code from the main program file.

Optimizing Parameters and Testing Expert Advisor

The Strategy Tester needs to be set as shown below:

Fig. 1. Strategy Tester settings.

Further, we set the parameters of the Expert Advisor for optimization (see also the attached *.set file with settings):

Fig. 2. Settings of the Expert Advisor.

The optimization took about 40 minutes on a dual-core processor. The optimization chart allows you to partly assess the quality of a trading system based on the results in the profit zone:

Fig. 3. Optimization chart.

Maximum recovery factor test results are as follows:

Fig. 4. Maximum recovery factor test results.


Attached to the article is the downloadable archive with the source codes of the Expert Advisor. Once it is extracted, you need to place the \TestIndicatorConditions file folder into \MQL5\Experts. To ensure the correct operation of the Expert Advisor, the MultiRange_PCH indicator should be downloaded and placed into \MQL5\Indicators.

How to Use the Relative Strength Indicator (RSI) for Day Trading

J. Welles Wilder is a giant in the field of technical analysis. In “New Concepts in Technical Trading Systems”, he introduced an array of trading indicators. Now, these indicators are among the most popular. And one of them is the Relative Strength Indicator (RSI).

The default RSI setting of 14 periods work well for swing traders. But many intraday traders find it lacking, because it produces infrequent trading signals.

Some traders deal with this problem by lowering their time-frame. Others lower the RSI period setting to get a more sensitive oscillator. However, these solutions produce RSI signals that are more unreliable.

Getting infrequent trades is not always a problem for day trading. That is if the few trading setups that show up are high-quality ones.

In this article, you will learn a simple method to find quality day trades.

The idea is to combine the default 14-period RSI with support/resistance zones. Our aim is to find intraday reversal setups with a high reward-to-risk ratio.

Trading Rules – Day Trading with the RSI

Long Day Trade

  1. 14-period RSI is below 30. (oversold)
  2. Price is testing a support zone.
  3. Buy above any bullish price bar.

Short Day Trade

  1. 14-period RSI is above 70. (overbought)
  2. Price is testing a resistance zone.
  3. Sell below any bearish price bar.

Examples – Day Trading with the RSI

(Trading sessions are separated by the black vertical lines.)

Winning Trade

This is a 10-minute chart of the popular day trading market, S&P 500 E-mini (ES).

  1. The congestion zone from the previous session projected a potential support zone.
  2. The RSI fell below 30, prompting us to look for potential trades.
  3. As the RSI became oversold, ES found support and printed a nice bullish inside bar. We went long a tick above it and caught the low of the trading session.

Losing Trade

The 5-minute time-frame is another common choice among day traders.

  1. This congestion area from two sessions ago acted as resistance in the last session.
  2. RSI rose above 70 and became overbought.
  3. This overbought signal formed as the market rose into the resistance zone. We shorted below the first bearish bar formed in the zone.

This trade did not turn out well. After some whipsaws, the market fell by a short distance. Then, it rose and broke the resistance zone for good.

In this case, the resistance zone held the market down for a period. However, the timing of this trade was not ideal.

As long as the trade risk is under control, take such losses in stride.

Review – Day Trading with the RSI

The key of this trading setup is your assessment of support and resistance zones. Take into account the market structure and focus on the higher quality trading setups.

This strategy is suitable for traders who do not want to eyeball the chart. You can mark up support and resistance zones before the start of a trading session. Then, set up alerts for RSI overbought/oversold signals. When your alerts sound off, take a closer look to assess the quality of the trading setups.

Day trading need not be an affair of rapid trades. By taking fewer trades, you have more time to analyze the larger picture. This is the merit of this RSI day trading strategy.

Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 2

    Donna Smith 3 years ago Views:

2 Important Notice: Wealthpire Inc. and Manny Backus are not registered investment advisers and do not provide individualized advice. You should consult your own professional advisers before making any financial or investment decision. These pages ARE NOT TO BE TREATED AS RECOMMENDATIONS OR TRADING ADVICE OF ANY KIND. Individuals attempting to “shadow” the real or paper trades documented here do so at their own risk. Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 2

3 Introduction: Technical analysis of stocks is both an art and a science. It is officially defined as an analysis method that uses past share prices and volume to forecast the direction of future prices. At first glance, technical analysis appears to be very complex with its own language, definitions, and methodologies. It can almost look like an ancient form of alchemy, super charged by software! While technical analysis certainly can become complicated by some of the more esoteric methods, at its core, it s very simple. This special report will explain technical analysis in easy to understand language so that you can immediately apply this forecasting methodology to improve your stock investing. After reading this quick report, you will have actionable knowledge of stock charts and several of the hottest momentum indicators to maximize your ROI. Chapter 1: The 3 Basic Principles Of Technical Analysis Principle One: History Repeats Itself Technical analysts believe that history repeats itself again and again in the stock market. This is why they look for patterns like the following: Head and Shoulders: Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 3

4 Double Bottom: Double Top Technical analysts believe that dozens of patterns such as these repeat time and time gain in the stock market. This means if you can identify one of these patterns forming, you can make a very good educated guess on where price is going to go next. This idea is based on the belief that investor behavior never changes. The unchanging buying and selling behavior is what forms the chart price patterns therefore by knowing the patterns high probability trades can be made. Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 4

5 Principle 2: Price Is All That Matters This really is the key concept behind all of tradition technical analysis. The belief is that all relevant information is already inherent in price and volume. All known and unknown fundamentals, news, and relevant economic information are already baked into the price/volume. Therefore, all one needs to do is study the charts themselves, as the other subjects do nothing but obscure the truth of price. Principle 3: Price Trends A price trend is a directional movement in prices across time. On the daily chart, two or more up days could be considered a trend. The same thing can be said for two or more down days on the daily chart. The specific definition of an uptrend is a series of higher highs and higher lows. Whereas, the definition of a downtrend is a series of lower highs and lower lows on the price chart. Identifying the next trend is the key to success as a technical analyst trader. Once a trend is identified, technical analysts believe that price will continue in the same direction long enough for profits. The holy grail of technical analysis is finding when trends will end and reverse. It is by trading at these reversal points that maximum profits can be extracted from the market. Chapter 2: The Basic Tools Of Technical Analysis 1. The Stock Chart The most basic tool of technical analysis is the price chart. A price chart is a sequence of prices plotted on a graph. The graph s horizontal axis represents time and the vertical axis represents price. Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 5

6 2. Price Plots Price can be represented on the stock chart as a continuous line. However, most technical analysts use price bars to represent a variety of time frames. For example, the high, low of each day can be turned into a vertical price bar to plot the day s price movement on the daily chart. Remember, a price bar can represent any time frame. The most popular are weekly, daily, hourly, 15 minute, 5 minute, 1 minute bars for time frames. This is what a typical price bar looks like: Price can also be illustrated as candlesticks on standard price charts and as X & 0 s on point and figure charts. Some traders believe that deeper insight can be derived from price by using these different ways of representing it. Here s what a candlestick and point & figure price plots look like: Candle Sticks Point & Figure There are pluses and minus to every way to plot prices on a stock chart. My suggestion is to use what you are most comfortable with. Just remember my number one rule when it comes to technical analysis and trading in general: SIMPLE IS BETTER Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 6

7 3. Technical Indicators I know technical indicators may sound complicated. While indicators can become complicated, the basic idea and basic use of indicators is extremely simple. Indicators are used to better understand and determine price trend, as well as, likely changes in price trend. The formal definition of a technical indicator is a series of data points that are derived by applying a mathematical formula to price data. In other words, indicators are the result of using math to crunch price data. Indicators are used in multiple ways by technical analysts. The two primary ways are to smooth price data to measure price momentum. Let s drill down into each of these types of indicators. Chapter 3: The Two Primary Types Of Indicators A. Price Smoothing Indicators These are the simplest and often the most powerful indicators. The simplest of these is called the Simple Moving Average or SMA. A Simple Moving Average calculates the average price of a stock over a specific number of periods. The most popular periods are 20, 50, and 200. These periods can be monthly, weekly, daily, hourly, 15 minutes, 5 minutes and 1 minute in duration. The longer the time period the more significant the SMA is thought to be. Institutions and big money players generally only focus on the 200 day SMA, making it the most important SMA time frame for investors to watch. The practical idea behind a moving average is that it smooth s data and makes it easier to define a trend. Here s an example of both the 50 and 200 day Simple Moving Average. You can see how a SMA filters out the noise and provides a clear view of what is happening with trend. Not to mention, provides technical support for the price trend. You will notice that price often bounces in the opposite direction once it hits a major SMA. Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 7

8 B. Leading Indicators While price smoothing indicators, such as Simple Moving Averages lag price, leading/momentum indicators are believed to lead price. In other words, the indicator signals price movements prior to their occurrence. First, let s cover a few definitions and then we will look at how to use leading/momentum indicators. Momentum measures the rate of change of a stock s price. The faster the price changes, the greater the price momentum. As momentum declines, price generally drops. The opposite is also true, increasing momentum usually goes hand in hand with rising prices. One of the most popular and my favorite momentum indicators is called the Relative Strength Index or RSI. Chapter 4: What Is The RSI and How To Use It The Relative Strength Index or RSI compares the average price change of the advancing periods with the average change of the falling periods. RSI is an oscillating indicator first popularized by Welles Wilder in his 1978 book, New Concepts In Technical Trading Systems. The standard time period used by most technical analysts is fourteen. The time frame is scaled on a chart from 0 to 100. Readings below 30 are believed to indicate an oversold condition; those above 70 are thought to indicate an overbought condition. Oversold reflects that the selling appears finished therefore the stock is near its lows thus ready to push higher. Overbought means the buying appears finished therefore the stock is ready to drop from its highs. Here s the basic formula to calculate RSI: This is how RSI looks on stock price chart. As you can see, when price pierced the upper line at 70, it soon started its decent. In addition, when price touched or pierced the lower line at 30, a bounce would occur soon thereafter. Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 8

9 Remember, the RSI and other momentum indicators do not work all the time. They work best when price is moving sideways within a channel. In strong uptrends and strong downtrends, the RSI can remain in oversold or overbought territory for long periods of time prior to the price trend changing. Some technical analysts like to change the number of periods used to calculate the RSI. I have seen various studies that indicate that two periods is the ideal number. Fortunately, it s easy to change the formula in most common technical analysis software programs. Chapter 5: Putting It All Together I use a variety of timeframes and indicators to scan the markets for potential buy or sell candidates. Once my technical analysis scan locates several companies, I then drill down into the fundamentals to see if the fundamentals support the bearish or bullish technical picture. If they do, I look to trade in the direction both the technicals and fundamentals are confirming. If there is divergence, I may avoid the stock all together or wait for further confirmation before I make a trading decision. Now you should have a basic working knowledge about what technical analysis is and how to use it help make trading decisions. Technical analysis can be turned into a very complicated topic. However, I have found over the last 25 years that the simple methods and tactics work the best in the stock market Technical Analysis Understanding Stock Charts and Momentum Indicators to Maximize Your Returns Wealthpire, Inc. 9

Best Binary Options Brokers 2020:
  • Binarium

    The Best Binary Broker 2020!
    Perfect For Beginners!
    Free Trading Education!
    Free Demo Account!
    Get Your Sign-up Bonus Now!

  • Binomo

    Good Broker For Experienced Traders!

Like this post? Please share to your friends:
How To Do Binary Options Trading?
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: