Custom Code MIN(a,b) formula

Optuma Forums Optuma General Discussion Custom Code MIN(a,b) formula

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #28943
    • Topics: 22
    • Replies: 23
    • Posts: 45

    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

    • Topics: 43
    • Replies: 304
    • Posts: 347

    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:

    Intermediate Scripting

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.