I've been tinkering with the Plot function for a while in order to be able and Plot oscilators like this : https://i.imgur.com/YUPFJu0.png
Here is the commented formula (you can also view it here, it might be easier to read) : http://pastebin.com/Xqb4cu7H
You can use this formula "as is", just change the first 5 lines :
oscillator = ... // put your oscillator function here
lowBound = ... // low horizontal line under which we color the oscillator
highBound = ... // high horizontal line over which we color the oscillator
oscilMin = ... // default = 0 : forces the Plot to draw at least to that (low) level
oscilMax = ... // default = 100 : forces the Plot to draw at least to that (low) level
/*
-------------------------------------------------------------------
HIGH BOUNDARY of PLOT
PLOT `oscillator`, fill to zero with color/hatch, then plot
`highBound` line and fill to zero with Green
-------------------------------------------------------------------
*/
// first plot the oscillator
// if you want color filled zone, use :
plot(oscillator, "Choppiness Index", colorRed|50, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
// if you dont want a color filled zone, use :
//plot(oscillator, "Choppiness Index", colorLightGray);
// hatch underneath it
SetHatchBrush("BackwardDiagonal", colorRed); // hatch zone under index curve
Plot(highBound, "", colorWhite|255, ChartLine, StyleDotted|StyleNoScale|StyleWidth0); // erase all under `highBound` horiz line
/*
-------------------------------------------------------------------
LOW BOUNDARY of PLOT
PLOT segments of `lowBound` line where `choppiness` < `lowBound`
and fill to zero with Green
(we have to segment so as not to erase the previous plot of
highbound color fill/hatch)
-------------------------------------------------------------------
*/
// determine segments
a = iff(oscillator <= lowBound, lowBound, 0);
// if you wish to fill the zone with a single color instead of hatching it,
// replace following line with : Plot(a, "", colorGreen|55, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
// otherwise, use Plot(a, "", colorGreen, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
// hatch the zone (comment out if you do not want to hatch)
SetHatchBrush("BackwardDiagonal", colorGreen); // hatch zone under index curve
// erase all under `oscillator` in the zone where `oscillator` < `lowBound`
b = iff(oscillator <= lowBound, oscillator, 0);
Plot(b, "", colorWhite|255, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
/*
-------------------------------------------------------------------
MAIN CURVE
Finally, plot the whole curve again, and adapt colors of its
sections.
-------------------------------------------------------------------
*/
// refresh the oscillator line
plot(oscillator, "Choppiness Index", colorDarkGray);
// optionally : overwrite lowBound portion with custom color
testLow = oscillator < lowBound and oscillator[-1] < lowBound; // in order to have fastcross segments colored
updatecolor(testLow, colorDarkGreen);
testHigh = oscillator > highBound and oscillator[-1] > highBound; // in order to have fastcross segments colored
updatecolor(testHigh, colorDarkRed);
// finally plot the `highBound` and `lowBound` lines
Plot(highBound, 'high', colorLightGray, ChartLine,StyleDashed); // `highBound` horiz line
Plot(lowBound, 'low', colorLightGray, ChartLine,StyleDashed);
// and the oscilMax & oscilMin so as to frame the region
Plot(oscilMax, "", colorTransparent);
Plot(oscilMin, "", colorTransparent);
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.