3

Context: I have a list of transactions (trades) in a csv file. I like to import these transactions into R and then plot the trades on the chart so that I can see visually the entries and exits. I finally figured the import part (from amzn_test.R in blotter demo) but having difficulty in changing color for plotted trade markers on the chart.

I noticed that the colors are currently fixed for the trade markers in source code for chart.Posn.R (package:blotter). (Filename: chart.Posn.R, Code URL: https://r-forge.r-project.org/scm/viewvc.php/pkg/blotter/R/chart.Posn.R?view=markup&root=blotter)

if(!is.null(nrow(Buys)) && nrow(Buys) >=1 ) (add_TA(Buys,pch=2,type='p',col='green', on=1));
    if(!is.null(nrow(Sells)) && nrow(Sells) >= 1) (add_TA(Sells,pch=6,type='p',col='red', on=1));

Question: Is there any way I can override these colors? If I cannot is there any way I can change the background chart theme to black so that the trade markers are visible better? I tried various ways to set the chartTheme but ran into errors.

To reproduce error, execute following blotter amzn_test demo code fragment and then the custom code.

Demo code:

require(blotter)

# Remove portfolio and account data if run previously
try(rm("portfolio.amzn_port","account.amzn_acct",pos=.blotter))

# load the example data
data("amzn")
currency("USD")
stock("amzn",currency="USD",multiplier=1)
# Initialize the Portfolio
initPortf("amzn_port",symbols="amzn",initDate="2010-01-14")
initAcct("amzn_acct",portfolios="amzn_port",initDate="2010-01-14", initEq=10000)
# look at the transactions data
amzn.trades
# Add the transactions to the portfolio
blotter:::addTxns("amzn_port","amzn",TxnData=amzn.trades,verbose=TRUE)

# update the portfolio stats
updatePortf("amzn_port",Dates="2010-01-14")

# update the account P&L
updateAcct("amzn_acct",Dates="2010-01-14")

# and look at it
chart.Posn("amzn_port","amzn",Dates="2010-01-14")

Custom Code:

> black_theme = chartTheme("black")
> chart.Posn("amzn_port","amzn",Dates="2010-01-14", theme=chartTheme("black"))
Error in if (theme$lylab) { : argument is of length zero
> 

I appreciate very much if anyone can guide me on how to solve this.

Regards,

GSee
  • 48,880
  • 13
  • 125
  • 145
Atrad
  • 85
  • 6
  • 2
    `chart.Posn` uses `chart_Series`, which is not compatible with `chartTheme`. Instead you would use `chart_theme`. I think you're supposed to be able to do this `thm <- chart_theme(); thm$col$bg <- 'black'; chart.Posn("amzn_port","amzn",Dates="2010-01-14", theme=thm)`. However, I think this is a bug (or not yet a working feature). – GSee Nov 06 '12 at 23:58
  • Hi GSee - Thanks. I think this would be great functionality to have. One common problem with many trading platforms when it comes to multi-symbol strategies (like rotation or paired switching) etc, is they don't allow a trader to see the strategy entries, exits and trails tops on the secondary charts. I think functionality to plot (markers and custom background) on secondary charts (on price panel) would be useful to many traders who rely more on TA and charts. – Atrad Nov 07 '12 at 18:20
  • I filed a [bug report](https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2357&group_id=125&atid=544), but I wouldn't hold my breath. – GSee Nov 07 '12 at 18:23

0 Answers0