I have the code that enters the trade if the marketcap of the cryptocurrency decreases by 3%. How would I change this so that it exits the trade when the marketcap increases/decreases by X% from the price at which it entered the trade?
change = input(3, title = "MktCap 1D percent change")/100.0 // <=== Change the value of 3 to whatever percentage you would like
rr(s, bb)=>(s - s[bb])/s
signal(s, bb)=>
rr = rr(s, bb)
//long = rr >= change // <=== For a percentage increase
long = rr <= -change // <=== For a percentage decrease
[long]
[long] = request.security("CRYPTOCAP:"+syminfo.basecurrency, "D", signal(close,1))
if (long and timePeriod)
strategy.entry("Long", strategy.long)