# Custom Code MIN(a,b) formula

Hi. I am trying to bound a value in a custom code (could be in a script also). I’m attempting to bound the top value plotted to 35. This doesn’t work but should provide the algorithm I am trying to implement.

MIN(SPX:WI, 35) … to print the SPX value or 35 if SPX is higher than 35.

Of course, this does not make sense to bound the SPX to at high of 35 - but it is just a simple example.

Thanks. Andy

Hi Andy,

You can use an IF(condition, value if true, value if false) statement for this, ie if SPX < 35 use SPX value, else use 35.

IF(CLOSE() < 35, CLOSE(), 35)

Here is an example of a watchlist column that uses the highest value between the closing value and the 13 period exponential moving average, using the following formula:

EMA13 = MA(BARS=13, STYLE=Exponential, CALC=Close);

IF(CLOSE() > EMA13, CLOSE(), EMA13)

For a video on using IF statements sign in to the scripting course here and watch Lecture 5:

https://learn.optuma.com/course/intermediate-scripting/