我在Pinescript V4中的停止功能遇到了一些问题。 TP有效,但由于某种原因,停止行动不起作用。附件是代码片段,也是该代码应该在哪里的图片。
Stop should be at the highest high of the last 4 bars (including the current bar)
longstop = lowest(low, 4)
shortstop = highest(high, 4)
if longcond
strategy.entry("long", strategy.long, 5, stop = longstop)
strategy.exit("TP", "long", limit = EMA)
if shortcond
strategy.entry("short", strategy.short, 5, stop = shortstop)
strategy.exit("TP", "short", limit = EMA)
Update
If我在if块中添加了额外的stragity.exit()函数,那么即使它应该以限制价格关闭Example
if shortcond
strategy.entry("short", strategy.short, 5)
strategy.exit("SL", "short", stop = shortstop)
strategy.exit("TP", "short", limit = EMA)
If I add the stop to the current strategy.exit() line, then the stop price is continually updated at each bar for the lowest/highest of the past我不想要的4个酒吧。我希望在入口栏上设定和静态停止价格。
if longcond
strategy.entry("long", strategy.long, 5)
strategy.exit("TP", "long", limit = EMA, stop = longstop)
我希望TP是动态的(更新每个栏是EMA价格),但我希望SL是静态的(最近4个bar中的最低/最高价格)
I've been having some problems with the stop function in Pinescript v4. The TP works but for some reason, the stop isn't working. Attached is the code snippet and a picture of where it should be.
Stop should be at the highest high of the last 4 bars (including the current bar)
longstop = lowest(low, 4)
shortstop = highest(high, 4)
if longcond
strategy.entry("long", strategy.long, 5, stop = longstop)
strategy.exit("TP", "long", limit = EMA)
if shortcond
strategy.entry("short", strategy.short, 5, stop = shortstop)
strategy.exit("TP", "short", limit = EMA)
Update
If I add an extra strategy.exit() function within the if block, then it will only trigger when it hits the stop price even when it should have closed at the limit price Example
if shortcond
strategy.entry("short", strategy.short, 5)
strategy.exit("SL", "short", stop = shortstop)
strategy.exit("TP", "short", limit = EMA)
If I add the stop to the current strategy.exit() line, then the stop price is continually updated at each bar for the lowest/highest of the past 4 bars which I don't want. I want the stop price to be set and static at the entry bar.
if longcond
strategy.entry("long", strategy.long, 5)
strategy.exit("TP", "long", limit = EMA, stop = longstop)
I want the TP to be dynamic (updates every bar to be the EMA price) but I want the SL to be static (the lowest/highest price within the last 4 bars)
发布评论
评论(2)
limit
strategy.exit()
的参数用于获取利润。如果要设置停止损失,请使用stop
参数。limit
argument of thestrategy.exit()
is used for take profits. If you want to set a stop loss, use thestop
argument.我能够通过添加一个条件来计算以来的条件来修复它,从而切换到V5。
I was able to fix it by adding a condition counting the number of bars since entry and switching to v5.