let's say that you enter a long position but the price goes down and the stoploss gets triggered, instead of just closing the long trade i want the script to open a short trade. How do i do that? I tried doing it myself, but i'm too dumb, so this is what i came up with.
strategy.exit("Exit short", from_entry="short", stop=low * stoplossforSell)
and then
if strategy.position_entry_name=="Exit short"
strategy.entry("long from short",strategy.long)
edit:
if(bhigh[1]>upper[1] and bhigh[1]>bhigh and macd<signal2 )
strategy.close("long")
strategy.entry("short",strategy.short)
strategy.exit("Exit short", from_entry="short", stop=low * stoplossforSell)
strategy.entry("Short", strategy.short, stop=low * stoplossforSell)
if(blow[1]<lower[1] and blow[1]<blow and open[1]<close[1] and macd>signal2)
strategy.close("short")
strategy.entry("long",strategy.long)
strategy.exit("Exit long", from_entry="long", stop=low * stoplossforBuy)
strategy.entry("long", strategy.long, stop=low * stoplossforSell)
edit 2:
stoplossforSell= input(defval=1.02,title="stoploss for sell")
stoplossforBuy= input(defval=0.98,title="Stoploss for buy")
if(bhigh[1]>upper[1] and bhigh[1]>bhigh and open[1]>close[1] and macd<signal2 )
strategy.close("long")
strategy.entry("short",strategy.short)
if (strategy.position_size < 0)
strategy.exit("Exit short", from_entry="short", stop=low * stoplossforSell)
strategy.entry("long", strategy.long, stop=low * stoplossforSell)
if(blow[1]<lower[1] and blow[1]<blow and open[1]<close[1] and macd>signal2)
strategy.close("short")
strategy.entry("long",strategy.long)
if (strategy.position_size > 0)
strategy.exit("Exit long", from_entry="long", stop=low * stoplossforBuy)
strategy.entry("short", strategy.short, stop=low * stoplossforBuy)