Trend

Trend both ways (EMA 20/100)

An example of a strategy with shorts. If shorts are off in the settings, a short signal simply closes the long position, and the rule becomes an ordinary trend rule.

Rules

  • Fast: a 20-candle exponential average; slow: a 100-candle one.
  • Fast above slow: long.
  • Fast below slow: short (if allowed) or exit the long.

In the test, a short pays nothing for borrowing the shares or financing the position. In real life these are costs, and on crypto there is also the futures funding rate.

Code for the lab

fast = input(20, 5, 50, 5)
slow = input(100, 50, 200, 10)
f = ema(close, fast)
s = ema(close, slow)
plot f, s
buy when f > s
short when f < s

You can change the code right in the lab: the numbers in input(…) become sliders.

Results on eight markets

MarketCAGRDrawdownTradesBuy and hold: CAGRBuy and hold: drawdown
MOEX Russia Index—————
Sberbank—————
Gazprom—————
Gold, $ per ounce—————
Brent crude, $ per barrel—————
Bitcoin—————
Ether—————
VN-Index—————

The numbers are calculated in your browser from fresh source candles.

Default parameters, daily candles, a fee and slippage of 0.05% each per trade, no return on cash out of the market, prices without dividends. The test starts once all of the rule’s indicators are calculated.

What research says

A short on a market that has grown for decades works against that growth. In our table, the rule with shorts loses to buy and hold more often, but it sometimes saves the day in long declines.

When the rule breaks

  • A long rise with pullbacks: a short on every pullback.
  • A short without a stop can lose more than the money put in: the price can rise without limit.
  • High costs of shorting eat the edge.