How Does the Parabolic SAR work?

The Parabolic SAR (hereafter SAR)  is a trend indicator.   It was one of the indicators published by Welles Wilder in New Concepts in Technical Trading Systems.  It plots a dot above or below the price action to indicate the existence of a trend.  If the dot is plotted above the price, then a bearish trend is indicated.  A dot below the price action indicates a bullish trend.

The SAR indicates a trend reversal when the high/low move below the value of the dot plotted.  These trend changes are designed to detect reversals.    Hence the name, “Stop and Reverse.”     Here is an example:

Before we go deeper into the data, I will just state that this indicator performs poorly at various points on the backtest.  Perhaps that is all you may want to know.  If it is, then it still shows the importance of backtesting an idea before trading with it.  Sometimes the best information you can get from a backtest is <em>not</em> to use it.

Additionally, as I’ve said before, an indicator is not a stand alone system.  So, if people have some interesting ideas on using the SAR in other ways, then I will do my best to integrate some new ideas.

Now that we have a bit of an introduction to the SAR let’s see how it does on historical BTC prices.  We will start with a simple backtest that  assumes 1 BTC  per trade (no slippage and commissions) and merely enter when the SAR indicates a reversal long or short.  The backtest will run from 1/1/2012 until 7/1/2014.  The indicator gives 52 trades, a $472 net profit, a 59% peak-to-valley drawdown and a profit factor of 1.61.

One thing to point out is that all the losses came from the short side of the signals.   The long part of the strategy had a net profit of $564.00  and a drawdown of 46%.

We can contrast can see that this underperforms a buy/hold strategy.  A buy/hold strategy with 1 BTC has a profit of $670 and a peak-to-valley drawdown of 73%.

Much of this underperformance is due to whipsaws and early exits on long trends.  Each of these features is undesirable from the perspective of a trend following indicator.   Here is a replay of the results so you can get a feel for the SAR signals.

Here are some observations from the backtest:

1. The indicator has many whipsaws when prices are moving sideways.  This suggests that its usage in a system would benefit from a trend filter.  In fairness, Wilder suggested that it be used with the ADX to indicate trend following.

2. The indicator exits a trend early.  Generally, “letting your profits run” is the motto of trend following, so this is undesirable from that perspective.  (You can see from the backtest that the exit at $600 was far from the end of the trend).

3. Could it be used as a trailing stop (i.e., a stop that continually moves up to capture profit before the trend reverses)?  Perhaps, IMO there are better methods for finding a trailing stop for each particular strategy.

I will post the code below.  (Note: if you want to use it only to enter/exit long then just bracket (//) out the short signals)


Distinguishing a Strategy from an Indicator: A Lesson from the Turtles

The ” Turtle Traders” are a legendary group of traders taught by commodity trader Richard Dennis.   He and his partner had a debate about whether or not trading could be taught.  They conducted an experiment by placing an ad in the Wall Street Journal and giving a group of traders some accounts and a system.  The turtles ended up making more than $150 million.    Richard Dennis came up with the idea after visiting a turtle farm in Singapore and thought that traders could be “grown” like turtles.

The Turtle Trading System’s entry and exit parameters are quite simple.  They are based on the Donchian channel breakout indicator.  The Donchian channel merely measures the highest high and the lowest low in a series of bars.  For example, if you set the lookback to 10 bars, then the system will give you the highest high/lowest low in the last 10 bars.

The turtle trading system had two different entry systems that could be used. Each one based is based on the Donchian Channel breakout.  The one we’ll consider goes long/short at the highest high/lowest low of the last 20 days.   It exits when when there is a new high/low 10 bars ago.   Here is an example:

If we backtest the indicator, then we will get some information about how it performed historically on BTC prices.  This information can be valuable when thinking about designing a system.   However, my primary purpose in this post is to distinguish between an indicator and a strategy.

Let’s take the Turtle System which is given for fee by one of the former turtles:

Notice that there are at least six things that go into the complete strategy:

1. Markets – What to buy or sell

2. Position Sizing – How much to buy or sell

3. Entries – When to buy or sell

4.  Stops – When to get out of a losing position

5. Exits – When to get out of a winning position

6. Tactics – How to buy or sell

Its important to notice that the entry/exit is only a small part of the entire strategy.  I will illustrate by running two  backtests and compare this with buy/hold.

The first will be a backtest of the Donchian indicator itself as determined by the Turtle trading strategy.  The second will be a backtest that includes the position sizing parameters of the Turtle system.  Each backtest will assume an account of $10,000 with profits reinvested and trade from 1/1/2012 thru 6/1/2014.

Here are the results for trading the Donchian channel indicator itself.  (Note: all profits are reinvested every trade because there is no position sizing strategy.)  The results include a 22 trades- 50% profitable- a profit factor of 1- a drawdown of 98%- and a net profit of $3,482.

Here is a youtube playback of the system.  (You will notice the large drawdown occurs in April 2013).

As is obvious, buy/sell signals generated from the indicator severely underperformed buy/hold.    Buying $10,000 worth of Bitcoin would’ve netted you a nice profit of 1.38 mill.  As you can see below:

Now, let’s consider what happens when we include the position sizing algorithm that the Turtle’s used.  We will follow their rules of only entering 4 units per trade.  Where a unit is defined by (0.01 x AccountSize)/ Dollar per point x the Average True Range).  This position sizing algorithm leads them to enter less money when markets are volatile and more when they are not.   Here are the results using the same time period.

There were 22 trades-50% profitable-a profit factor of 5.27- a drawdown of 98% and a net profit of 3.61 mill.  See below:

I will also add the Youtube playback so you that you can see how the position sizing affected the trading.  Notice the awful trade that occurs in April 2013 doesn’t  destroy all the equity because the trade size is risk adjusted for larger volatility.


Here are some takeaways:

1. An indicator is not a system.  It should not be used as a complete system when trading.  It should not be evaluated as a complete system when backtesting.

2. An indicator that, by itself, underperforms buy/hold can outperform buy/hold when placed in a good strategy.

3.You can learn a lot from a Turtle.  Personally, the 34 pages providedis one of the most concise and helpful pieces on trading that I’ve read.

As always, the code is given below:

DonchianIndicatorBacktest TurtlePositionSizing

Trade Well and Prosper





The MACD: Does It Beat Buy and Hold?

The MACD is a fairly straightforward momentum indicator.  It consists of the difference between a 12 and 26 bar EMA.  The difference between these two moving averages is the MACD.  It is smoothed by a 9 Day EMA that is called the “signal line.”

The MACD  is usually plotted with a histogram that represents the difference between the MACD and the signal line.  The histogram can give either positive or negative values.  On the traditional interpretation, a buy signal occurs when the signal line crosses the MACD and a sell signal occurs when the signal line crosses below the MACD.   See the example below:

The MACD is a popular indicator on BTC forums.  How does it hold up historically? Does it beat  buy and hold?  How does a long and short strategy perform?  We will perform two backtests.  The first will be a MACD long only strategy.  The second will be a long and short MACD strategy.  Finally, we will compare this to buy and hold.

We will make the following assumptions: (1) The backtest will cover 1/’1/2012-6/1/2012.  (2) We will reinvest profits beginning with a $1,000 account.  (3) We will keep the default parameters for the MACD.

How does the long/short strategy perform?

The strategy entered 41 total trades – 59% were profitable- net profit was $9,820- there was a 98% a drawdown and a profit factor of 6.42.  See below

I am also attaching a youtube replay of each trade in the system to get a better feel for how the system would’ve worked.

You will notice that the system trades a different number of BTC depending on the account size.  Once it hit a large drawdown at the end of April 2013, then the system did not have the equity to trade larger quantities of BTC.

Now let’s backtest the long only system.

The strategy entered a total of 21 trades – 76.19% were profitable – net profit was $135,000,  there was a 19% drawdown and a profit factor of 60.41.

Here is the youtube replay.

Ultimately, MACD outperforms a buy/hold strategy as seen below.  The Buy/Hold had a net profit of $126,600 and a drawdown of 73%.  (For Buy/Hold I entered a buy at the open of everyday with the same amount of BTC 202 on each trade to make the performance equivalent. )

Here are a few takeaways:

1. Ultimately, MACD long only does beat buy and hold on both a net profit and drawdown.   It caught every major uptrend even though it lagged the market.

2. However, MACD long only underperformed buy and hold during the large price increases.  At one point, someone would’ve seen their BTC holdings drop from 202 to 58 due to price increases, lag and some losing trades.

3.  The drawdown  in USD on the MACD strategy is superior to buy/hold.  Returns should always be related to risk.  Someone trading the MACD would’ve had a $1,982 drawdown in USD, while the buy/hold drawdown equaled $159,000.

I am attaching the code below.



Better Know an Indicator: ADX

The ADX is one of the more complicated indicators in a trader’s arsenal.  Honestly, it looked like bad’s child’s crayon coloring the first time I saw it.   The reason why the ADX is complex is because it is a compilation of many indicators created by J. Welles Wilder in his book New Concepts in Technical Trading.  The book is worth the read because his ideas have been so influential on previous and contemporary traders.  (I also heard from an elf that it is easy to find a pdf of the book on google.)

I am going to give a basic overview of the indicator and its interpretation and then backtest these ideas on historical BTC data.   The ADX is designed to indicate changes in momentum and the direction and strength of a trend.   The indicator does this by first calculating the Directional Movement Index (DMI).

The DMI generally consists of the difference between two different values the DM+(blue or green) and the DM-(red).  The DM+ and DM- consist of the net difference between the most recent highs and lows.  Changes in momentum are generally detected when the DM+ crosses the DM- and vice versa.    Additionally, the direction of the trend is determined by whether or not the DM+ or DM- has a higher value.

The creation of the ADX is based on the DMI and various smoothing techniques.  This involves taking the difference between the absolute value of the DM+ and DM- and dividing it by the sum of the DM+ and DM-.  The calculation is somewhat complex and can be found in more detail at

The traditional interpretation of the indicator involves using the ADX line (green or blue) to indicate a trend.  When the ADX is below 20, then the markets are moving sideways.  If it is above 20, then the markets are trending.  Trading signals are determined when there is a crossover of the DM+ and DM-.   Here is an example:

Now that we have the basics of the ADX down let’s do some historical research. I am going to do two backtests using the default parameters for the ADX and a non-optimized position sizing strategy that trades approx 1,000 (or less) on each trade.  The position sizing strategy helps to focus on the performance of the indicator itself.  The downside is that it limits comparisons with buy/hold.  Since our focus here is the indicator research and not a fully developed strategy, then this is less of  a drawback.

I will create two separate strategies.  The first will be trade when the DM+ crosses above the DM- and use the ADX line above 20 as a filter (ADX Research).    The second will merely use the DMI without the ADX filter (DMI Research).  As usual, I will use NinjaTrader for the backtest and analysis.  I will post images of the results and provide links for the code.

Here is a summary of  the results of the ADX results:

Here is a summary of each trade

Here is short simulation of the strategy on Youtube to give you a picture of each trade.

Here is a summary of the DMI results

Here is a summary of each trade

Here is a short simulation on Youtube to give you a picture of each trade.

Here are some things to notice:

1. The ADX system does succeed at filtering out many whipsaw trades when the market is flat.  However, this increase in % profitable also comes with the cost of less total profit and a lower profit fact.

2. The total drawdown of each system is the same.  Importantly, the ADX filter does not decrease drawdown risk.  The ADX filter does not perform better on a return to risk basis.

3. One reason that the DMI indicator does well is because BTC prices trend and have low volatility when moving sideways.  If these features were to change, then the DMI indicator would do less well.   I am merely pointing out one of the many limitations that occur through backtesting.

Here is the code that can be imported directly into NinjaTrader

ADXResearch DMIResearch







Better Know an Indicator: Aroon

The Aroon indicator is a momentum indicator used to determine the beginning,  direction and strength of a trend.  It is popular in currency markets because, like bitcoin, they trend.  I thought we might see how the Aroon works and its application to Bitcoin markets.   The Aroon is different than most momentum oscillators because it is based primarily on time.

It measures the amount of time between the most recent highs and lows.  In a strong up trend there isn’t a lot of time elapsed between the last high.  In a downtrend there isn’t a lot of time elapsed from the recent low.  In a sideways market time has elapsed from both highs and lows.

The Aroon has two lines that measure the time elapsed since recent highs and lows.  For example, let’s say that the Aroon is set to 21 (a common setting).  This means that it will measure highs and lows of the last 21 bars.  When  the price hit a new 21 bar high, then the Aroon Up line will be at 100.  Conversely, if the the most recent low as yesterday, then the Aroon Down will be set at 100.   It is generally thought that a crossover of the Aroon Up above the Aroon Down is a buy signal and a cross of the Aroon Down above the Aroon Up is a sell signal.  Here is an example:


We can see that the Aroon gave a buy signal when BTC closed at $5.08 and closed at 9.54.  It also showed sideways price action when the Aroon Up and Aroon Down moved toward each other.

Now that we understand the basics of the Aroon it might help us better understand the indicator to see how it has fared historically.  My purpose in this backtest is to better understand the Aroon indicator and not to create a stand alone system.  So, I will make certain assumptions that would be slightly different than if I were creating a system.

Let’s assume that we are consistently trading approximately $1,000 and not reinvesting profits.  This assumption helps us to better see the Aroon work across various  Bitcoin prices for a few reasons.  First, the profits and losses from each trade are more equivalent.  Second, we get a better idea of how the Aroon profited from each trend.  Third, there are no optimized reinvestment parameters (its pretty easy to get a backtest yielding millions if you curve fit your position sizing strategy).

Here are the results from 1/1/2012 – 6/1/2014

The indicator yielded 18 trades with a net profit of $7,609- 61% profitable – 30% drawdown and 15.41 profit factor.

If you watch the quick market replay of these trades (about 2 min.) you may get a better picture of how the aroon would’ve actually worked in real time trading.

Here are some things that we’ve learn from this backtest

1. The aroon crossover does succeed in entering each major trend early and does not exit too early.   However, this often means exiting after giving back a good amount of profit.

2. The aroon crossover made most of its losses when there was a longer term down trend. Perhaps one might think of only using the aroon when longer term trend filters are in place.

3. The aroon is subject to various whipsaw trades when momentum spikes and then quickly moves sideways.

I am attaching the code below.

Trade Well and Prosper








**A few caveats these backtests are designed to better understand this indicator and not to be stand alone systems.   A much more complete backtest would be required to make a robust trading system.

Moving Average Crossover Systems

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”.

Let’s try three different moving average crossover strategies and see how they do.

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;

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, but it introduced more lag.

See below

Double Exponential Moving Average (DEMA) Cross0ver

Let’s see what happens when we introduce a more adaptive double exponential crossover.  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

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 decrease noise and lag.    In later posts, I can go over Kaufman and Mesa adaptive moving averages.  Each is included in the NinjaTrader suite.

If you want to test these systems yourself, then the code is below.  To import it into NinjaTrader just select File → Utilities →Import NinjaScript

SMACrossover EMACrossover DEMACrossover