Hey all!

Here's an algorithm I threw together to try and showcase various features and techniques available within QuantConnect. This algorithm tries to detect an opening breakout in the direction of the short term trend and takes a position in that direction. The opening breakout is nominally defined as trading outside of the range established in the first 3 minutes of trading. Orders are always submitted with accompanying stop market orders which are gradually tightened using PSAR after some initial profit condition is met.

I've tried to keep it fairly simple but still provide a good framework. As an algorithm grows in complexity, it's typically beneficial to split the pieces out into stand-alone components that can be reused between algorithms, but for the sake of simplicity and understandability, I've left all the code in one file.

In this algorithm you'll see various features and techniques including:

* Scheduled Daily Events

* History function to warm up indicators manually

* StopMarket order updates

* Dynamic position sizing using ATR/allowable losses

* Custom indicator on custom (30 min) interval

* Custom leverage settings

* Decent logging functionality

* Plotting considerations made for backtest and live

There's still plenty of work to be done here before it is made into a good, reliably profitable algorithm. Some things that could be worked on is:

* Setting the stop loss % based on the position size instead of a constant, this way we decide to lose a max% of our portfolio per trade.

* Better entry execution could be done by not entering the position once the signal is generated, but to wait for a reversion to VWAP or for a price point that is ~2 standard deviations from the mean in the beneficial direction.

* Better exit execution, currently it exits based on the stop loss criteria and the encroaching PSAR.

* There's also work that could be done to allow the algorithm to enter a position in the opposite direction of the trend, maybe given a larger breakout threshold from the opening range.

These are just a few areas of the algorithm that could be improved. If you make improvements, please share the algorithm back to this thread and we as a community can learn together!

EDIT: Looks like a previous edit removed the attached algorithm, here it is, enjoy!

Author