Bitcoin Forum
November 18, 2017, 10:40:25 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1] 2 »  All
  Print  
Author Topic: Much Ado About Moving Averages  (Read 2637 times)
let_me_backtest_that
Jr. Member
*
Offline Offline

Activity: 32


View Profile
June 09, 2014, 03:55:37 PM
 #1

Moving average crossovers are one of the most well known strategies. Unfortunately, they have the reputation of being great in theory, but bad in practice. There are two problems with most moving average crossover signals. First, they present a signal too late. Traders refer to this as "lag." Second, they give too many false signals that lead to quickly entering and exiting a market (or whipsaws). Traders refer to this as "noise".

If we backtest three different moving average crossover strategies we can see the ways that lag/noise affects trading and how to decrease it. We will do this by backtesting three different moving average crossover systems and posting the results. (All backtests run from 1/1/2012-1/1/2014 and assume 1BTC is traded w/ no commissions)

Simple Moving Average (SMA) Crossover

If you were to backtest the most profitable daily simple moving average crossover (16/22). You would get a net profit of $881 with a 71% winning percentage, but a 17% drawdown. The strategy was profitable, but had quite a few whipsaws. See below;

http://i.imgur.com/9nxRW7G.png

Exponential Moving Average (EMA) Crossovers

If you were to backtest the most profitable exponential daily moving average crossover (24/41). You would get a net profit of $755 with a 75% winning percentage and only a 5% drawdown. In other words, the longer EMA actually reduced the whipsaws and drawdown, but decreased net profit by increasing lag.

See below

http://i.imgur.com/9E5yTJV.png

Double Exponential Moving Average (DEMA) Cross0ver

Let's see what happens when we introduce a more adaptive moving average crossover, the DEMA. The backtested results for the most profitable combination of the DEMA crossover (18/33). You would get 8 trades with a net profit of $937 with 87.50% of winning trades and only an 8% drawdown.

see below

http://i.imgur.com/sWLfPqy.png

Here is what we learn from this research. Double Exponential Moving Averages introduce less noise and lag because they are more adaptive. More adaptive moving averages increase net profit and decrease drawdowns.  There have been several attempts to make moving averages more adaptive I can post on them later as well.

Each of the backtests were done through NinjaTrader. You can download NinjaTrader for free. Also, we have configured BTC historical data that is constantly updated for NinjaTrader. The link is below

http://www.signalstrengthfinance.com/bitconnector-bitcoin-trading-on-ninjatrader/
1511001625
Hero Member
*
Offline Offline

Posts: 1511001625

View Profile Personal Message (Offline)

Ignore
1511001625
Reply with quote  #2

1511001625
Report to moderator
1511001625
Hero Member
*
Offline Offline

Posts: 1511001625

View Profile Personal Message (Offline)

Ignore
1511001625
Reply with quote  #2

1511001625
Report to moderator
1511001625
Hero Member
*
Offline Offline

Posts: 1511001625

View Profile Personal Message (Offline)

Ignore
1511001625
Reply with quote  #2

1511001625
Report to moderator
A blockchain platform for effective freelancing
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
the_sunship
Full Member
***
Offline Offline

Activity: 230


View Profile
June 09, 2014, 04:58:22 PM
 #2

Many thanks for this, very appreciated!

😀
oda.krell
Legendary
*
Offline Offline

Activity: 1386



View Profile
June 09, 2014, 07:10:50 PM
 #3

Much appreciated, OP.

Never tried NinjaTrader, but will give it a shot. Also, what are the advantages of signing up for BitConnector for someone who doesn't use fully automated trading? Care for a sales pitch, I'm actually interested Smiley

Two short remarks about the DEMA results:

One, the resulting trades in the 2013/2014 bear market are extremely "unintuitive". Example: You would have had to sit out (all fiat potentially) the entire dead cat bounce to ~1000. It's certainly possibly if you really, really trust your momentum signal, but, boy, I would have been nervous during that period.

Two, I don't agree that the DEMA beats the other options straight and obvious. The optimal parameters you gave for the DEMA are, imo, almost certainly overfitted. The initial post-ATH SELL signal lands *perfectly* on the first rebound. I can't say exactly how much your profit comes from that instance, but it's probably a good chunk. This is almost certainly a lucky hit, and won't be reproducible.

What I'm trying to say is: DEMA might still be the preferably choice for average crossover strategies, but at least the DEMA parameters you mention look like they owe a good deal of their profit to one lucky trade after the bubble popped.

DEMA chart:


Not sure which Bitcoin wallet to use? I suggest to take a look at Electrum.
Electrum is an open-source lightweight client: user friendly, fast, and one of the safest ways to store, send or receive bitcoins.
For executables (Windows, OSX, Linux, Android), source code and documentation, see the Electrum homepage.
let_me_backtest_that
Jr. Member
*
Offline Offline

Activity: 32


View Profile
June 09, 2014, 08:07:36 PM
 #4

Thanks for the questions and response!

I'll make the sales pitch short and sweet:  For someone who doesn't use fully automated systems bitconnector allows you have multiple real time charts open with saved charting parameters, 100s of built in indicators, real time alerts via email when trading conditions are met and increased order functionality like stoploss orders.  

About DEMA:

1. Yes, it would've been hard sit through the dead cat bounce to 1000.  Systematic trading takes the same kind of discipline as discretionary trading to be successful.  A mere backtest wouldn't give you that confidence.  There would have to be in and out of sample tests, testing on unseen data, monte carlo simulations etc.

2.  I will agree that for other methods such as filtering, trend identification and retracement trades, the DEMA may not be the best.  Also, the exact combination for each of the crossovers is surely curve fitted.  I merely chose the most profitable for comparison purposes.  I did find the same results when researching profit factor and % profitable.   Below are the top 20 optimized results that were not included in the original backtest (Jan -June 2014).  

SMA
http://i.imgur.com/kz3qEI1.png

EMA
http://i.imgur.com/unhdXp6.png

DEMA
http://i.imgur.com/e7YfrCF.png


 
bitcoinsrus
Hero Member
*****
Offline Offline

Activity: 546



View Profile
June 09, 2014, 08:23:02 PM
 #5

can anyone give me a dumb down explanation of all this (for noobs like me) greatly appreciated.
let_me_backtest_that
Jr. Member
*
Offline Offline

Activity: 32


View Profile
June 09, 2014, 10:50:39 PM
 #6

I can give a quick overview of moving averages.  A simple moving average merely takes the average price over the last x number of periods.  So, a 5 day moving average will give the average price over the last five days.  An exponential and double exponential moving average weights the most recent prices more heavily.

 This is usually put on a chart in the form of a line.  A moving average crossover is thought to be a buy/sell signal to indicate changes in momentum.   So if the 5 day moving average crosses a 25 day moving average it indicates the prices have moved up.  People use different periods of moving averages to try to better indicate profitable signals. 

hope that helps.
bitcoinsrus
Hero Member
*****
Offline Offline

Activity: 546



View Profile
June 10, 2014, 01:13:26 AM
 #7

I can give a quick overview of moving averages.  A simple moving average merely takes the average price over the last x number of periods.  So, a 5 day moving average will give the average price over the last five days.  An exponential and double exponential moving average weights the most recent prices more heavily.

 This is usually put on a chart in the form of a line.  A moving average crossover is thought to be a buy/sell signal to indicate changes in momentum.   So if the 5 day moving average crosses a 25 day moving average it indicates the prices have moved up.  People use different periods of moving averages to try to better indicate profitable signals. 

hope that helps.

Thanks for clearing that up, it makes more sense to me.
oda.krell
Legendary
*
Offline Offline

Activity: 1386



View Profile
June 10, 2014, 09:37:39 AM
 #8

I can give a quick overview of moving averages.  A simple moving average merely takes the average price over the last x number of periods.  So, a 5 day moving average will give the average price over the last five days.  An exponential and double exponential moving average weights the most recent prices more heavily.

 This is usually put on a chart in the form of a line.  A moving average crossover is thought to be a buy/sell signal to indicate changes in momentum.   So if the 5 day moving average crosses a 25 day moving average it indicates the prices have moved up.  People use different periods of moving averages to try to better indicate profitable signals.  

hope that helps.

Thanks for clearing that up, it makes more sense to me.

Maybe one addition: Head over to Goomboo's thread if you're intersted, he's doing a very understandable introduction to average based systematic momentum trading.

