dynamic Stop Loss with minimum and maximum values

 

Im trying to create a dynamic stop loss based on a moving average. In my example i use the 20 period Simple Moving average as my SL level. To this function i would like to add a "max SL value in pips" and "minimum SL value in pips".

if 20 SMA is more than x pips away from entryprice, use "max sl value" instead.

And

if 20 SMA is closer than x pips away from entry price, use "min sl value" instead.. 

I have defined the SMA stoploss value with a variable using the iMA function. 

So far so good. 

But i can't get my head around how to add the min and max values. 

If anyone has any ideas i will be happy to hear them;)