试图获得战略,进入和条件是否有效
Trying to get Strategie,entry and if condtion to work
我在使用 strategy.entry 和停止命令时遇到一些问题。
当 strategy.position_size == 0 且低 > long_1 且低 < long_2.
时,我希望 strategy.entry 为真
//@version=4
strategy("Turtle Project",overlay= true)
entry_1 = input(55)
profit_1 = input(20)
long_1 = float(na)
long_1:= if high[entry_1] >= highest(high,entry_1)
high[entry_1]
else
long_1[1]
entry_2 = input(20)
profit_2 = input(10)
long_2 = float(na)
long_2:= if high[entry_2] >= highest(high,entry_2)
high[entry_2]
else
long_2[1]
profit2 = float(na)
profit2:= if low[profit_2] <= lowest(low,profit_2)
low[profit_2]
else
profit2[1]
stop_2 = input(2)/100
x = strategy.position_size == 0 and low > long_1 and low < long_2 ? true : false
barcolor(x ? color.blue : na)
if strategy.position_size == 0 and low > long_1 and low < long_2
strategy.entry("longlong_3",strategy.long, stop=long_2)
stoploss_2 = lowest(low,1) <= long_2 and highest(high,1) >= long_2
stoploss2 = float(na)
stoploss2:= stoploss_2 ? strategy.position_avg_price * (1 - stop_2) : stoploss2[1]
stoploss__2 = max(stoploss2,profit2)
if high > long_2 and strategy.position_size > 0
strategy.exit("exit_2 ","longlong_3",stop=stoploss__2)
plot(long_1,color=color.red ,linewidth=3)
plot(long_2,color=color.blue,linewidth=3)
plot(profit2,color=color.blue, linewidth=1)
plot(stoploss2,style=plot.style_circles, color=color.red)
我希望有人知道如何解决我的问题。
您的问题是因为条件在 2018 年 1 月至 2 月变为 true
(绘制条件值以查看何时为真:plot(strategy.position_size == 0 and low > long_1 and low < long_2 ? 10000 : 0, color=color.green)
),然后将订单发送至交换并且从未被取消,所以从那时起它就一直在等待。要解决此问题,只需使用 strategy.cancel
:
if strategy.position_size == 0 and low > long_1 and low < long_2
strategy.entry("longlong_3",strategy.long, stop=long_2)
else
strategy.cancel("longlong_3")
应该可以。
我在使用 strategy.entry 和停止命令时遇到一些问题。 当 strategy.position_size == 0 且低 > long_1 且低 < long_2.
时,我希望 strategy.entry 为真//@version=4
strategy("Turtle Project",overlay= true)
entry_1 = input(55)
profit_1 = input(20)
long_1 = float(na)
long_1:= if high[entry_1] >= highest(high,entry_1)
high[entry_1]
else
long_1[1]
entry_2 = input(20)
profit_2 = input(10)
long_2 = float(na)
long_2:= if high[entry_2] >= highest(high,entry_2)
high[entry_2]
else
long_2[1]
profit2 = float(na)
profit2:= if low[profit_2] <= lowest(low,profit_2)
low[profit_2]
else
profit2[1]
stop_2 = input(2)/100
x = strategy.position_size == 0 and low > long_1 and low < long_2 ? true : false
barcolor(x ? color.blue : na)
if strategy.position_size == 0 and low > long_1 and low < long_2
strategy.entry("longlong_3",strategy.long, stop=long_2)
stoploss_2 = lowest(low,1) <= long_2 and highest(high,1) >= long_2
stoploss2 = float(na)
stoploss2:= stoploss_2 ? strategy.position_avg_price * (1 - stop_2) : stoploss2[1]
stoploss__2 = max(stoploss2,profit2)
if high > long_2 and strategy.position_size > 0
strategy.exit("exit_2 ","longlong_3",stop=stoploss__2)
plot(long_1,color=color.red ,linewidth=3)
plot(long_2,color=color.blue,linewidth=3)
plot(profit2,color=color.blue, linewidth=1)
plot(stoploss2,style=plot.style_circles, color=color.red)
我希望有人知道如何解决我的问题。
您的问题是因为条件在 2018 年 1 月至 2 月变为 true
(绘制条件值以查看何时为真:plot(strategy.position_size == 0 and low > long_1 and low < long_2 ? 10000 : 0, color=color.green)
),然后将订单发送至交换并且从未被取消,所以从那时起它就一直在等待。要解决此问题,只需使用 strategy.cancel
:
if strategy.position_size == 0 and low > long_1 and low < long_2
strategy.entry("longlong_3",strategy.long, stop=long_2)
else
strategy.cancel("longlong_3")
应该可以。