| fg_signal_to_events | R Documentation |
Event Helpers: fg_signal_to_events
fg_signal_to_events(signal_df, colormap)
signal_df |
A two-column |
colormap |
A two column |
This helper applies run-length encoding to match the signal in signal_df to the color in colormap
data.table suitable for passing into fgts_dygraph() via the event_ds parameter
# A simple moving average strategy with threshold
require(data.table)
ma_signal<-eqtypx[,.(date,sig=cut(frollmean(EEM,5)-frollmean(EEM,20),
c(-10,-0.5,0.5,10),labels=c("long","flat","short")),EEM)]
colormap<-data.frame(sig=c("long","flat","short"),color=c("#f56462","white","#6161ff"))
fgts_dygraph(eqtypx[,.(date,EEM)],event_ds=fg_signal_to_events(ma_signal,colormap),
dtstartfrac=0.8,roller=1,title="5/20 MA positions")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.