Back

Help with bollinger band strategy

I am trying to create a strategy based on bollinger bands, but something must be wrong as only 1 trade is being made over a year which doesn't make sense as mutliple trades should be made each day...

The concept is:

The system should only trade between 10 pm and 8 am UTC, and a trade should only be made if there are no other open positions.

If the closing price of the EURUSD is above or equal to the Upper Bollinger band, then Sell. The trade should be closed when the price hits the lower bollinger band or it should be stopped out if the price hits the Stop (Which is set as the upper bollinger band at 6 std dev)

And if the closing price of the EURUSD is below or equal to the Lower Bollinger band, then Buy. The trade should be closed when the price hits the Upper bollinger band or it should be stopped out if the price hits the Stop (Which is set as the lower bollinger band at 6 std dev)

 

I can't figure out what is wrong in my code as only 1 trade is being made over a year period. Anyone can help?

Update Backtest








The statements are correct we just needed to change the layout of the conditional statements. It checked if it was not invested, but if it was the rest of the logic was skipped. Also the long and short strategies were conflicting by having them right after each other so for the sake of simplicity I commented out the long strategy.

0


Excellent! Thank you for this! 

For the buy strategy would you suggest I create a separate algorithm? or is there a way to have them not conflicting?

0

Having a buy and sell strategy in the same algorithm depends on the portfolio structure. It is possible to have them in the same algorithm, but then holdings shouldn't be set to 1 or -1, since it affects the entire portfolio.

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