EMA Bug

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

EMA Bug

Postby jefftrader » Fri Jul 16, 2010 2:54 am

Not sure if this is the correct place to post this, but there is a bug in the EMA indicator in Trade Station. If you set up an EMA with a period of 5 with the Close as the source and then set up another EMA with a period of 5 with the Open as the source the indicator plots one line rather than two. And just to make sure I wasn't crazy I created two EMAs with 10 as the period and used the Open as one source and the Close as the other source and it also just plots one line (by "plot one line" I mean both lines are exactly same and are laid directly on top of each other).

It works properly when using the High and the Low as the respective sources, but not when using the Open and the Close.

The same bug exists for the simple moving average (MVA).

Can this also be fixed?
jefftrader
 
Posts: 28
Joined: Tue Jul 13, 2010 4:13 pm

Re: EMA Bug

Postby Apprentice » Fri Jul 16, 2010 5:59 am

Inspired by your post I tested the code for these indicators.

Conclusion, there is no Bug.
Simply close one period, is a second period Open.
You could say, they are Redudant.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36476
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Bug

Postby Nikolay.Gekht » Fri Jul 16, 2010 10:18 am

Absolutely correct. You can easily check it by appling EMA on the source where open is not equal to close, for example to the result of Market Index indicator (viewtopic.php?f=17&t=611).
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: EMA Bug

Postby jefftrader » Sun Jul 18, 2010 10:13 am

I understand your explanation (that close of one period is the same as the open of the next period).

However, that would mean that the lines of the respective EMAs (or SMAs) should be shifted by one period and they are not. The only way your explanation could be correct is if the open and the close were the same for the SAME period.

I still believe there is a bug. Other trading platforms display the lines shifted by one period - which is the point of a moving average.

Please take a look again.
jefftrader
 
Posts: 28
Joined: Tue Jul 13, 2010 4:13 pm

Re: EMA Bug

Postby Apprentice » Sun Jul 18, 2010 1:25 pm

Truth MT4 has at least three different versions i know.
Question, how to determine which is the right one.

The logic of the current version has a meaning to me.
Close of one period, and second period Open is separated by only one second.

However, neither your position is not without basis.

Surely, I will rethink this interesting issue.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36476
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Bug

Postby jefftrader » Sun Jul 18, 2010 2:34 pm

Please don't take this personally, but it doesn't take a rocket scientist to run a simple moving average of the Open and then compare it to the simple moving average of the Close over some period of time with values taken from a chart.

So, that is what I did. I pulled up a 5 minute chart of GBP/JPY and added up the Open values for 10 periods and divided by 10 (thereby getting a simple moving average of 10 periods of the Open). I then did the same thing for the Close. The SMA(10) of the Open is 6.51 pips higher than the SMA(10) of the Close - which means duirng this 10 period sample price action was falling. You can double check my math if you would like, OR you can run your own simple test. The result you will find is that it is IMPOSSIBLE for the moving average of the Open to match the moving average of the Close.

Here are the values take from the 5 minute GBP/JPY chart from July 16th at 13:50 through 14:35 from DBFX Trade Station:

Open first:
133.653
133.543
133.361
133.303
133.303
133.228
133.323
133.268
133.205
133.193
Added up and divided by 10 = 133.338 (the SMA of the Open)

Now the Close for the same 10 periods:
133.543
133.361
133.303
133.303
133.208
133.323
133.268
133.205
133.093
133.122
Added up and divided by 10 = 133.2729 (the SMA of the Close)

the difference is: 133.338 - 133.2729 = 0.0651 === 6.51 pips

Please revisit this issue because I promise you charting the SMA/EMA of the Open and the Close as being the same value is absolutely incorrect. Do the math by hand yourself and you will see.......

thanks,

jefftrader
jefftrader
 
Posts: 28
Joined: Tue Jul 13, 2010 4:13 pm

Re: EMA Bug

Postby jefftrader » Sun Jul 18, 2010 2:42 pm

I just wanted to add one additional thing to your comment about the close and subsequent open being 1 second apart. While is true of a time line - it is completely irrelevant to charting due to price action that occurs DURING the period (1 min, 5 min, 1 hour, whatever). The only way an SMA/EMA can match is if the values are EXACTLY the same for the entire sample period.

i.e. 10 Opens of 133.653 would yield an SMA of (133.653 * 10) / 10 = 133.653

and 10 Closes of 133.653 would yield an SMA of (133.653 * 10) / 10 = 133.653

BUT, if you change ANY of the values throughout the 10 period sample the resulting SMA calculations will not (cannot) match.

thanks,

jefftrader
jefftrader
 
Posts: 28
Joined: Tue Jul 13, 2010 4:13 pm

Re: EMA Bug

Postby Nikolay.Gekht » Thu Jul 22, 2010 8:56 pm

One moment, which is probably is not take into cosideration.
The shift is not visible because the indicator applied on open price is drawn trough the left border of the candle and the indicator which applied to the close price is drawn trough the right border of the candle. The right border of the previous candle is close or touches (depending on zoom) to the left border of the next candle.

When I am back from vacation I'll write the indicator which is applied on bar and let you choose the price manually. In that case it will be drawn trough the center of the bar regardless to the price and you will see that open and close EMAs differs in fact. Please wait till monday and I will provide the detailed response, ok?
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: EMA Bug

Postby Nikolay.Gekht » Mon Jul 26, 2010 3:32 pm

Ok, I'm in the office back and can provide snapshots and demos.

First, you can download and install indicator TEST_MA I used to prepare this demo. This is a bar indicator which applied at the chosen price, so it uses, for example open price to calculate EMA but is always drawn trough the middle line of the bar because TEST_MA is a bar indicator and marketscope, in fact, does not know which particular price is used.
TEST_MA.lua
(2.92 KiB) Downloaded 740 times


The tick indicators (such as MA) are always drawn trough the price on which they are applied. So, EMA(open) will be drawn trough open prices and EMA(close) will be drawn trough close prices.

Compare the values, as I said the open MA just 1 bar forward comparing close MA.

mas2.png


If we zoom the chart with the indicator applied we can see that the open and close MA are shown as the same line, but MA applied to close price looks 1 bar longer. Because the the open price of this period touches the close price of the previous period and the MA(open) == MA(close)[-1 bar] - it is drawn as it is:

Just put TEST_MA as well on the chart and look that TEST_MA is drawn trough the center of the bar and values are the same (see the price scale), only location of the point inside the bar differs!

mas1.png


We can use the TEST_MA feature that it shows both, open and close MA drawn trough the center of the bar and see the following image (I think the exact image you expected):

mas4.png


However, no doubt we can see almost the same picture in case the source does not have open of the next bar equal to the close of the previous bar. Let's take as an example the "market index" indicator (viewtopic.php?f=17&t=611). Look, the open does not equal close, so, even the regular tick indicators are not equal as for FXCM's data.

mas5.png


I hope this helps. Please feel free to discuss this point. Probably we should think about drawing ANY indicator trough the center of the bar, like, for example metatrader does:
mas6.png

To tell truth, I think nobody knows when and why it was requested to draw the indicators trough the open and close part of the bar instead of the center of the bar, but if it is so confusing, it is probably the good time to make a change. :-)
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: EMA Bug

Postby jefftrader » Tue Aug 10, 2010 7:23 am

have been away and just saw your reply.

i will test this right away and let you know.....

thanks again for taking another look at it.
jefftrader
 
Posts: 28
Joined: Tue Jul 13, 2010 4:13 pm

Next

Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Bing [Bot] and 27 guests