I am using the Williams R oscillator in my entry criteria. I want to optimize this level but the William's r oscillator uses values from -100 to 0. When I run the optimization, I get an error that the optimization values can not be a negative. Does anyone know of a work around for this? Thank you in advance.

```
WR = ( ( HHV(H,5) - Close ) / ( HHV(H,5) - LLV(L,5) ) ) * -100 ; //Williams %R
Buy= WR<Optimize("WR Level" , -80, -80, -95, -5) AND RSI(5) < Optimize("rsi Level", 10,5,30,5) ;
buyPrice= Close;
Sell= 1;
sellPrice= Close ;
```

@Rogerscott here are a couple of possible solutions for an indicator that runs from -100 to 0 (why did Williams decide to multiply by -100? ).

First, don't use Williams R, use the Stochastic K

@de.yudi.dy why bother coding yet another oscillator. Did you read an article somewhere that tells you how great it is? And what does this mean ??
I thought it was a standard indicator in AmiBroker (at least it's in my copy though I may have put in my own there and forgotten?),
[image]
The Williams %R is the inverse of the Fast Stochastic Oscillator without the usual smoothing. IMHO it is important that you understand the formula of any indicator you are using, especially simple ones.
…
Here would be a plot of your 5 bar William's vs the StochK(5,1)

Second possibility, manipulate your indicator (Williams R) by adding 100.

@CascadeEffect depending on what your Max value is, you could simple do a 100 - yourval and then optimize on the results.
Good luck and let us know how it goes.

2 Likes

Tomasz
February 24, 2023, 5:16pm
#3
You are calling Optimize() function incorrectly.

You CAN optimize negative values, but still minimum value needs to be less than maximum (in your code is reverse) and step must be postiive

```
x = Optimize("x", -80, -100, -50, 5 ); // values can be negative, but step > 0
```

2 Likes

Tomasz:

`Optimize("x", -80, -100, -50, 5 )`

Thank you very much for the knowledge!

Thank you very much for the knowledge!