Different exits and setpositionsize

Hi all,

I try to write a strategy with different exits and this is my idea:
When profit (high since buy) is less than 5% then
the system will exit
50% of position if MA20 as trailing stop is hit
50% of position if MA50 as trailing stop is hit
Max loss is fixed at 5%
When profit is between 5% and 20% then
the system will exit
50% of position if MA20 as trailing stop is hit
50% of position if MA50 as trailing stop is hit
Max loss is fixed at 0% since profit is more than 5% already
When profit is higher than 20% then
the system will exit
100% of position if MA10 as trailing stop is hit

I try to read this link https://www.amibroker.com/guide/afl/setpositionsize.html which has similar idea but mine is really more complicated. I think to use Applystop will make it easier. Anyone can help me please?

See Verify License.