OHLC HLC HL

Is there a quick way or function to get OHLC or HLC or HL instead of for example (OPEN + HIGH + LOW + CLOSE) / 4

It would be great if I could do OHLC - OHLC (1) for example.

Many thanks,

Hi Liam,

You can use a 1 period SMA to do this. In the example of OHLC you could use:

V1 = MA(BARS=1, CALC=OHLC) ;
V1 - V1[1]

I thought about that, many thanks,

Hi Liam, while Matthew’s response makes use of Optuma’s excellent in-built functions and is the most elegant method to achieve what you want, there is a longer alternative that might be useful to you:

OHLCAvg = (OPEN(0) + HIGH(0) + LOW(0) + CLOSE(0)) / 4;
OHLCAvg[0] - OHLCAvg[1]

Why would you care about this alternative? You might find that you need to apply a similar concept elsewhere if Optuma does not have an in-built function that you need. The shorthand bar index notation (last bar = [0] , second last bar = [1], etc.) can be extremely useful. It can also be very helpful for debugging purposes to explicitly use bar index notation at all times (e.g. OHLCAvg[0] instead of just OHLCAvg) because then there is no ambiguity on what the intent of the script is.

Carefully note that Open, High, Low, Close use parenthesis ‘(’, ‘)’ for their bar index notation, while variables use square brackets ‘[’, ‘]’ for their bar index notation.

Just some additional information and techniques to put into your scripting toolkit. :slight_smile:

Cheers, Dean

Many thanks Dean, I can see the use cases for both ways. Thanks for sharing.