首页 > 解决方案 > 如何使退出信号打印低于先前的进入信号?(Pine Script 交易视图 PineScript 交易视图)

问题描述

如果 Exit 信号小于 Entry,则保持到下一个 Exit 信号。我不想打印退出信号,除非它有利润。有人可以教我如何用我的脚本实现这一目标吗?

我试图说 longentry 必须是 < longexit 但这是错误...“无法使用 'expr2'=series[bool] 调用 'operator >'。参数的类型应为:float”

这是代码的一部分。

//Long                                                                       ◄◄◄
emalong = out1 > out2
macdlong = macd > signal and ((macd[1] < signal[1]) or (macd[2] < signal[2]))
histlong = hist > hist[1] and hist[1] < hist[2]
psarlong = psar < close and ((psar[1] > close[1]) or (psar[2] > close[2]))

//Short                                                                      ◄◄◄
emashort = out1 < out2
macdshort = macd < signal and ((macd[1] > signal[1]) or (macd[2] > signal[2]))
histshort = hist < hist[1] and hist[1] > hist[2]
psarshort = psar > close and ((psar[1] < close[1]) or (psar[2] < close[2]))

//Collect Signals                                                            ◄◄◄
longentry = emalong and macdlong and psarlong
longexit = histshort
shortentry = emashort and macdshort and psarshort
shortexit = histlong[enter image description here][1]

//Position of Signals                                                        ◄◄◄
var pos = 0
if longentry and pos <= 0
    pos := 1
if longexit and pos == 1
    pos := 2
if shortentry and pos >= 0
    pos := -1
if shortexit and pos == -1
    pos := -2
longensignal = pos == 1 and (pos != 1)[1]
longexsignal = pos == 2 and (pos != 2)[1]
shortensignal = pos == -1 and (pos != -1)[1]
shortexsignal = pos == -2 and (pos != -2)[1]

//Shapes                                                                     ◄◄◄
plotshape(longensignal, style=shape.circle, color=#26a69a, text="LEN", 
    textcolor=#ffffff, location=location.belowbar, size=size.tiny)
plotshape(longexsignal, style=shape.xcross, color=#26a69a, text="LEX", 
    textcolor=#ffffff, location=location.abovebar, size=size.tiny)
plotshape(shortensignal, style=shape.circle, color=#ef5350, text="SEN", 
    textcolor=#ffffff, location=location.abovebar, size=size.tiny)
plotshape(shortexsignal, style=shape.xcross, color=#ef5350, text="SEX", 
    textcolor=#ffffff, location=location.belowbar, size=size.tiny)

再次......我不想打印“LEX”,除非它大于“LEN”,我不想打印“SEX”,除非它小于“SEN”。

标签: pine-script

解决方案


推荐阅读