I am trying to set a minimum value for a stop loss currently based on setting the stop loss on moving averages, but if the stop loss is less than XI would like to set the minimum value.
So currently if the price is below ma1 it weill set the stop loss at ma2, but if the price is below ma2 it will set the stop loss at ma3. What should I add to set the minimum value at eg 0.6 % ?
I am just learning pine script so I have just tried a couple of things that didn´t compile. Halp?
if buy[1]
en := open
sl := en > ma3[1] ? ma4[1] : ma4[1]
tg := en + profit_mult * abs(en - sl)
trl := en + trail_mult * abs(en - sl)
trl_perc := (trl-en)/en
buy_indx := bar_index
buy_str = "Reward: " + tostring(round( ((tg-en)/en)*100 , 2)) + "%, " + tostring(round( tg - en, 2)) + "\nRisk: " + tostring(risk(sl, en, "buy")) + "%, " + tostring(round(en-sl, 2))
label.new(bar_index, tg, yloc=yloc.price, text=buy_str, textcolor=color.white, style=label.style_none, size=size.small)
strategy.exit("BUY_EXIT", "BUY", limit=tg, stop=sl, comment="B-Ex", alert_message=ExitLong)
minSL = close - (close * 0.006)
if buy[1]
sl = ((en - ma4) / en) < 0.006 ? minSL : na
//checks if the difference between open and ma4 is less than 0.6%, sets sl at 0.6% below close if true
Edit: Combined with your previous sl conditions
sl := ((en - ma4) / en) < 0.006 and not en > ma3[1] ? minSL : en > ma3[1] ? ma4[1] : ma4[1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.