Wednesday 23 October 2013

A New DSP Indicator in MT4

In this post, you will to understand how an MT4 indicator, specifically a Digital Signal Processing (DSP) indicator, is written and also how to interpret it on a chart.

Before I begin, let me digress a little bit. My DSP journey began in 1990s when I studied Computer Engineering at UNSW, Australia. For those not familiar with DSP, it is an engineering tool used to filter noise from signal and it has many practical uses in different industries. In 2011, when I started trading in the forex market, I purchased several books including a DSP trading book, titled "Cybernetic Analysis for Stocks and Futures" by John F. Ehlers. The book requires some familiarity with DSP from a practitioner's perspective, but I was lacking in DSP experience. I enrolled in the Coursera's "Digital Signal Processing" course, but I had to drop the course due to my personal commitments. For those interested, here is the course link.

The DSP indicator that I have written is based on a trading strategy from OneStepRemoved's "Cumulant Ratio" indicator. Although my DSP journey has taken a pause, I will read any interesting articles from a DSP practitioner's perspective.

Here is a snapshot of the USDZAR H1 chart with the CumulantRatio (CR) indicator below (Figure 1). I will explain to you the vertical red lines, which I have drawn on the chart after I explain how the maths work.

Figure 1: USDZAR H1 Chart


The maths is basically one equation:



where N is the period (or number of candles/bars), Xi is the individual price of each bar, Xo is the price of latest bar, and X_ is the average price of all the bars. The price may be the Open, High, Low or Close, in this case we use the Close price.

It is important to note that the numerator, which is a sum over the period N, divided by the denominator, which is also a sum over the period N, is the same result as when you divide the average of period N over the average of period N. I will explain why this is important later when we look at its implementation.

We implement the steps to the above math equation as follows:

(i) X_: this series is calculated using a simple moving average.

(ii) Xo: this series is calculated by using a step of the latest price every N period.

(iii) Numerator, i.e. Xo - Xi: this series is calculated by subtracting individual price of each bar from the second series.

(iv) Denominator, i.e. |Xi - X_|: this series is calculated by subtracting the first series from individual price of each bar.

(v) Equation, i.e. ratio: this series is calculated by dividing a simple moving average of third series by a simple moving average of the fourth series.

After mapping the math equation to the steps above, it is relatively straightforward to implement in MQL source code.

I will summarize the implementation in one paragraph, instead of explaining each step in detail. The simple moving average can be implemented using the iMA() function for prices, e.g. Close[], that are taken from a chart, or using the iMAOnArray() function for prices that are taken from a time series. The second step can be implemented using the MathMod() function and integer divisor (/) operator. The MathAbs() function can be used to calculate the absolute value in the fourth step. Unfortunately, in step five, MQL does not provide a sum on array function for time series, but we noted previously that we could use a simple moving average as the result is equivalent.

How to Interpret the Indicator on a Chart

The indicator has two user inputs:

(a) int CrPeriod: the number of bars to use for period N.

(b) int CrAlpha: a multiplier used to increase the range (enhanced visual and significance of the two lines, but it does not affect the histogram)

Figure 2: Custom Indicator Inputs


The indicator has two lines (green and silver) and one histogram (yellow):

(a) The green line represents the third series (Numerator), which can take any value from -infinity to infinity, but in practice, it has a limited range because it is a deviation from the latest price.

(b) The silver line represents the fourth series (Denominator), which can take any positive value from 0 to infinity, but it has a limited range because it is a deviation from the average price.

(c) The yellow histogram represents the fifth series (Equation), which can take any value from -infinity to infinity, and it has a much larger range than the two lines, because the Denominator is usually small, hence the ratio can be large.

Figure 3: CumulantRatio (CR) Indicator


In the next chart (Figure 4), I have marked three vertical red lines on the chart where the green line crosses the zero level. According to Shaun Overton, the green line
is only positive if the current price is “above” the sum of the last N bars. A negative position means that the current price is “below”.
(i) The first cross up showed a relatively weak up move, but you will note that the prices moved up strongly afterwards.

(ii) The second cross down showed a stronger down move, and the prices followed down strongly two bars later.

(iii) The third cross up weakly, and this is followed by the prices moving up strongly.

Figure 4: The green line crossing zero has preceded every big price move


At this preliminary stage, I do not yet fully understand how the indicator behaves and how to use it in trading. I will continue to monitor the relationship between the CR indicator and the prices. I think that you could use some additional filters before using it for trading, so as to prevent false signals.

Download Indicator

Please read the disclaimer first before downloading the source code or indicator.

You understand and agree to the following terms and conditions for use:
(a) you do not remove any of the copyright information from the source code, or attempt to commercialize the source code or indicator.
(b) you are allowed to modify the source code, but you do not attempt to commercialize any variation of the source code or indicator.
(c) I am not liable for any damages or losses as a result of you using the indicator or any variation of the indicator for any purposes.


The indicator can be downloaded here.

4 comments:

  1. Hey Everybody,

    "Which Forex pair and time frame is best to trade" is the frequently asked question and I want do give you the EXACT ANSWER in this comment.

    Are you expecting that I am going to say something like EUR/USD on 15-minute time frame or GBP/USD on daily...? No, it is not so simple, but SIMPLE ENOUGH we can figure it out!

    The "PROBLEM" is that markets change over time. If EUR/USD was a well trending currency pair a few years ago, today it is another one.

    I actually want to let you know about a SPECIAL TOOL that I use to find the BEST TRENDING PAIRS among all the Forex pairs.

    CHECK IT OUT: ForexTrendy

    The software inspects 34 Forex pairs on all time frames from minute to monthly. This way you pick the best trending pair and time frame at the current time.

    CHECK IT OUT: ForexTrendy

    ReplyDelete
  2. Hello Everybody,

    I've included a list of the most recommended FOREX brokers:
    1. #1 Forex Broker
    2. eToro - $50 minimum deposit.

    Here is a list of top forex instruments:
    1. ForexTrendy - Recommended Odds Software.
    2. EA Builder - Custom Indicators Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    I hope you find these lists helpful...

    ReplyDelete
  3. GPS robot [10X increase of the deposit balance]

    I just completed a webinar with Mark and his partner, Antony, two days ago and it was AWESOME.

    During the webinar Mark and Antony shared their stories to success and answered questions about their new release of the GPS Forex Robot that CAME OUT TODAY!

    ReplyDelete
  4. Your Affiliate Profit Machine is waiting -

    Plus, making profit with it is as easy as 1, 2, 3!

    Here are the steps to make it work...

    STEP 1. Input into the system which affiliate products you want to push
    STEP 2. Add some push button traffic (it LITERALLY takes 2 minutes)
    STEP 3. Watch the affiliate system grow your list and sell your affiliate products on it's own!

    Are you ready to start making money??

    You can test-drive the system for yourself risk free...

    ReplyDelete