0
votes

enter image description hereIm trying to make a strategy that buys at the 55 day high and sells at the 20 day low. The probles is that i want to add a stoploss. The stoploss needs to be at 5 procent from the entry. This is what i already tried.

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

Sometimes it works and somtimes it does not work. its really wierd, i hope som1 can help me.

1
"Sometimes it works and somtimes it does not work" doesn't realy help. Please add more info with some screenshots when it "does not work" and when it "works". Try to explain the behavior when it doesn't work. - Baris Yakut

1 Answers

0
votes

That's because your stop loss level is higher than current price: http://dl4.joxi.net/drive/2019/10/14/0024/1758/1636062/62/f02fb255bc.jpg