Back

USO Hourly EMA Long Short

Testing a Long/Short strategy on USO intraday hourly. I think the code on flatten + short if long is off and am getting a 'insuficient funds' error. Any help would be much appreciated.
Update Backtest








Hey @Vats, it looks like MarketOnOpen orders are being generated at the last bar of the day. You'll see messages show up in the console stating the conversion (from market to market on open) took place. So at the time when SetHoldings(-1.0) was called, we computed a quantity of shares, but then the next morning the price moved enough to cause insufficient funds.

Personally I wouldn't recommend using SetHoldings(symbol, 1) since by defintion it's going to use all of your cash . It's nice to have a cash buffer in your account. If you change it to SetHoldings(symbol, .95) you'll get very similar backtest results without risking your last pennies.
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.


Thanks once again Michael, I'll change the logic
0

Hi Michael, Thanks for the suggestion. It seems to work now, I also thought I could do away with liquidate since the position is always in the market. See attached

One small issue cropped up now that used to work before - The plot of the SMAs and price stops at 2013. I must have changed something that I can't tell what.
0


We limit plots to 4,000 data points, any more and it can cause issues in the browser.
1

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.


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