Guest User

Cumulative_Delta_Bars

a guest
Oct 2nd, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CumulativeDeltaBarsCalculator(data, options){
  2.   var deltaOpen = 0
  3.   data.forEach(function(d, idx){    
  4.     var delta = d.buyVolume - d.sellVolume
  5.     delta = delta
  6.     var deltaClose = parseFloat((deltaOpen+delta).toFixed(2))
  7.    
  8.    
  9.     data[idx].cdbars = [deltaOpen, Math.max(deltaOpen, deltaClose), Math.min(deltaOpen, deltaClose), deltaClose];
  10.    
  11.     deltaOpen = deltaClose
  12.   });
  13.  
  14.   return data;
  15. }
  16.  
  17. plotStudy({
  18.     type: "candlesticks",
  19.     name: "Cumulative Delta Bars",
  20.     fill: function(d){ return  d.close<d.open ? "#00ff00" : "#ff0000"},  
  21.     stroke: function(d){ return  d.close<d.open ? "#00ff00" : "#ff0000"},
  22.     valueColor:"#ffffff",
  23.     calculator: CumulativeDeltaBarsCalculator,
  24.     options:{
  25.         yAccessor: function(d){return { open: d.cdbars[0], high: d.cdbars[1], low: d.cdbars[2], close: d.cdbars[3] }},
  26.     },
  27.     chartId: "cdbars"
  28.  
  29. })
Advertisement
Add Comment
Please, Sign In to add comment