Here is a new oscillator made of a cycle calculation of the median price calculated from the highest high and lowest low of the last x periods.
An adaptive period formula can be activated to calculate the “best” period of the hi/lo channel because of market noises.
I added 4 different returned buffers to identify when the oscillator is increasing or declining above of below the 0 level which represent the bull/bear side of the market.
// parameters
// myPeriod = 21
// Adaptive = 1 //boolean
once f = 0
once g = 0
if barindex>myPeriod then
//adaptive period
averagePeriod = myPeriod
if adaptive=1 and averagePeriod > 1 then
price = medianprice
minPeriod = round(averagePeriod/2.0)
maxPeriod = minPeriod*5.0
endPeriod = round(maxPeriod)
signal = Abs((price-stored[endPeriod]))
noise = 0.00000000001
for k=1 to endPeriod do
noise=noise+Abs(price-stored[k])
averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)
next
endif
stored=price
averageperiod=max(averageperiod,2)
myHigh = Highest[abs(averagePeriod)](high)
myLow = Lowest[abs(averagePeriod)](Low)
mean = (High + Low) / 2.0
myVAR1 = 0.66 * ((mean - myLow) / (myHigh - myLow) - 0.5) + 0.67 * f
myVAR1 = Min(Max(myVAR1, -0.999), 0.999)
fxhilo = Log((myVAR1 + 1.0) / (1 - myVAR1)) / 2.0 + g / 2.0 //main line
f = myVAR1
g = fxhilo
if fxhilo>fxhilo[1] and fxhilo>0 then
plusone = fxhilo
plustwo = 0
minusone = 0
minustwo = 0
elsif fxhilo<fxhilo[1] and fxhilo>0 then
plusone = 0
plustwo = fxhilo
minusone = 0
minustwo = 0
elsif fxhilo>fxhilo[1] and fxhilo<0 then
plusone = 0
plustwo = 0
minusone = fxhilo
minustwo =0
elsif fxhilo<fxhilo[1] and fxhilo<0 then
plusone = 0
plustwo = 0
minusone = 0
minustwo = fxhilo
endif
endif
RETURN plusone coloured(0,255,0), plustwo coloured(0,155,0), minusone coloured(150,0,0), minustwo coloured(255,0,0), 0 as "0 level"