You need to understand one thing though (that took me a while to really get my head around last year when I started trading): there's a tradeoff... "momentum methods", like trading based on signals from different moving averages gives you the ability to backtest your method and parameters (what let_me_backtest_that suggested in his first post). That's a huge plus. On the other hand, momentum trading means, by definition, that you "follow" the market. You will sometimes miss the early part of a huge swing because your signal isn't there yet. You will sometimes enter a trade that will end in a slight loss, because your averages whipsawed (that means: they crossed over, but then the trend never really formed, and the cross over again in the opposite direction)

Where I'm getting at: average crossover methods are a great starting place for a trader, in my opinion, if for no other reason than that they really invite rigor and planning, as opposed to "intuitive" trading which usually ends in tears. On the other hand, not everyone is comfortable with mainly "reactive" trading, which trading with averages is in the end, so you need figure out what trading style works best for you.

Not sure which Bitcoin wallet to use? I suggest to take a look at Electrum.
Electrum is an open-source lightweight client: user friendly, fast, and one of the safest ways to store, send or receive bitcoins.
For executables (Windows, OSX, Linux, Android), source code and documentation, see the Electrum homepage.
Bit_Happy
Legendary
*
Offline Offline

Activity: 1638


A Great Time to Start Something!


View Profile
June 10, 2014, 04:13:14 PM
 #9

can anyone give me a dumb down explanation of all this (for noobs like me) greatly appreciated.

Here is a simple run-down in my own words:
TA (Technical analysis) is a useful set of tools, but not always accurate.
Moving Averages have severe issues for traders who count on them heavily.

At/near the recent lows (~$400/BTC) the moving average Bears where extremely confident they should not buy, and that was clearly the wrong "signal". By the time key moving averages give a clear signal you probably missed a large part of the move, and/or certainly didn't get the best prices.

tuneman1980
Full Member
***
Offline Offline

Activity: 228



View Profile WWW
June 10, 2014, 04:17:15 PM
 #10

Here's a great page to track moving averages of many coins: http://www.cryptocoinstats.com/priceaverage.php

http://cryptocoinstats.com/

BTC: 19YQqtEdtuWhT6nk6ArBgMTiKMEjoJ5eww  LTC: Li1RLpZm8Rx7txSnQdvZvtLMsd4XDN2vMJ  FTC: 6qAU4vtyf9LPW4yV4m4Vx1jm4ZkXJHTFP7
oda.krell
Legendary
*
Offline Offline

Activity: 1386



View Profile
June 10, 2014, 04:27:45 PM
 #11

can anyone give me a dumb down explanation of all this (for noobs like me) greatly appreciated.

Here is a simple run-down in my own words:
TA (Technical analysis) is a useful set of tools, but not always accurate.
Moving Averages have severe issues for traders who count on them heavily.

At/near the recent lows (~$400/BTC) the moving average Bears where extremely confident they should not buy, and that was clearly the wrong "signal". By the time key moving averages give a clear signal you probably missed a large part of the move, and/or certainly didn't get the best prices.


That one swings both ways:

"At/near the $1200 ATH, the moving average avoiding bulls were extremely confident that the rally would continue forever, and didn't sell in time."


The daily DEMA 33/18 suggested by OP gave a buy signal ~520 on April 15, holding since then. That's not exactly perfectly catching the bottom, but far from shabby considering that we're now more than $100 higher.

Not sure which Bitcoin wallet to use? I suggest to take a look at Electrum.
Electrum is an open-source lightweight client: user friendly, fast, and one of the safest ways to store, send or receive bitcoins.
For executables (Windows, OSX, Linux, Android), source code and documentation, see the Electrum homepage.
JustAnotherSheep
Full Member
***
Offline Offline

Activity: 239



View Profile
June 10, 2014, 04:54:38 PM
 #12

That one swings both ways:

"At/near the $1200 ATH, the moving average avoiding bulls were extremely confident that the rally would continue forever, and didn't sell in time."


