Pine script 如何在pine脚本中设置停止损失?

Pine script 如何在pine脚本中设置停止损失?,pine-script,Pine Script,当我进入一个仓位时,我试图绘制止损图。问题是当我进入一个位置时,我得到两个止损点,但我只想要一个 //@版本=4 策略(“海龟项目”,overlay=true) entry_long_2=输入(55,title=“entry_long_2_input”,minval=2) 利润长2=输入(20,title=“利润长2=输入”,minval=1) cond_L_2=浮动(na) cond_L_2:=如果高[entry_long_2]>=最高(high,entry_long_2) 高[入口长2]

当我进入一个仓位时,我试图绘制止损图。问题是当我进入一个位置时,我得到两个止损点,但我只想要一个


//@版本=4
策略(“海龟项目”,overlay=true)
entry_long_2=输入(55,title=“entry_long_2_input”,minval=2)
利润长2=输入(20,title=“利润长2=输入”,minval=1)
cond_L_2=浮动(na)
cond_L_2:=如果高[entry_long_2]>=最高(high,entry_long_2)
高[入口长2]
其他的
条件2[1]
cond_L_P_2=浮动(na)
cond_L_P_2:=如果低[利润长2]=最高(高,入口长1)
高[入口长度1]
其他的
条件1[1]
cond_L_P_1=浮动(na)

cond_L_P_1:=如果低[profit_long_1]

此代码中的绘图已清理干净,希望能如您所愿。请参阅注释以了解所做的更改。你的交易止损点现在是较大的淡红色圆点

//@version=4
strategy("Turtle Project",overlay= true)
entry_long_2  =  input(55,   title="entry_long_2_input" ,minval=2)                
profit_long_2 =  input(20,   title="profit_long_2_input",minval=1)                

cond_L_2 = float(na)                                                             
cond_L_2:= if high[entry_long_2] >= highest(high,entry_long_2)                   
    high[entry_long_2]                                                            
else                                                                              
    cond_L_2[1]                                                                   


cond_L_P_2 = float(na)                                                            
cond_L_P_2:= if low[profit_long_2] <= lowest(low,profit_long_2)                   
    low[profit_long_2]                                                            
else                                                                            
    cond_L_P_2[1]                      



if high < cond_L_2
    strategy.entry("enter long",strategy.long, stop=cond_L_2)
// For debugging: Shows when your entry order issuing condition is true, but not necessarily when the order is executed.
// plotchar(high < cond_L_2, "high < cond_L_2", "▲", location.top)

sl_inp_1 = input(2.0, title='Stop Loss_1 %', type=input.float)/100
stop_level_1 = strategy.position_avg_price * (1 - sl_inp_1)
stop_1 = max(cond_L_P_2,stop_level_1)

strategy.exit("exit ","enter long",stop=stop_1)
// Commented this plot out as it's not useful on the chart.
// plot(stop_level_1, "stop_level_1", style=plot.style_circles,color=color.red)
plot(cond_L_2, "cond_L_2")
plot(cond_L_P_2, "cond_L_P_2", color=color.green)

entry_long_1 =  input(20,   title="entry_long_2_input" ,minval=2)                
profit_long_1 =  input(10,   title="profit_long_2_input",minval=1)                

cond_L_1 = float(na)                                                             
cond_L_1:= if high[entry_long_1] >= highest(high,entry_long_1)                   
    high[entry_long_1]                                                            
else                                                                              
    cond_L_1[1]                                                                   


cond_L_P_1 = float(na)                                                            
cond_L_P_1:= if low[profit_long_1] <= lowest(low,profit_long_1)                   
    low[profit_long_1]                                                            
else                                                                            
    cond_L_P_1[1]                      



if high < cond_L_1
    strategy.entry("enter longj",strategy.long, stop=cond_L_1)

sl_inp_2 = input(10.0, title='Stop Loss_2 %', type=input.float)/100
stop_level_2 = strategy.position_avg_price * (1 - sl_inp_2)
stop_2 = max(cond_L_P_1,stop_level_2)

strategy.exit("exit ","enter longj",stop=stop_2)
// This plots the actual stop used in your exit order.
plot(stop_2, "stop_2", style=plot.style_circles, color=color.maroon, linewidth = 3, transp = 80)
// Comment this line out if you don't want the initial entry's stop level to plot.
plot(stop_level_2, "stop_level_2", style=plot.style_circles,color=color.maroon)
plot(cond_L_1, "cond_L_1")
plot(cond_L_P_1, "cond_L_P_1", color=color.green)
/@version=4
策略(“海龟项目”,overlay=true)
entry_long_2=输入(55,title=“entry_long_2_input”,minval=2)
利润长2=输入(20,title=“利润长2=输入”,minval=1)
cond_L_2=浮动(na)
cond_L_2:=如果高[entry_long_2]>=最高(high,entry_long_2)
高[入口长2]
其他的
条件2[1]
cond_L_P_2=浮动(na)

cond_L_P_2:=如果低[利润长2],这两个不同的入口似乎没有不同的止损点。谢谢你的帮助,但我不认为它是固定的,你的策略中只有一个入口和一个出口。你说当你进入一个位置时,你有两次停站,并且只想要一次。现在你说你有两个不同的条目,它们需要不同的止损。我不知道你的意思,所以我也帮不了你。对不起,我想我只是说得不够清楚。好的,让我解释一下。我有策略,条目1在55日线买入,条目2在20日线买入。我只想在每个进场信号上有一个止损点,但我希望能够看到它们。因此,当我进场时,我只想看到一个与该策略相关的止损点。进场。