Click here to Login





                                                   Pretty oscillators (RSI, ...)

Back to threads - Tags: --
  0

0
pilow
2014-10-13 10:18:17


Hi,

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

======================================================================
oscillator = rsi(20);

lowBound = 40;
highBound = 60;
oscilMax = 80;
oscilMin = 20;


/*
-------------------------------------------------------------------
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);

Plot(a, "", colorGreen|50, 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);






QuantShare
2014-10-14 03:31:00

  0

Very nice. Thank you for sharing.


QuantShare
2014-10-28 04:04:36

  0

Another way to do the same thing:

oscillator = rsi(20);
lowBound = 40;
highBound = 60;

plot(oscillator, "Choppiness Index", colorGray);

// hatch underneath it
plot1(max(oscillator, highBound), highBound, "", "", colorTransparent, colorRed, colorGray, ChartLine, StyleSymbolNone);
SetHatchBrush("BackwardDiagonal", colorRed); // hatch upper zone

plot1(min(oscillator, lowBound), lowBound, "", "", colorTransparent, colorGreen, colorGray, ChartLine, StyleSymbolNone);
SetHatchBrush("BackwardDiagonal", colorGreen); // hatch lower zone



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
China stock market
Ehlers Decycler Oscillator
Standard Deviation of Monthly/Yearly Returns
Return Since a Specific Condition Occurred
RSI Predictor

How-to Lessons
How to create a correlation matrix of several securities
How to run a screen or a watchlist from a script
How to drag & drop a stock to a static watchlist
How to automate the data downloading process
How to quickly add several positions to your portfolio

Related Forum Threads
How to export to metastock ascii, 10 or 11 Format
Bulk Updater
Watchlists
Plot Threshold Lines
Books

Blog Posts
New Ranking and Percentile Composite Functions
Getting Accurate Backtesting Results: Survivorship bias-free S&P ...
How to predict and trade the stock market using pivot points
How to choose which technical indicators to use in your trading s...
Update Chart Layout based on Active Ticker Symbol









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



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.