Back

Using insights to signal exit of a current position

I am trying to implement the following simple breakout strategy using the Framework Algorithm Insight abstraction:

for each asset 

  • If long position does not exist and today's close is higher than the highest close in the past 50 days, enter long position
  • If long position exists and today's close is lower than the lowest close for past 25 days, exit long position
  • if short position does not exist and today's close is lower than the lowest close in the past 50 days, enter short position
  • if short position exists and today's close is higher than the highest close in the past 25 days, 
Assuming  equal weighting for all positions, how can I express the fact that a position should be liquidated, using Insights? insights = []
for asset in universe:
if not symbolData.LongPosition and symbolData.LongBreakout:
insights.append(Insight.Price(symbolData.Symbol, self.predictionInterval, InsightDirection.Up))
continue
if symbolData.LongPosition and symbolData.LongExit:
# exit long position above
#insights.append(Insight(????))
continue
if not symbolData.ShortPosition and symbolData.ShortBreakout:
insights.append(Insight.Price(symbolData.Symbol, self.predictionInterval, InsightDirection.Down))
continue
if symbolData.ShortPosition and symbolData.ShortExit:
# exit short position above
#insights.append(Insight(????))
continue

 

  
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.


Closed because question is duplicate of this thread, which has been answered. 

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.


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