Tradingview止损%

时间:2019-10-14 13:12:25

标签: pine-script

我正在尝试制定在55天高点买入并在20天低点卖出的策略。 问题是我想加止损。止损需要在入场时达到5%。 这就是我已经尝试过的。

//@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]                      

sl_inp = input(2.0, title='Stop Loss %', type=input.float)/100
stop_level = strategy.position_avg_price * (1 - sl_inp)

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

loll = float(na)
loll:=  stop_level > cond_L_P_2 ? stop_level : cond_L_P_2 > stop_level ? cond_L_P_2 :loll[1]


strategy.exit("exit ","enter long",stop=loll)

plot(stop_level,style=plot.style_circles,color=color.red)
plot(cond_L_2)
plot(cond_L_P_2, color=color.green)

有时它起作用,有时它不起作用。它真的很奇怪,我希望som1可以帮助我。 enter image description here

0 个答案:

没有答案
相关问题