# RSI Indicator with Martingale Position Sizing

The following article is a guest post from Jared Broad, CEO and Founder of QuantConnect. QuantConnect is an online browser-based back-testing platform for C# that allows you to test custom strategies over 15 years of historical intraday data. This article will be part of a new bi-monthly post by Jared with strategy examples for algorithmic trading.

Martingale is a bet sizing technique for increasing odds of winning at the expense of increased risk. The classic example is a coin flipping game where the gambler doubles his bet if he loses, in the hopes of making back any losses to break even. He will continue doubling his bet through subsequent losses until the bet breaks even. Once he returns to whole he continues betting with a unit bet. In theory with infinite capital and exactly 50-50 probability martingale can ensure the gambler will always return a profit.

Martingale position sizing is sometimes used in trading strategies without knowing its true risks. When implemented in reality traders have limited leverage, and the market win-loss probability fluctuates as losses can when the market is range-bound. It is a certainty that with a sufficient sample size eventually catastrophic loss does occur, it’s just a matter of when.

To demonstrate this we built a martingale position management algorithm, and backtest it on 15 years of data in QuantConnect to highlight the crashes.

[js] document.write(“[!– QUANTCONNECT.COM EMBEDDED BACKTESTS ([email protected]) –][div class=\”qc-embed-frame\” style=\”display: inline-block; position: relative; width: 98%; min-height: 100px; min-width: 300px;\”][div class=\”qc-embed-dummy\” style=\”padding-top: 56.25%;\”][/div][div class=\”qc-embed-element\” style=\”position: absolute; top: 0; bottom: 0; left: 0; right: 0;\”] [/div][/div]”);

To decide entry points we chose a the popular Relative Strength Index (RSI) indicator and shorted when it was over 70, signalling it was overbought. Conversely we entered the market long when it was less than 30, signalling oversold. Our entry and exit conditions were fairly arbitrary because we wanted to explore martingale position sizing more than RSI.

Once the algorithm was vested we monitor for a minimum profit gain, and on achieving the minimum profit-gain we exit the strategy locking in the profit.

In the event the algorithm reaches our maximum loss, we record the trade loss and double-invert the position as per martingale rules. The trade’s loss is now attached to a “loss-chain” parameter which serves as memory of this doubling-sequence. The minimum profit gain must also recoup the loss-chain before resetting to start again.

Our backtest result shows our implementation beating the absolute return of the SPY over a 15 year period, but it has greater volatility resulting in a lower Sharpe Ratio (0.4 vs 1.1 S&P). Interestingly it demonstrates the characteristic crashes of a martingale strategy, but since we have fixed leverage the crashes never rebound to form the perfect straight line.

There are many areas for experimentation to improve the strategy performance, such as using more intelligent entry and exit techniques, anti-martingale position sizing and adjusting our entry and loss targets based on market volatility. But I’ll leave that for you to explore! Originally posted by Jared Broad on QuantConnect.

This post originally appeared on the QuantConnect Blog. QuantConnect is a free online back-testing solution, seeking to democratize finance and make algorithmic trading accessibly to all investors.