Skip to content

Examples of Scripting Formulas

By Optuma Team · Updated 2020-04-18

The following are examples of formulas that can be used for backtesting, scanning, watchlist analysis columns, etc. Also, be sure to check out the forum where you can see other examples and post questions:

Optuma Scripting Forum

CLOSE() >= HIGHESTHIGH(RANGE=LOOK BACK PERIOD,BARS=252)
CLOSE() >= LOWESTLOW(RANGE=LOOK BACK PERIOD,BARS=252)
TIMESINCESIGNAL(CLOSE()>HIGHESTHIGH(BARS=252))

Relative Performance to Index Over Last 6 Months

Section titled “Relative Performance to Index Over Last 6 Months”
RIC(DATESEL=Last 6 Months, INDEX=[index]) - 100
CLOSE() >= (HIGHESTHIGH(RANGE=LOOK BACK PERIOD,BARS=260)*0.98)

Close more than 5% above or below the 20SMA

Section titled “Close more than 5% above or below the 20SMA”
(CLOSE() > (MA(BARS=20, CALC=Close) * 1.05)) OR (CLOSE() Volume Greater than 20 Day Average VOLUME() > MA(VOLUME(),BARS=20, CALC=CLOSE,0)

Current 12 Period Exponential Mvg Avg is Higher than the Previous Value i.e. Mvg Avg is sloping up

Section titled “Current 12 Period Exponential Mvg Avg is Higher than the Previous Value i.e. Mvg Avg is sloping up”
MA(BARS=12, STYLE=Exponential, CALC=Close) IsUp

Higher high and higher low, but the close is both below the open and in the lower half of the range:

(HIGH() > HIGH(1)) AND (((LOW() > LOW(1)) AND (CLOSE() < OPEN())) AND (CLOSE() < ((HIGH() + LOW()) / 2)))

This formula will notify you of the third consecutive higher Gann swing low: ``` GS1 = GANNSWING(); SWINGUP(GS1) and (SWINGSTART(GS1) > SWINGSTART(GS1, 2))and (SWINGSTART(GS1, 2) > SWINGSTART(GS1, 4))and (SWINGSTART(GS1, 1) > SWINGSTART(GS1, 3))

### Relative Rotation Graphs
Codes in the Leading Sector which have turned down:

(JDKRS(DEFAULT=Quadrant, INDEX=[comparison index]) == 0) and (JDKRS(DEFAULT=Momentum, INDEX=[comparison index]) TurnsDown)

### Relative Index Comparison Crosses Above it's 20 day Moving Average

RIC(INDEX=SPX:WI) CrossesAbove MA(RIC(INDEX=SPX:WI), BARS=20, CALC=Close)

### 5th Consecutive Close Above 34 EMA after Crossing

CLOSE(5) CLOSE(4) > OFFSET(MA(BARS=34, STYLE=Exponential),4) and CLOSE(3) > OFFSET(MA(BARS=34, STYLE=Exponential),3) and CLOSE(2) > OFFSET(MA(BARS=34, STYLE=Exponential),2) and CLOSE(1) > OFFSET(MA(BARS=34, STYLE=Exponential),1) and CLOSE() > MA(BARS=34, STYLE=Exponential)

### 3 Consecutive Higher Closes each on Higher Volume Than Day Before

DU()==3 and DU(VOLUME())==3

### Relative Volume
For example, to compare the relative volume of your chart to that of the S&P500 Index in a Show View:

VOL() / VOL(GETDATA(CODE=SPY:WI))

### Close - Square Root
When used as a new Script Tool, this formula draws a line one square root away from the closing price, ie a close or 100 will plot the tool at 90.

CLOSE() - SQRT() CLOSE() - SQRT(HIGH()) for the square root of the high

Choose which categories of cookies you allow. Strictly-necessary cookies are always on. You can change this any time via the "Cookie Settings" link in the footer.

  • Functional

    Remember preferences like dismissed banners and your dark-mode choice.

  • Analytics

    Help us understand how the site is used so we can improve it.

  • Marketing

    Measure our advertising and help us reach people who may be interested in Optuma.