Lets say i i bought EURUSD at 1.05 and want to set a stop loss about 15 pips below and a take profit 40 pips above the buy price.
The most examples i saw were not that clear and bad documented.
How the heck do we do this ? Could someone give an detailed example of how we implement this in an easy way ? :/
Aaron Janeiro Stone
See the attached.
Basically, you would reset the current price of whatever your "buy-in" variable was set to only when you don't hold the equity, making it available for comparison to the current price in order to determine if you need to sell. Upon selling, the next OnData call will cause you to take a position in the attached example (although, of course, you can always set conditions for entry into the position by replacing Portfolio.Invested with whatever alternative of your choosing).
Aaron Janeiro Stone
Just noticed a typo in the code documentation. The second if statement should instead be:
if CurrentPrice > self.BuyIn*(1+0.05) or CurrentPrice < self.BuyIn*(1-0.05): # Sell if +/- 5 pct from buy
Â
Lars Matthäus
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!