简体   繁体   English

如果仍满足初始入场条件,如何在追踪止损收盘获利后尽快强制“买入信号”重新激活?

[英]How to force a "Buy-Signal" to reactivate ASAP after a Trailing Stop-Loss closes in profit, if conditions for initial Entry are still being met?

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.我正在构建基于秒的策略(目前使用 5 秒蜡烛来限制警报数量),它在回溯测试中效果很好,但我认为它可以进一步优化。

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).假设我使用一个指标来触发一个简单的buySignalsellSignal (一个必须跟随另一个而不重复),我已经根据这些信号设置了我的strategy.entry/close (duh.) 并添加了一个追踪止损useTrailStop太紧以至于它经常退出(80% 的时间获利)在进入后(1 秒或 5 秒)一根、两根,也许最多三根蜡烛。

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 .好吧,很酷,我赚了很多钱,而且随着时间的推移它在稳定增长,但是我错过了每一个大的价格波动,因为获利回吐发生得太快了,下一个buySignal只能在跟随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 )

The idea is to monitor for the last trade being closed with strategy.exit (comment of the closed trade will be "Trail" in that case), and check if position has changed, and then enter Long.这个想法是用strategy.exit监控最后一笔关闭的交易(在这种情况下关闭交易的注释将是“Trail”),并检查 position 是否已更改,然后输入 Long。

// Strategy backtesting signals Buy / Close :


if (buySignal) or (ta.change(strategy.closedtrades) and strategy.closedtrades.exit_comment(strategy.closedtrades -1) == "Trail")
    strategy.entry("Long", strategy.long, 1)

if sellSignal
    strategy.close("Long")

// === STRATEGY RISK MANAGEMENT EXECUTION ===

strategy.exit("Exit Long", from_entry = "Long", trail_points = useTrailStop, trail_offset = useTrailOffset, comment = "Trail")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM