出口贸易中的过多信号(指标)
我已经编译了此脚本(指示器),并且它不断显示错误。贸易出口应对应于“ SL”或“ LONGEXIT”水平。 “ longexit”工作时,“ sl”不是每次交易发出单个信号,而是每次价格打破“ SL”时发出信号。我尝试了几种替代方案,但它们都没有设法消除此错误。
//@version=5
indicator("", overlay = true)
// ------------------------------ ALGO SETTING SSL INDICATOR ---------------------------{
len = input(title = 'Period', defval = 10)
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))
// }
// -------------- LONG INDICATOR INPUT FOR 3COMMAS -----------------{
LongEntry = ta.crossover(sslUp, sslDown) and barstate.isconfirmed
plotshape(LongEntry, color = color.yellow)
alertcondition(LongEntry, "BUY LONG", "message")
var int bar = 0
var int count = 0
if LongEntry
bar := bar_index
bar
count := bar_index - bar + 1
// ------------------ ALGO SETTING LONG EXIT ------------------- {
LongExit = ta.crossunder(sslUp, sslDown) and barstate.isconfirmed
alertcondition(LongExit, "LONG CLOSE REVERSE", "message")
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)
LongStopLoss = ta.crossunder(close, SL)
Condition = (LongExit or LongStopLoss)
alertcondition(LongStopLoss, "CLOSE TRADE", "message")
plotshape(Condition, color = color.blue)
// }
I have compiled this script (Indicator) and it keeps showing an error. The trade exit should correspond to the "SL" or "LongExit" level. "LongExit" works while "SL" does not issue a single signal per trade but issues the signal every time the price breaks the "SL". I tried several alternatives but none of them managed to eliminate this error.
//@version=5
indicator("", overlay = true)
// ------------------------------ ALGO SETTING SSL INDICATOR ---------------------------{
len = input(title = 'Period', defval = 10)
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))
// }
// -------------- LONG INDICATOR INPUT FOR 3COMMAS -----------------{
LongEntry = ta.crossover(sslUp, sslDown) and barstate.isconfirmed
plotshape(LongEntry, color = color.yellow)
alertcondition(LongEntry, "BUY LONG", "message")
var int bar = 0
var int count = 0
if LongEntry
bar := bar_index
bar
count := bar_index - bar + 1
// ------------------ ALGO SETTING LONG EXIT ------------------- {
LongExit = ta.crossunder(sslUp, sslDown) and barstate.isconfirmed
alertcondition(LongExit, "LONG CLOSE REVERSE", "message")
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)
LongStopLoss = ta.crossunder(close, SL)
Condition = (LongExit or LongStopLoss)
alertcondition(LongStopLoss, "CLOSE TRADE", "message")
plotshape(Condition, color = color.blue)
// }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它每次都会发出SL信号,因为您何时以及为什么不应该触发脚本。为什么不使用策略脚本?否则,您必须手动遵循订单并使用自定义逻辑进行管理,而内置的回测引擎可以做到这一点。
作为解决方法,创建一个SL Break事件的计数器并在入口条件下重置它,我还添加了一个金字化输入,以过滤序列中的SL信号量。图表上的红十字会 - SL事件,白色十字 - SL事件,用计数器和金字塔过滤:
It issues the SL signal every time because you haven't told the script when and why it shouldn't trigger. Why not use the strategy script? Otherwise, you'll have to manually follow orders and manage them with your custom logic, while the built-in backtesting engine could do it instead.
As a workaround, create a counter of SL break event and reset it on the entry condition, I've also added a pyramiding input to filter the amount of SL signals in a sequence. Red cross on the chart - SL event, white cross - SL event filtered with a counter and pyramiding: