出口贸易中的过多信号(指标)

发布于 2025-01-24 00:57:41 字数 1662 浏览 0 评论 0原文

我已经编译了此脚本(指示器),并且它不断显示错误。贸易出口应对应于“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个ˇ局外人 2025-01-31 00:57:41

它每次都会发出SL信号,因为您何时以及为什么不应该触发脚本。为什么不使用策略脚本?否则,您必须手动遵循订单并使用自定义逻辑进行管理,而内置的回测引擎可以做到这一点。

作为解决方法,创建一个SL Break事件的计数器并在入口条件下重置它,我还添加了一个金字化输入,以过滤序列中的SL信号量。图表上的红十字会 - SL事件,白色十字 - SL事件,用计数器和金字塔过滤:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © e2e4mfck

//@version=5
indicator("indicator() sl")

LongEntry = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
bgcolor(LongEntry ? color.new(color.red, 80) : na, title = 'EntrySignal / ResetSLCounter')
LongStopLoss = close < ta.sma(close, 14)
plotshape(LongStopLoss, color = color.red, title = 'LongStopLoss')

var int LongStopLossCounter = 0
if LongStopLoss
    LongStopLossCounter += 1
else if LongEntry
    LongStopLossCounter := 0

pyramid = input.int(1, 'Pyramiding', minval = 1)

plotshape((LongStopLossCounter <= pyramid) and LongStopLoss, color = color.white, size = size.huge, title = 'LongStopLoss filtered')

“在此处输入图像说明”

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:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © e2e4mfck

//@version=5
indicator("indicator() sl")

LongEntry = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
bgcolor(LongEntry ? color.new(color.red, 80) : na, title = 'EntrySignal / ResetSLCounter')
LongStopLoss = close < ta.sma(close, 14)
plotshape(LongStopLoss, color = color.red, title = 'LongStopLoss')

var int LongStopLossCounter = 0
if LongStopLoss
    LongStopLossCounter += 1
else if LongEntry
    LongStopLossCounter := 0

pyramid = input.int(1, 'Pyramiding', minval = 1)

plotshape((LongStopLossCounter <= pyramid) and LongStopLoss, color = color.white, size = size.huge, title = 'LongStopLoss filtered')

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文