Back

ETF Trend Following Algorithm

This trend following algorithm is converted from Naoki Nagai combined with the improvement of Maxim Girbu about applying the weighted moving average to adjust position sizing.

First, choose the major ETFs in the index, fix income and commodity market. The linear regression over the open price of the last half year is used to decide the current trend. The trading signals are triggered by the following rules

1. Set a threshold to the slope of the regression line, trade if the slope exceeds the threshold

2. Uptrend ( slope > 0 and slope > threshold):  

  • Today's open cross the regression line upward and the equity is not invested  - long
  • The equity has already been invested(long) and today's open greater than 95% upper Bollinger band - liquidate 

3. Downtrend (slope < 0 and slope < - threshold)

  • Today's open cross below the regression line and the equity is not invested  - short
  • The equity has already been invested(short) and today's open lower than 95% lower Bollinger band - liquidate

4. If the equity has already been invested

  • long but the slope turns down, liquidate
  • short but the slope turns upward, liquidate

 5. Trailing stop

  • The stoploss percentage is the absolute value of slope over the lookback period, the price is the historical mean over the last three days
Update Backtest






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.



Can someone explain how self.weigth is determined in this algo? As is initialized with 0, but I don't see any part in which is assigned a new value for self.weigth. 

Thanks

Nicolas

0

I get an error of 

QuantConnect.Scheduling.ScheduledEventException: In Scheduled Event 'SPY: EveryDay: SPY: 28 min after MarketOpen', ---> System.MissingMethodException: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the History method. Please checkout the API documentation. ---> Python.Runtime.PythonException: TypeError : No method matches given arguments for History
at Python.Runtime.PyObject.Invoke (Python.Runtime.PyObject[] args) [0x00035] in <7ada479175184ff388929ece541bbdb4>:0 
at QuantConnect.Scheduling.ScheduleManager+<>c__DisplayClass15_0.b__0 (System.String name, System.DateTime time) [0x00007] in <857ba9811bc24bd589f0534bda0e8a7c>:0 
at QuantConnect.Scheduling.ScheduledEvent.OnEventFired (System.DateTime triggerTime) [0x00036] in <857ba9811bc24bd589f0534bda0e8a7c>:0 
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---

Does anyone know what to do here?

OK

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