pine-script crossunder 不工作我期望
pine-script crossunder don't work I expected
我对 enterShortCondition 有这个问题。
当收盘价低于下线时,我想要退出空头信号。
对于多头头寸,我没有问题,但对于空头条件(它是多头条件的镜面反射),当收盘价超过上线时,我有一个退出信号。我不明白。我为此疯狂。
有人可以帮我吗?
这是代码
// This source code is subject to the terms of the Mozilla Public License 2.0 at ``https://mozilla.org/MPL/2.0/
// © pret71
//@version=4
strategy("Intraday Forex Strategy", overlay=true)
length = input(20, minval=1)
smaPeriod = input(defval = 60, title = "SMA Period", type = input.integer)
lower = lowest(length)[1]
upper = highest(length)[1]
basis = avg(upper, lower)
plot(basis, "Basis", color=#FF6A00)
u = plot(upper, "Upper", color=#0094FF)
l = plot(lower, "Lower", color=#0094FF)
mySma=sma(close,smaPeriod)
plot(mySma, "Basis", color=color.red)
//verifico che incaso long sma50 (mySma) sia crescente e in caso short decrescente
confirmLongCondition = iff(mySma[25]>mySma[50] and mySma[0]>mySma[25],true,false)
confirmShortCondition = iff(mySma[25]<mySma[50] and mySma[0]<mySma[25],true,false)
enterLongCondition = crossunder(close,lower) and confirmLongCondition //and (lower>mySma)
if (enterLongCondition)
strategy.entry("LongEntry", strategy.long)
enterShortCondition = crossover(close,upper) and confirmShortCondition //and (upper<mySma)
if (enterShortCondition)
strategy.entry("ShortEntry", strategy.short)
exitLongConditiond = crossover(close,upper)
if (exitLongConditiond)
strategy.close("LongEntry")
exitShortConditiond = crossunder(close,lower)
if (exitLongConditiond)
strategy.close("ShortEntry")
我尝试使用这个 pine 脚本,但它不起作用
您在上次条件检查中输入了错误的变量名称。您设置 exitShortConditiond
,然后您正在检查 exitLongConditiond
。
您的代码:
exitLongConditiond = crossover(close,upper)
if (exitLongConditiond)
strategy.close("LongEntry")
exitShortConditiond = crossunder(close,lower)
if (**exitLongConditiond**)
strategy.close("ShortEntry")
我对 enterShortCondition 有这个问题。 当收盘价低于下线时,我想要退出空头信号。
对于多头头寸,我没有问题,但对于空头条件(它是多头条件的镜面反射),当收盘价超过上线时,我有一个退出信号。我不明白。我为此疯狂。
有人可以帮我吗?
这是代码
// This source code is subject to the terms of the Mozilla Public License 2.0 at ``https://mozilla.org/MPL/2.0/
// © pret71
//@version=4
strategy("Intraday Forex Strategy", overlay=true)
length = input(20, minval=1)
smaPeriod = input(defval = 60, title = "SMA Period", type = input.integer)
lower = lowest(length)[1]
upper = highest(length)[1]
basis = avg(upper, lower)
plot(basis, "Basis", color=#FF6A00)
u = plot(upper, "Upper", color=#0094FF)
l = plot(lower, "Lower", color=#0094FF)
mySma=sma(close,smaPeriod)
plot(mySma, "Basis", color=color.red)
//verifico che incaso long sma50 (mySma) sia crescente e in caso short decrescente
confirmLongCondition = iff(mySma[25]>mySma[50] and mySma[0]>mySma[25],true,false)
confirmShortCondition = iff(mySma[25]<mySma[50] and mySma[0]<mySma[25],true,false)
enterLongCondition = crossunder(close,lower) and confirmLongCondition //and (lower>mySma)
if (enterLongCondition)
strategy.entry("LongEntry", strategy.long)
enterShortCondition = crossover(close,upper) and confirmShortCondition //and (upper<mySma)
if (enterShortCondition)
strategy.entry("ShortEntry", strategy.short)
exitLongConditiond = crossover(close,upper)
if (exitLongConditiond)
strategy.close("LongEntry")
exitShortConditiond = crossunder(close,lower)
if (exitLongConditiond)
strategy.close("ShortEntry")
我尝试使用这个 pine 脚本,但它不起作用
您在上次条件检查中输入了错误的变量名称。您设置 exitShortConditiond
,然后您正在检查 exitLongConditiond
。
您的代码:
exitLongConditiond = crossover(close,upper)
if (exitLongConditiond)
strategy.close("LongEntry")
exitShortConditiond = crossunder(close,lower)
if (**exitLongConditiond**)
strategy.close("ShortEntry")