Back

Inside Bar Momentum Strategy from Babypips

Hi everyone, 

for the last few days, I tried to implement the inside bar momentum strategy (Babypips). However, I cannot make this strategy profitable. Since this is also my first time with Quantconnect, I am probably doing something wrong. 

The inside bar momentum strategy works as follows (and I am quoting the article here): 

“Long position

The first candlestick must be bullish (green or white) and if the second candlestick is completely contained by the first, set a buy stop order at the first candle’s high plus 10% of its range (high minus low).

Place the stop loss at the first candle’s high minus 20% of its range and set the target at the first candle’s high plus 80% of its range.

Short position

The first candlestick must be bearish (red or black) and if the second candlestick is completely contained by the first, set a sell stop order at the first candle’s low minus 10% of its range (high minus low).

Place the stop loss at the first candle’s low plus 20% of its range and set the target at the first candle’s low minus 80% of its range.

Additional rules

If another inside bar pattern forms, the current position should be closed or the pending buy/sell order must be canceled and entry orders must be updated to the latest candles. “

https://www.babypips.com/trading/forex-inside-bar-20170113

Attached you find my version. I would love to improve and make this strategy work. There is also an implementation on tradingview that is actually profitable, so I guess there is an error in my code. Would be cool if someone could help me out, thanks in advance! :) 

https://www.tradingview.com/script/Y2e6lEXw-Babypips-Inside-Bar-Momentum-Strategy/

 

Update Backtest








0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


 

Hey FoolishObserver,

I improved the efficiency of your code by removing the history calls in your OnData. History calls are, in general, expensive to make repeatedly. Instead of get the past OHLC data from the history call, we're getting the OHLC data from a RollingWindow which will save our past TradeBars.

I also changed the way you are indexing your dictionaries. It is good practice to use Symbols rather than tickers to key your dictionaries. You can learn more about this here.

You could also attempt to implement a SymbolData class which contains the information you are currently storing in dictionaries. You can find an example in this thread. However, I'll leave that up to you =).

 

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thank you Rahul for the help! The boost in performance is really awesome! :)  

I worked on this Project again today and realized some flaws in my implementation. I now use self.holdings[symbol] to keep track if my position is long or short. Also, I tried to implement some order cancelation, since the stop loss ticket should be canceled when the profit is taken and vice versa. 

However, I encountered really weird backtest behavior, almost no orders were filled. So I went back and just cloned your updated version of the algorithm and again got the same weird backtest behavior. Did something change in the Engine? It seems like all orders are filled on the last day only. Really weird since all I did was clone your backtest so the result should be the same!

0


Implementing technical strategies that focus on quotebar signals is very hard and i've yet to successfully do it. I"ve been on here for 1.5 years. I am curious to watch and see how this improves. 

1

Alright, backtesting wise everything is back to normal again. So I thing I implemented the stoploss takeprofit order cancellation. However, this strategy still performs super poorly. I don't know if I made a mistake somewhere, I hope somebody can point it out to me. 

0


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed