Exit strategy

Plz Help me code EXIT strategy for pi.

Where the exit rules is SL or target @ 1% from entry price, whichever comes first

For one percent of buy value , lets say your buy script is

CLOSE>SMA(HIGH,20)

then one percent exit will be

(CLOSE>SMA(HIGH,20))* 1.01

thanks sir, really appreciate