Examples of Scripting Formulas

Author: Optuma Team Last updated: Apr 18, 2020 01:05

Overview

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

Examples

52 Week Highs

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

52 Week Lows

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

Days Since New 52 Week High

TIMESINCESIGNAL(CLOSE()>HIGHESTHIGH(BARS=252))

Relative Performance to Index Over Last 6 Months

RIC(DATESEL=Last 6 Months, INDEX=[index]) - 100

Close within 2% of 52 Week Highs

CLOSE() >= (HIGHESTHIGH(RANGE=LOOK BACK PERIOD,BARS=260)*0.98)

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

MA(BARS=12, STYLE=Exponential, CALC=Close) IsUp

Bearish Reversal

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)))

3 Higher Gann Swing Lows

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