英文:
While trade is open, check if middleBand is crossed below twice, if true trigger SL
问题
我试图检查价格是否"下穿"中间线两次:
longSLCondition = ta.crossover(close, middleBand ) and ta.crossover(close, middleBand )
条件会关闭交易,但是方向错误:
在图表中,您可以看到价格第一次在开仓后闭合到中间线下方。然后价格再次上升到中间线上方,触发了止损(红圈)。
我希望止损在价格第二次下穿中间线时触发(绿圈),而不是上穿。
感谢您的专业知识。
英文:
I am trying to check if the price is "crossing down" twice the middleBand :
longSLCondition = ta.crossover(close, middleBand ) and ta.crossover(close, middleBand )
Condition closes the trade but the wrong way :
In the chart, you can see that the price closes a first time below the middleBand just after the trade was opened. Then he closes above the middleBand and the SL is triggered (red circle).
I would like the SL triggered when the price closes a second time below the middleBand (green circle) and not above.
Thanks for your expertise.
答案1
得分: 0
以下是翻译好的部分:
"Idea was to trigger a stop loss if the price close twice below the middle band."
这个想法是,如果价格连续两次关闭在中间线以下,就触发止损。
"Here's the solution :"
以下是解决方案:
if ta.crossunder(close, middleBand)
cross_count := cross_count + 1 // Increment the counter if condition is met
if delayElapsed
strategy.entry('long', strategy.long)
cross_count:=0 // Reset the counter after having entered the trade
strategy.close('long', comment="SL Long")```
<details>
<summary>英文:</summary>
Idea was to trigger a stop loss if the price close twice below the middle band.
Here's the solution :
var int cross_count = 0 // Initialize the counter variable
if ta.crossunder(close, middleBand)
cross_count := cross_count + 1 // Increment the counter if condition is met
// --- Long Entry | Close
if delayElapsed
strategy.entry('long', strategy.long)
cross_count:=0 // Reset the counter after having entered the trade
f (cross_count >= 2 and strategy.position_size > 0) // Check if long trade and price crossed twice the middleBand
strategy.close('long', comment="SL Long")
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论