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?
Gurumeher Sawhney
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.
David Morris
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?
Gurumeher Sawhney
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.
Apollos Hill
Hi Gurumeher,
Should we set the holdings to a specific share quantity rather than allocating a percentage of portfolio using SetHoldings 1 or -1?
Gurumeher Sawhney
With respect to the example above, it would be hard to allocate a percentage of the portfolio using SetHoldings 1 or -1 because when a long or short signal is created, the allocation would then take over the entire portfolio, This overlapping would create a problem and the strategy would not work.
It would be easier to use a specific share quantity because then one could manage the short and long strategies separately, Code for risk management and portfolio construction would be recommended for this situation. When allocating the share quantity it would be useful to record the current positions for future trading signals.
David Morris
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!