if() for custom index

After reading your latest blog post on custom indexes it got me thinking if I could calculate some of my excel charts directly in Optuma.

One of them operates as a lagging indicator that combines a number of factors of price, volume, and time through nested if statements. The idea being that in a chosen group of stocks I can see how many are trending with the chosen indicators.

A simplified version of my excel formula to sum the total of stocks that have their price sitting above the 20 period moving average each day.

sum(if(Stock1 Price>20MA,true=1,false=0),if(Stock2 Price>20MA,true=1,false=0)...

I'm slowly getting my head around Optuma scripting, but before I get too far in three questions:

  • Is it possible to use if() in the custom codes builder?
  • What is the syntax of the if() statement - excel is: if(logical test, value if true, value if false)
  • Is there a tool or feature of Optuma that can do this that I have not found


Hi Rhiannon,

We have a custom Market Breadth module which will calculate any true/false condition for a universe of stocks (eg CLOSE()>MA(BARS=20) in your example) to create a time series. This is an optional add-on module available here:

Custom Market Breadth Module

For more on using the IF() statement see this post: