Crypto Asset BTCEUR Long-Only MA Crossover with Trailing Stop

Dear all,

Please find attach the backtest with the code on the following strategy: long-only moving average crossover with trailing stop. Note: it is not possible to short sell on GDAX (unless you have more than $5M), so that explains the long-only.

I had a few questions for you:

- What is the purpose of the clr.AddReference(some_module) after which we import the said module:

import clr
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *

- I use the OnOrderEvent(self, event) method. However, I believe it is never executed (despite orders being filled) since I have debug/log messages in this code block that do not appear. Furthermore, since I create the limit stop loss in this method, after backtesting, it seems no stop loss was ever executed despite some huge drawdowns. What should I do for this code block to be executed?

- How would you go setting how the trailing stop price follows the current price? In my mind, the best would be a formula that could set the pace 1 for 1, more than 1 for 1 (with a constraint at some point), less than 1 for 1. I came up with the following formula: 

if currentPrice > self.previousPrice:
ratio = currentPrice / self.previousPrice
adjustedRatio = (ratio + self.follow_factor) / (1 + self.follow_factor)
trigger = decimal.Decimal(self.previousTrigger * adjustedRatio)

- Relative to the QuantConnect Coding Standards (no matter how officious they are ;) ) is there anything in the code that should be improved/changed?

- Relative to the strategy, what would you change or add? The next steps I planned: add a time filter (hourly period during a day), add a breaking out/price confirmation signal (recent high surpassed?), adjust the parameters´ inputs for better performance.

Thank you in advance!

Update Backtest

Thanks man, I'll check it out!


there is a problem with the onorder event...

thats the new post:

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.


This discussion is closed