For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Sell when exit conditions are met or trailing stop loss?
-
Hi everyone,
Not sure if my question makes sense...
Say I want to do a simple MA crossover strategy for entry and exit.
But I just want to add a trailing stop loss to protect myself, just in case.How would I implement the sell orders so that I exit my position either when the exit conditions are met (MA crossdown) or when the trailing stop loss is triggered?
At the moment, I have this code, but I am not sure it is actually doing what I intended...
(i.e. it might actually look for trailing stop loss trigger after the crossdown occurs, instead of looking for either a crossdown OR a trailing stop loss trigger)elif self.order is None: if self.MAfast < self.MAslow: self.order = self.sell(exectype=bt.Order.StopTrail, trailpercent=self.p.trailpercent)
Thanks to this knowledgeable community for helping!