Bar within % of MA

Trying to write a script to show the last bar within a certain percentage of a MA.

Like this: [today’s close < today’s SMA(80,close) * 1.02]
and [today’s close > today’s SMA(80,close) * 0.98]

I don’t see an option in Optuma for multiplication, so I’ve tried to run the script like this as the results would be similar.

MA1 = MA(BARS=78); MA2 = MA(BARS=82) ; CLOSE() < MA1 CLOSE() > MA2

Unfortunately, I’m pulling zero results… The pain of learning scripting manager.

Hi,

The WithinRange() function allows you to find where a value is within x% of another value. For example a Close within 2% of a Moving Average.

V1 = CLOSE() ;
V2 = MA(BARS=80) ;
WITHINRANGE(V1,V2, PERCENT=2.00)

The shaded green zone in the following example shows where the script triggers, when the Close is within 2% of the 80SMA (within the blue dashed lines).

Ex6

More information: https://help.optuma.com/kb/faq.php?id=1038

Thank you! It’s always a bit difficult learning a new scripting format.

Hi Terry,

Just to let you know that * should be used to multiply, so this would work as well to define the 2% band:

CLOSE()>(MA(BARS=80, CALC=Close)*0.98) and
CLOSE()<(MA(BARS=80, CALC=Close)*1.02)

For a free scripting tutorial course sign in here:

https://learn.optuma.com/scripting-courses/