The daily DEMA 33/18 suggested by OP gave a buy signal ~520 on April 15, holding since then. That's not exactly perfectly catching the bottom, but far from shabby considering that we're now more than $100 higher.
Furthermore, I imagine Moving Average-based trading can be made far more accurate by using clever combinations of different MA crossings, as well as MACD and price-MA crossings, to get earlier signals and confirmations (very important for twitchy exponential moving averages which can sometimes give false signals). For example, price crossing daily SMA50 on May 20th in addition to the DEMA crossing would've served as stronger buy confirmation and allowed one to buy at 460-ish, at the same time of the bear trendline breakout, and the decision (to hold) would've been further reinforced by daily MACD shooting up.

Of course as you say it's still largely reactive trading and personally I prefer other methods to (primarily) base my decisions on. But MA-strategies/momentum trading have the advantage of being fairly easy and straight-forward (and also easily automated for the more lazy traders Smiley ).

Is it a bull? Is it a bear? No, it's just another sheep.
let_me_backtest_that
Jr. Member
*
Offline Offline

Activity: 32


View Profile
June 11, 2014, 04:31:01 AM
 #13

That one swings both ways:

"At/near the $1200 ATH, the moving average avoiding bulls were extremely confident that the rally would continue forever, and didn't sell in time."


The daily DEMA 33/18 suggested by OP gave a buy signal ~520 on April 15, holding since then. That's not exactly perfectly catching the bottom, but far from shabby considering that we're now more than $100 higher.
Furthermore, I imagine Moving Average-based trading can be made far more accurate by using clever combinations of different MA crossings, as well as MACD and price-MA crossings, to get earlier signals and confirmations (very important for twitchy exponential moving averages which can sometimes give false signals). For example, price crossing daily SMA50 on May 20th in addition to the DEMA crossing would've served as stronger buy confirmation and allowed one to buy at 460-ish, at the same time of the bear trendline breakout, and the decision (to hold) would've been further reinforced by daily MACD shooting up.

Of course as you say it's still largely reactive trading and personally I prefer other methods to (primarily) base my decisions on. But MA-strategies/momentum trading have the advantage of being fairly easy and straight-forward (and also easily automated for the more lazy traders Smiley ).


I added a filter of the 50 day SMA. It eliminated 1 trade that resulted in a $99 loss.  However, it also introduced lag on trade entries.  I did not add a MACD, however, by itself it beat the DEMA with the 50 day SMA.  In any case,  increasing filters (i.e., adding prices above x MA and other indicators) lowers the chances that the results in the past will be representative in the future.

I'm not trying to rain on anyone's parade.  if you have a strategy that is working and it fits your style, then by all means make money.  As far as backtesting goes, it is important to keep in mind that there are no free lunches and that adding additional filters can have costs.
falllling
Member
**
Offline Offline

Activity: 112


View Profile
June 11, 2014, 04:39:56 AM
 #14

$637 is broken, $600 is coming
JustAnotherSheep
Full Member
***
Offline Offline

Activity: 239



View Profile
June 11, 2014, 05:40:17 AM
 #15

I added a filter of the 50 day SMA. It eliminated 1 trade that resulted in a $99 loss.  However, it also introduced lag on trade entries.  I did not add a MACD, however, by itself it beat the DEMA with the 50 day SMA.  In any case,  increasing filters (i.e., adding prices above x MA and other indicators) lowers the chances that the results in the past will be representative in the future.

I'm not trying to rain on anyone's parade.  if you have a strategy that is working and it fits your style, then by all means make money.  As far as backtesting goes, it is important to keep in mind that there are no free lunches and that adding additional filters can have costs.
Out of curiosity, could you backtest a combination strategy, giving buy and sell signals both at SMA10/7, DEMA33/18 and MACD 21, 28 crossings?

Is it a bull? Is it a bear? No, it's just another sheep.
YipYip
Hero Member
*****
Offline Offline

Activity: 574



View Profile
June 11, 2014, 08:19:17 AM
 #16

STill waiting on access to to your BETA ninja add-on Huh

EDIT: ...lolz should have checked email b4 posting  Cheesy

OBJECT NOT FOUND
let_me_backtest_that
Jr. Member
*
Offline Offline

Activity: 32


View Profile
June 11, 2014, 02:05:02 PM
 #17

I added a filter of the 50 day SMA. It eliminated 1 trade that resulted in a $99 loss.  However, it also introduced lag on trade entries.  I did not add a MACD, however, by itself it beat the DEMA with the 50 day SMA.  In any case,  increasing filters (i.e., adding prices above x MA and other indicators) lowers the chances that the results in the past will be representative in the future.

I'm not trying to rain on anyone's parade.  if you have a strategy that is working and it fits your style, then by all means make money.  As far as backtesting goes, it is important to keep in mind that there are no free lunches and that adding additional filters can have costs.
Out of curiosity, could you backtest a combination strategy, giving buy and sell signals both at SMA10/7, DEMA33/18 and MACD 21, 28 crossings?

I am interested enough to see how this turns out I'll call it "The Follow Sheep" strategy and i'll give you the code if you want it.  To be clear, do you want all of these conditions met on every entry/exit or do you want to enter/exit if any one of the conditions is met independently of the others?
JustAnotherSheep
Full Member
***
Offline Offline

Activity: 239



View Profile
June 11, 2014, 03:10:44 PM
 #18

Out of curiosity, could you backtest a combination strategy, giving buy and sell signals both at SMA10/7, DEMA33/18 and MACD 21, 28 crossings?

I am interested enough to see how this turns out I'll call it "The Follow Sheep" strategy and i'll give you the code if you want it.  To be clear, do you want all of these conditions met on every entry/exit or do you want to enter/exit if any one of the conditions is met independently of the others?
Heh, excellent name! Grin I'd greatly appreciate the code if it turns out to be profitable. Actually, I'd greatly appreciate the code regardless, as then I could have a look at it to get a basic gist of whatever scripting/programming language you use, download BitConnector and start playing around with different strategies myself.

Enter/Exit if any one of those conditions are met independently. I looked at charts and noticed that sometimes MACD gave better timed buy and sell signals, and sometimes the moving averages, and so got the gut feeling that a combination would get me the best of both worlds Smiley

Is it a bull? Is it a bear? No, it's just another sheep.
oda.krell
Legendary
*
Offline Offline

Activity: 1386



View Profile
June 11, 2014, 03:27:34 PM
 #19

Forgot to ask in the first place, but what's the cost per trade during the backtest?

Given even moderate volume, slippage+fees (mainly slippage, though) easily reach 4% per trade pair. Once that is taken into account, I suspect any strategy that just cranks out one trade after another won't be profitable compared to one with less frequent trades.

That said, I'd still like to see the follow_sheep results Cheesy

Not sure which Bitcoin wallet to use? I suggest to take a look at Electrum.
Electrum is an open-source lightweight client: user friendly, fast, and one of the safest ways to store, send or receive bitcoins.
For executables (Windows, OSX, Linux, Android), source code and documentation, see the Electrum homepage.
let_me_backtest_that
Jr. Member
*
Offline Offline

Activity: 32


View Profile
June 11, 2014, 04:56:25 PM
 #20

Out of curiosity, could you backtest a combination strategy, giving buy and sell signals both at SMA10/7, DEMA33/18 and MACD 21, 28 crossings?

I am interested enough to see how this turns out I'll call it "The Follow Sheep" strategy and i'll give you the code if you want it.  To be clear, do you want all of these conditions met on every entry/exit or do you want to enter/exit if any one of the conditions is met independently of the others?
Heh, excellent name! Grin I'd greatly appreciate the code if it turns out to be profitable. Actually, I'd greatly appreciate the code regardless, as then I could have a look at it to get a basic gist of whatever scripting/programming language you use, download BitConnector and start playing around with different strategies myself.

Enter/Exit if any one of those conditions are met independently. I looked at charts and noticed that sometimes MACD gave better timed buy and sell signals, and sometimes the moving averages, and so got the gut feeling that a combination would get me the best of both worlds Smiley

I backtested from 1/1/2012-6/1/2014.  Here is what we get: net profit $805, 46 trades, 60% profitable, 23% drawdown and a profit factor of 3.25. It looks like the short SMA values caused most of your losses through whipsaw trades. You can see the results on the link below:

http://i.imgur.com/FFCEU5N.png

When you email us for bitconnector, then reference this forum post and I'll also send you the strategy code.  In NinjaTrader the backtesting allows you to easily change all the variables when backtesting, so I made all the lookbacks into variables.

Also, oda.krell is right about including slippage and commissions to make results the most realistic.  I didn't include them, but various levels of slippage/commission can be added as well as order quantity can be changed.
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!