[R-SIG-Finance] Overlaying OBV on Volume chart

Joshua Ulrich josh.m.ulrich at gmail.com
Mon Jan 6 20:46:10 CET 2014


On Mon, Jan 6, 2014 at 1:29 PM,  <manojit_roy at comcast.net> wrote:
> I'm trying to overlay OBV on the volume subplot using the code below:
>
>> getSymbols('AAPL',from='2013-6-1')
>> chartSeries(AAPL,type='candlesticks',TA='addVo()',theme='white')
>> addTA(OBV(Cl(AAPL),Vo(AAPL)),on=2)
>
> This does not work (all I get is a few vertical lines on the volume chart). Using addTA() without 'on=2' argument gives the correct OBV graph but on a separate subplot, as I would expect. Any help on how to do this is appreciated.
>
> Manojit
>
The problem is that you expect the function to automagically convert
your data to have the same y-axis range and/or to automagically adjust
the y-axis limits.  While chart_Series does the latter, I don't think
it gives the results you expect either.

> chart_Series(AAPL,TA='add_Vo()')
> add_TA(OBV(Cl(AAPL),Vo(AAPL)),on=2)

The most flexible solution is to adjust the data as you see fit:

> chartSeries(AAPL,type='candlesticks',TA='addVo()',theme='white')
> addTA(OBV(Cl(AAPL),Vo(AAPL))/1e7+16,on=2)

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-SIG-Finance mailing list