Quote:if the EMA cross's over or RSI signals a buy start trailing the bid price down by a percent once the bid price starts moving up go long and set a stop-loss on profit.
So once you detect your initial buy signal you want to to have some form of a trailing mechanism that confirms the signal? Most example strategies in Gekko come with a "persistence" system, that checks if the buy signal persists for X candles. Note that this is all implemented directly inside the strategy.
Quote:So far I've copied and renamed trailingStop.js to trailingStopDown.js and reversed the logic on line 27 and 33. But i'm having a hard time getting it to trigger without a long advice signal. If the logic of what I'm trying to do makes sense is it possible to trail the price down on a indicator signal then buy when the bid price goes back up?
I would advice against this: in order to have trailing stoplosses I had to implement them in a lot of places in the gekko codebase:
- I had to create the base class.
- I had to wrap that in the paper trader (based on 1min candles)
- I had to wrap that in the real trader (based on ticker polls)
- I had to introduce new gekko events
- I had to handle all the logic around: if a strat signalled a buy with a stoploss, set it up and listen to it triger.
- if before it triggered the strategy signaled a sell clean it up.
- make sure to always update local state after it triggers so gekko is aware that the exposure reversed without a trade signal (but a trailing stop trigger).
It took me a while and there were a ton of bugs, some I was able to shield with unit tests but I still get bug reports here and there.
As though why the trailing stops only go one way now: Gekko is build on some core assumptions, one being that signaling a LONG is risky (since you are about to buy into exposure) but signalling a SHORT is not (since you are selling out of exposure).
-----
In your case I would stick all the required logic inside your strategy and only signal LONG when you are sure (with your own trailing logic). You can definitely hack the trailingStop class I created, but I would import it into your strategy and don't monkey patch it into gekko!