通过指标条件确定的价格交易
我正在尝试为Pine Script V5策略输入停止损失。停止损失是指示器红线的-0.10%。为了找到此级别,我创建了一条(白色)线。然后,我必须以白线的确切价格关闭交易。目前,我尝试了数千种解决方案,仅在突破蜡烛之后就关闭了所有这些解决方案(这非常适合重新粉刷,但对于我现在正在寻找的解决方案不足)。谁能告诉我如何在白线上获得精确的出口?
`//@version=5
strategy("", overlay = true, currency = currency.EUR,
initial_capital = 1000, commission_type = strategy.commission.percent, commission_value = 0.03,
default_qty_value = 100, default_qty_type = strategy.percent_of_equity)
len = input(title = 'PERIOD', defval = 10, group = "SETTING INDICATOR")
smaHigh = ta.sma(high, len)
smaLow = ta.sma(low, len)
Hlv = int(na)
Hlv := close > smaHigh ? 1 : close < smaLow ? -1 : Hlv[1]
sslDown = Hlv < 0 ? smaHigh : smaLow
sslUp = Hlv < 0 ? smaLow : smaHigh
plot(sslDown, linewidth = 2, color = color.new(color.red, 0))
plot(sslUp, linewidth = 2, color = color.new(color.lime, 0))
LongEntry = ta.crossover (sslUp, sslDown) and barstate.isconfirmed
LongExit = ta.crossunder(sslUp, sslDown) and barstate.isconfirmed
isLong = LongEntry //and inDateRange
if (isLong and barstate.isconfirmed)
strategy.entry(id = "BUY", direction = strategy.long, qty = 100)
var int bar = 0
var int count = 0
if LongEntry
bar := bar_index
bar
count := bar_index - bar + 1
isExit = if LongExit
close
StopLoss = input.float(defval = 0.10, title = "STOP LOSS VALUE", minval = 0.00)
distance = (sslDown * StopLoss) / 100
Value = (sslDown - distance)
SL = ta.valuewhen(LongEntry, Value, 0)
plot(SL, color = color.white)
Close = if ta.crossunder(close, SL)
close
strategy.exit("CLOSE LONG", from_entry = "BUY", stop = Close)
//strategy.close_all(when = SL)
//strategy.close_all(when = isExitStopLoss, comment = "CLOSE TRADE STOP LOSS")`
I am trying to enter a stop loss for a Pine Script V5 strategy. The stop loss is -0.10% of the red line of the indicator. To find this level I have created a (white) line. I must then necessarily close the trade at the exact price of the white line. At the moment I have tried thousands of solutions all of which close only after the breakout candle (this is great for repainting but not sufficient for the solution I am looking for now). Can anyone tell me how to get a precise exit on the white line ?
`//@version=5
strategy("", overlay = true, currency = currency.EUR,
initial_capital = 1000, commission_type = strategy.commission.percent, commission_value = 0.03,
default_qty_value = 100, default_qty_type = strategy.percent_of_equity)
len = input(title = 'PERIOD', defval = 10, group = "SETTING INDICATOR")
smaHigh = ta.sma(high, len)
smaLow = ta.sma(low, len)
Hlv = int(na)
Hlv := close > smaHigh ? 1 : close < smaLow ? -1 : Hlv[1]
sslDown = Hlv < 0 ? smaHigh : smaLow
sslUp = Hlv < 0 ? smaLow : smaHigh
plot(sslDown, linewidth = 2, color = color.new(color.red, 0))
plot(sslUp, linewidth = 2, color = color.new(color.lime, 0))
LongEntry = ta.crossover (sslUp, sslDown) and barstate.isconfirmed
LongExit = ta.crossunder(sslUp, sslDown) and barstate.isconfirmed
isLong = LongEntry //and inDateRange
if (isLong and barstate.isconfirmed)
strategy.entry(id = "BUY", direction = strategy.long, qty = 100)
var int bar = 0
var int count = 0
if LongEntry
bar := bar_index
bar
count := bar_index - bar + 1
isExit = if LongExit
close
StopLoss = input.float(defval = 0.10, title = "STOP LOSS VALUE", minval = 0.00)
distance = (sslDown * StopLoss) / 100
Value = (sslDown - distance)
SL = ta.valuewhen(LongEntry, Value, 0)
plot(SL, color = color.white)
Close = if ta.crossunder(close, SL)
close
strategy.exit("CLOSE LONG", from_entry = "BUY", stop = Close)
//strategy.close_all(when = SL)
//strategy.close_all(when = isExitStopLoss, comment = "CLOSE TRADE STOP LOSS")`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 sl 变量作为
stop =
参数,而不是 close ,它返回na
没有na
code> ta.crosunder()遇到条件:Use the SL variable as a
stop=
argument instead of the Close, which returnsna
when there is nota.crosunder()
condition met: