Bar within % of MA

Optuma Forums Optuma Scripting Bar within % of MA

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #60103
    • Topics: 1
    • Replies: 1
    • Posts: 2

    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.

    • Topics: 5
    • Replies: 309
    • Posts: 314


    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.

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


    More information:

    • This reply was modified 3 weeks, 4 days ago by MatthewMatthew.
    • Topics: 1
    • Replies: 1
    • Posts: 2

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

    • Topics: 56
    • Replies: 478
    • Posts: 534

    Hi Terry,

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

    For a free scripting tutorial course sign in here:

Viewing 4 posts - 1 through 4 (of 4 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.