@@ -19,6 +19,25 @@ const PLOT_ARROW_SIGNATURE = [
1919 'editable' , 'show_last' , 'display' , 'format' , 'precision' , 'force_overlay' ,
2020] ;
2121
22+ //prettier-ignore
23+ const PLOTBAR_SIGNATURE = [
24+ 'open' , 'high' , 'low' , 'close' , 'title' , 'color' , 'editable' , 'show_last' , 'display' , 'format' , 'precision' , 'force_overlay' ,
25+ ] ;
26+
27+ //prettier-ignore
28+ const PLOTCANDLE_SIGNATURE = [
29+ 'open' , 'high' , 'low' , 'close' , 'title' , 'color' , 'wickcolor' , 'editable' , 'show_last' , 'bordercolor' , 'display' , 'format' , 'precision' , 'force_overlay' ,
30+ ]
31+ //prettier-ignore
32+ const BGCOLOR_SIGNATURE = [
33+ 'color' , 'offset' , 'editable' , 'show_last' , 'title' , 'display' , 'force_overlay' ,
34+ ] ;
35+
36+ //prettier-ignore
37+ const BARCOLOR_SIGNATURE = [
38+ 'color' , 'offset' , 'editable' , 'show_last' , 'title' , 'display'
39+ ] ;
40+
2241//prettier-ignore
2342const PLOT_ARGS_TYPES = {
2443 series : 'series' , title : 'string' , color : 'string' , linewidth : 'number' ,
@@ -43,6 +62,33 @@ const PLOT_ARROW_ARGS_TYPES = {
4362 format : 'string' , precision : 'number' , force_overlay : 'boolean' ,
4463} ;
4564
65+ //prettier-ignore
66+ const PLOTBAR_ARGS_TYPES = {
67+ open : 'series' , high : 'series' , low : 'series' , close : 'series' ,
68+ title : 'string' , color : 'string' , editable : 'boolean' , show_last : 'number' , display : 'string' ,
69+ format : 'string' , precision : 'number' , force_overlay : 'boolean' ,
70+ } ;
71+
72+ //prettier-ignore
73+ const PLOTCANDLE_ARGS_TYPES = {
74+ open : 'series' , high : 'series' , low : 'series' , close : 'series' ,
75+ title : 'string' , color : 'string' , wickcolor : 'string' , bordercolor : 'string' ,
76+ editable : 'boolean' , show_last : 'number' , display : 'string' ,
77+ format : 'string' , precision : 'number' , force_overlay : 'boolean' ,
78+ } ;
79+
80+ //prettier-ignore
81+ const BGCOLOR_ARGS_TYPES = {
82+ color : 'string' , offset : 'number' , editable : 'boolean' , show_last : 'number' ,
83+ title : 'string' , display : 'string' , force_overlay : 'boolean' ,
84+ } ;
85+
86+ //prettier-ignore
87+ const BARCOLOR_ARGS_TYPES = {
88+ color : 'string' , offset : 'number' , editable : 'boolean' , show_last : 'number' ,
89+ title : 'string' , display : 'string' ,
90+ } ;
91+
4692export class PlotHelper {
4793 constructor ( private context : any ) { }
4894 private extractPlotOptions ( options : PlotCharOptions | PlotShapeOptions ) {
@@ -102,16 +148,19 @@ export class PlotHelper {
102148
103149 //in the current implementation, plot functions are only used to collect data for the plots array and map it to the market data
104150 plotchar ( ...args ) {
105- // if (!this.context.plots[title]) {
106- // this.context.plots[title] = { data: [], options: this.extractPlotOptions(options), title };
107- // }
108- // const value = Series.from(series).get(0);
109- // this.context.plots[title].data.push({
110- // time: this.context.marketData[this.context.idx].openTime,
111- // value: value,
112- // options: { ...this.extractPlotOptions(options), style: 'char' },
113- // });
114- this . any ( ...args ) ;
151+ const _parsed = parseArgsForPineParams < PlotOptions > ( args , PLOT_SIGNATURE , PLOT_ARGS_TYPES ) ;
152+ const { series, title, ...others } = _parsed ;
153+ const options = this . extractPlotOptions ( others ) ;
154+ if ( ! this . context . plots [ title ] ) {
155+ this . context . plots [ title ] = { data : [ ] , options : { ...options , style : 'char' } , title } ;
156+ }
157+
158+ const value = Series . from ( series ) . get ( 0 ) ;
159+
160+ this . context . plots [ title ] . data . push ( {
161+ time : this . context . marketData [ this . context . idx ] . openTime ,
162+ value : value ,
163+ } ) ;
115164 }
116165
117166 //this will map to plot() - see README.md for more details
@@ -184,6 +233,69 @@ export class PlotHelper {
184233 : undefined ,
185234 } ) ;
186235 }
236+
237+ plotbar ( ...args ) {
238+ const _parsed = parseArgsForPineParams < PlotBarOptions > ( args , PLOTBAR_SIGNATURE , PLOTBAR_ARGS_TYPES ) ;
239+ const { open, high, low, close, title, ...others } = _parsed ;
240+ const options : PlotBarOptions = this . extractPlotOptions ( others ) ;
241+ if ( ! this . context . plots [ title ] ) {
242+ this . context . plots [ title ] = { data : [ ] , options : { ...options , style : 'bar' } , title } ;
243+ }
244+
245+ const value = [ Series . from ( open ) . get ( 0 ) , Series . from ( high ) . get ( 0 ) , Series . from ( low ) . get ( 0 ) , Series . from ( close ) . get ( 0 ) ] ;
246+
247+ this . context . plots [ title ] . data . push ( {
248+ time : this . context . marketData [ this . context . idx ] . openTime ,
249+ value : value ,
250+ options : { color : options . color } ,
251+ } ) ;
252+ }
253+
254+ plotcandle ( ...args ) {
255+ const _parsed = parseArgsForPineParams < PlotCandleOptions > ( args , PLOTCANDLE_SIGNATURE , PLOTCANDLE_ARGS_TYPES ) ;
256+ const { open, high, low, close, title, ...others } = _parsed ;
257+ const options : PlotCandleOptions = this . extractPlotOptions ( others ) ;
258+ if ( ! this . context . plots [ title ] ) {
259+ this . context . plots [ title ] = { data : [ ] , options : { ...options , style : 'candle' } , title } ;
260+ }
261+
262+ const value = [ Series . from ( open ) . get ( 0 ) , Series . from ( high ) . get ( 0 ) , Series . from ( low ) . get ( 0 ) , Series . from ( close ) . get ( 0 ) ] ;
263+
264+ this . context . plots [ title ] . data . push ( {
265+ time : this . context . marketData [ this . context . idx ] . openTime ,
266+ value : value ,
267+ options : { color : options . color , wickcolor : options . wickcolor , bordercolor : options . bordercolor } ,
268+ } ) ;
269+ }
270+
271+ bgcolor ( ...args ) {
272+ const _parsed = parseArgsForPineParams < BackgroundColorOptions > ( args , BGCOLOR_SIGNATURE , BGCOLOR_ARGS_TYPES ) ;
273+ const { title, ...others } = _parsed ;
274+ const options : BackgroundColorOptions = this . extractPlotOptions ( others ) ;
275+ if ( ! this . context . plots [ title ] ) {
276+ this . context . plots [ title ] = { data : [ ] , options : { ...options , style : 'background' } , title } ;
277+ }
278+
279+ this . context . plots [ title ] . data . push ( {
280+ time : this . context . marketData [ this . context . idx ] . openTime ,
281+ value : options . color && options . color !== 'na' && options ?. color . toString ( ) !== 'NaN' ,
282+ options : { color : options . color } ,
283+ } ) ;
284+ }
285+ barcolor ( ...args ) {
286+ const _parsed = parseArgsForPineParams < BarColorOptions > ( args , BGCOLOR_SIGNATURE , BGCOLOR_ARGS_TYPES ) ;
287+ const { title, ...others } = _parsed ;
288+ const options : BarColorOptions = this . extractPlotOptions ( others ) ;
289+ if ( ! this . context . plots [ title ] ) {
290+ this . context . plots [ title ] = { data : [ ] , options : { ...options , style : 'barcolor' } , title } ;
291+ }
292+
293+ this . context . plots [ title ] . data . push ( {
294+ time : this . context . marketData [ this . context . idx ] . openTime ,
295+ value : options . color && options . color !== 'na' && options ?. color . toString ( ) !== 'NaN' ,
296+ options : { color : options . color } ,
297+ } ) ;
298+ }
187299}
188300
189301export class HlineHelper {
0 commit comments