Coding an oscillator using OHLC
Author: mkt_ronin
Creation Date: 9/27/2011 8:39 PM
profile picture


I've been trying to program an oscillator for a few hours and frankly, I just barely know the rudiments of programming in WealthLab, at best!

The oscillator is a 13 day average (including the bar it lands on) but if that can be a variable input that would be great:

OSC = ((High - Open) + (Close - Low)) / (2 * (High - Low))

This is how I did it in TOS but that is not anywhere near as powerful as WL, which I prefer to run:

declare lower;
# def OSC1 = ((High - Open) + (Close - Low)) / (2 * (High - Low));

input length = 13;
Plot OSC1 = Average(((High - Open) + (Close - Low)) / (2 * (High - Low)),length);


If anyone can do that I think you might find it useful and I'd appreciate being able to use it on all time frames.

profile picture


The oscillator itself is:
Please log in to see this code.

Variable input version:
Please log in to see this code.
profile picture


Thank you so much, Eugene! It's very much appreciated.

I just had one other thought in how to implement this more easily across a wide range of trading vehicles and I am unsure of how to do so, or if it is possible to save the above as a standalone indicator to pull up and add to open strategies/charts. I've looked through the User Guide and can;t find how to make this a standalone indicator, if at all possible.

WealthLab has TASC Indicators to put on charts as well as WealthLab's own ones that are their own and standard TA ones from the "Tools" menu. And this question is likely going to show how I barely know how to use WealthLab.

Can this be used in some way as they are used to take a chart and then pull-up this oscillator (preferably the one that allows the length to be changed ) into a chart window that you already have open and have or have not worked on? Here is an example of one chart I have setup with averages and bands. Is it possible to add that oscillator to the chart along with what you will see is the the MACD and RSI in this snapshot?

I don't know if you trade, but someone I know who is very good with cycles never fails to look at this oscillator in 30 min, 60 min, and daily charts. He only does some simple programming in Excel and imports it all at the end of the day as he is a position trader. I'm going to suggest he start looking at Wealthlab given that you were good enough to write this out for me.


profile picture


Yes it could be transformed into a formal indicator. We have the Community Indicators library especially for such cases. However, it's not ready for inclusion in Community Indicators:

1. No name
2. No description/objective
3. As with any simple formula, it could've been invented before and already available as a known indicator
4. Barely fits the minimum requirement:
We'll accept custom indicators that require logical operations to populate the DataSeries or those that involve a minimum of 4 simple math operations.

In your case I'd recommend including the oscillator code to the default strategy template. So every new strategy window (not a chart but strategy) comes up with this code.

Edit Menu > Set as Default Template Code
profile picture


I'm taking a guess that #3 is already true, if you mean that someone already has written this somewhere as it seems too simple to have not been previously "invented"

I'll try the other way you suggested.

Thank you,

EDIT: WOW...took 3 minutes to do exactly what I wanted. I can go to bed now.

Thanks Eugene!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).