I'm building a second-based strategy (currently on 5sec candles to limit the amount of alerts), it's working great in backtesting, but I think it can be optimized even further.
Let's say I work with an indicator which triggers a simple buySignal
and sellSignal
(one must follow the other without repetition), I've set my strategy.entry/close
based on those signals (duh.) and added a Trailing Stop-Loss useTrailStop
so tight that it often Exits (in profit 80% of the time) one, two, maybe max three candles after Entry (1sec or 5 sec).
Ok, cool, I'm making good profit and it's a steady growth over time, but then I'm missing-out on every big price swings because the profit-taking happened way too soon, and the next buySignal
can only happen AFTER the following sellSignal
. So...
Is there any way to reactivate my buySignal to trigger as-soon-as-possible after Exit if the conditions for my initial Long Entry are still being met ?
Here comes the code, stripped down to the basics.
// Risk management inputs (settings) :
//If one of you knows how to translate this part in percentages, something about input.float I think, I'd love to know.
inpTrailStop = input(defval = 200, title = "Trailing Stop Loss", minval = 0)
inpTrailOffset = input(defval = 0, title = "Trailing Stop Loss Offset", minval = 0)
// === RISK MANAGEMENT Back-end ===
// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na
// Strategy backtesting signals Buy / Close :
strategy.entry("Long", strategy.long, 1, when=buySignal)
strategy.close("Long", when=sellSignal)
// === STRATEGY RISK MANAGEMENT EXECUTION ===
strategy.exit("Exit Long", from_entry = "Long", trail_points = useTrailStop, trail_offset = useTrailOffset )