@@ -149,24 +149,24 @@ f_array_ops(_X, _Y, _op, _value)=>
149
149
array.clear(id=_Z)
150
150
_Z
151
151
152
- float byvalue = input(0)
153
- byvalue := byvalue == 0? na : byvalue
154
- float[] array_ops = f_array_ops(indices, prices, input(''), byvalue)
155
- bool show_debug = input(false)
156
- var label debug = label.new(bar_index, open, '')
157
- if show_debug
158
- label.set_xy(id=debug, x=bar_index, y=close)
159
- label.set_text(id=debug, text=tostring(indices, '#') + '\n' + tostring(prices) + '\n' + tostring(array_ops))
160
- else
161
- label.delete(id=debug)
152
+ // float byvalue = input(0)
153
+ // byvalue := byvalue == 0? na : byvalue
154
+ // float[] array_ops = f_array_ops(indices, prices, input(''), byvalue)
155
+ // bool show_debug = input(false)
156
+ // var label debug = label.new(bar_index, open, '')
157
+ // if show_debug
158
+ // label.set_xy(id=debug, x=bar_index, y=close)
159
+ // label.set_text(id=debug, text=tostring(indices, '#') + '\n' + tostring(prices) + '\n' + tostring(array_ops))
160
+ // else
161
+ // label.delete(id=debug)
162
162
163
163
164
164
f_array_mean(_id)=>
165
165
int _size = array.size(id=_id)
166
166
float _mean = array.sum(id=_id) / _size
167
167
168
- float mean = f_array_mean(prices)
169
- plot(mean, color=color.yellow, transp=50)
168
+ // float mean = f_array_mean(prices)
169
+ // plot(mean, color=color.yellow, transp=50)
170
170
171
171
f_array_standardize(_X)=>
172
172
//| returns standardized array values against the maximum range in the data set.
@@ -281,10 +281,10 @@ f_array_contains(_X, _value)=>
281
281
break
282
282
_return
283
283
284
- var float[] values = array.new_float(size=2, initial_value=1)
285
- array.push(id=values, value=2)
286
- int test_value = f_array_contains(values, input(0)) ? 1 : 0
287
- plot(test_value, color=color.yellow, transp=50)
284
+ // var float[] values = array.new_float(size=2, initial_value=1)
285
+ // array.push(id=values, value=2)
286
+ // int test_value = f_array_contains(values, input(0)) ? 1 : 0
287
+ // plot(test_value, color=color.yellow, transp=50)
288
288
289
289
f_array_index_of(_X, _value)=>
290
290
//| returns the index of the first element in the array that is equal to value:
@@ -397,7 +397,7 @@ f_array_linreg(_X, _Y)=>
397
397
_stdev := _stdev + abs(_diff)
398
398
[_predictions, _max_dev, _min_dev, _stdev/_sizeX]
399
399
400
- // [D, Dmax, Dmin, Dstdev] = f_array_linreg(indices, prices)
400
+ [D, Dmax, Dmin, Dstdev] = f_array_linreg(indices, prices)
401
401
402
402
// bool show_debug = input(false)
403
403
// var label debug = label.new(bar_index, open, '')
@@ -407,27 +407,27 @@ f_array_linreg(_X, _Y)=>
407
407
// else
408
408
// label.delete(id=debug)
409
409
410
- // color _ln_col = color.aqua
411
- // var line ln_mid = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_solid, width=2)
412
- // var line ln_max = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dotted, width=1)
413
- // var line ln_min = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dotted, width=1)
414
- // var line ln_upper = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dashed, width=1)
415
- // var line ln_lower = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dashed, width=1)
416
-
417
- // int first = input(0)
418
- // int last = input(9)
419
- // ln_y1 = array.get(id=D, index=first)
420
- // ln_y2 = array.get(id=D, index=last)
421
- // line.set_xy1(id=ln_mid, x=array.get(id=indices, index=first), y=ln_y1)
422
- // line.set_xy2(id=ln_mid, x=array.get(id=indices, index=last), y=ln_y2)
423
- // line.set_xy1(id=ln_max, x=array.get(id=indices, index=first), y=ln_y1 + Dmax)
424
- // line.set_xy2(id=ln_max, x=array.get(id=indices, index=last), y=ln_y2 + Dmax)
425
- // line.set_xy1(id=ln_min, x=array.get(id=indices, index=first), y=ln_y1 + Dmin)
426
- // line.set_xy2(id=ln_min, x=array.get(id=indices, index=last), y=ln_y2 + Dmin)
427
- // line.set_xy1(id=ln_upper, x=array.get(id=indices, index=first), y=ln_y1 + Dstdev)
428
- // line.set_xy2(id=ln_upper, x=array.get(id=indices, index=last), y=ln_y2 + Dstdev)
429
- // line.set_xy1(id=ln_lower, x=array.get(id=indices, index=first), y=ln_y1 - Dstdev)
430
- // line.set_xy2(id=ln_lower, x=array.get(id=indices, index=last), y=ln_y2 - Dstdev)
410
+ color _ln_col = color.aqua
411
+ var line ln_mid = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_solid, width=2)
412
+ var line ln_max = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dotted, width=1)
413
+ var line ln_min = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dotted, width=1)
414
+ var line ln_upper = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dashed, width=1)
415
+ var line ln_lower = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, color=_ln_col, style=line.style_dashed, width=1)
416
+
417
+ int first = input(0)
418
+ int last = input(9)
419
+ ln_y1 = array.get(id=D, index=first)
420
+ ln_y2 = array.get(id=D, index=last)
421
+ line.set_xy1(id=ln_mid, x=array.get(id=indices, index=first), y=ln_y1)
422
+ line.set_xy2(id=ln_mid, x=array.get(id=indices, index=last), y=ln_y2)
423
+ line.set_xy1(id=ln_max, x=array.get(id=indices, index=first), y=ln_y1 + Dmax)
424
+ line.set_xy2(id=ln_max, x=array.get(id=indices, index=last), y=ln_y2 + Dmax)
425
+ line.set_xy1(id=ln_min, x=array.get(id=indices, index=first), y=ln_y1 + Dmin)
426
+ line.set_xy2(id=ln_min, x=array.get(id=indices, index=last), y=ln_y2 + Dmin)
427
+ line.set_xy1(id=ln_upper, x=array.get(id=indices, index=first), y=ln_y1 + Dstdev)
428
+ line.set_xy2(id=ln_upper, x=array.get(id=indices, index=last), y=ln_y2 + Dstdev)
429
+ line.set_xy1(id=ln_lower, x=array.get(id=indices, index=first), y=ln_y1 - Dstdev)
430
+ line.set_xy2(id=ln_lower, x=array.get(id=indices, index=last), y=ln_y2 - Dstdev)
431
431
432
432
433
433
@@ -490,12 +490,80 @@ f_array_polyreg(_X, _Y)=>
490
490
[_predictions, _max_dev, _min_dev, _stdev/_sizeX]
491
491
492
492
493
- // [P, Pmax, Pmin, Pstdev] = f_array_polyreg(indices, prices)
494
-
495
- // color _pr_col = color.red
496
- // for _i = 0 to array.size(id=P)-2
497
- // _pr_y1 = array.get(id=P, index=_i)
498
- // _pr_y2 = array.get(id=P, index=_i+1)
499
-
500
- // line pr_mid = line.new(x1=array.get(id=indices, index=_i), y1=_pr_y1, x2=array.get(id=indices, index=_i+1), y2=_pr_y2, color=_pr_col, style=line.style_solid, width=2)
501
- // line.delete(id=pr_mid[1])
493
+ [P, Pmax, Pmin, Pstdev] = f_array_polyreg(indices, prices)
494
+
495
+ color _pr_col = color.red
496
+ var line pr_mid00 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
497
+ var line pr_mid01 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
498
+ var line pr_mid02 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
499
+ var line pr_mid03 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
500
+ var line pr_mid04 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
501
+ var line pr_mid05 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
502
+ var line pr_mid06 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
503
+ var line pr_mid07 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
504
+ var line pr_mid08 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
505
+ var line pr_mid09 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_solid, width=2)
506
+ var line pr_max00 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
507
+ var line pr_max01 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
508
+ var line pr_max02 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
509
+ var line pr_max03 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
510
+ var line pr_max04 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
511
+ var line pr_max05 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
512
+ var line pr_max06 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
513
+ var line pr_max07 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
514
+ var line pr_max08 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
515
+ var line pr_max09 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
516
+ var line pr_min00 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
517
+ var line pr_min01 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
518
+ var line pr_min02 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
519
+ var line pr_min03 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
520
+ var line pr_min04 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
521
+ var line pr_min05 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
522
+ var line pr_min06 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
523
+ var line pr_min07 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
524
+ var line pr_min08 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
525
+ var line pr_min09 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dotted, width=1)
526
+ var line pr_upper00 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
527
+ var line pr_upper01 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
528
+ var line pr_upper02 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
529
+ var line pr_upper03 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
530
+ var line pr_upper04 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
531
+ var line pr_upper05 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
532
+ var line pr_upper06 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
533
+ var line pr_upper07 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
534
+ var line pr_upper08 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
535
+ var line pr_upper09 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
536
+ var line pr_lower00 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
537
+ var line pr_lower01 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
538
+ var line pr_lower02 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
539
+ var line pr_lower03 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
540
+ var line pr_lower04 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
541
+ var line pr_lower05 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
542
+ var line pr_lower06 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
543
+ var line pr_lower07 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
544
+ var line pr_lower08 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
545
+ var line pr_lower09 = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, color=_pr_col, style=line.style_dashed, width=1)
546
+ f_pr_mid_line_selector(_i)=>(_i==0?pr_mid00:(_i==1?pr_mid01:(_i==2?pr_mid02:(_i==3?pr_mid03:(_i==4?pr_mid04:(_i==5?pr_mid05:(_i==6?pr_mid06:(_i==7?pr_mid07:(_i==8?pr_mid08:(_i==9?pr_mid09:pr_mid00))))))))))
547
+ f_pr_max_line_selector(_i)=>(_i==0?pr_max00:(_i==1?pr_max01:(_i==2?pr_max02:(_i==3?pr_max03:(_i==4?pr_max04:(_i==5?pr_max05:(_i==6?pr_max06:(_i==7?pr_max07:(_i==8?pr_max08:(_i==9?pr_max09:pr_max00))))))))))
548
+ f_pr_min_line_selector(_i)=>(_i==0?pr_min00:(_i==1?pr_min01:(_i==2?pr_min02:(_i==3?pr_min03:(_i==4?pr_min04:(_i==5?pr_min05:(_i==6?pr_min06:(_i==7?pr_min07:(_i==8?pr_min08:(_i==9?pr_min09:pr_min00))))))))))
549
+ f_pr_upper_line_selector(_i)=>(_i==0?pr_upper00:(_i==1?pr_upper01:(_i==2?pr_upper02:(_i==3?pr_upper03:(_i==4?pr_upper04:(_i==5?pr_upper05:(_i==6?pr_upper06:(_i==7?pr_upper07:(_i==8?pr_upper08:(_i==9?pr_upper09:pr_upper00))))))))))
550
+ f_pr_lower_line_selector(_i)=>(_i==0?pr_lower00:(_i==1?pr_lower01:(_i==2?pr_lower02:(_i==3?pr_lower03:(_i==4?pr_lower04:(_i==5?pr_lower05:(_i==6?pr_lower06:(_i==7?pr_lower07:(_i==8?pr_lower08:(_i==9?pr_lower09:pr_lower00))))))))))
551
+
552
+ int pr_fractions = 10
553
+ int pr_size = array.size(id=P)
554
+ int pr_step = max(pr_size / pr_fractions, 1)
555
+ for _i = 0 to pr_size - pr_step - 1 by pr_step
556
+ int _next_step_index = _i + pr_step
557
+ int _line = _i / pr_step
558
+
559
+ line.set_xy1(id=f_pr_mid_line_selector(_line), x=array.get(id=indices, index=_i), y=array.get(id=P, index=_i))
560
+ line.set_xy2(id=f_pr_mid_line_selector(_line), x=array.get(id=indices, index=_i + pr_step), y=array.get(id=P, index=_i + pr_step))
561
+ line.set_xy1(id=f_pr_max_line_selector(_line), x=array.get(id=indices, index=_i), y=array.get(id=P, index=_i) + Pmax)
562
+ line.set_xy2(id=f_pr_max_line_selector(_line), x=array.get(id=indices, index=_i + pr_step), y=array.get(id=P, index=_i + pr_step) + Pmax)
563
+ line.set_xy1(id=f_pr_min_line_selector(_line), x=array.get(id=indices, index=_i), y=array.get(id=P, index=_i) + Pmin)
564
+ line.set_xy2(id=f_pr_min_line_selector(_line), x=array.get(id=indices, index=_i + pr_step), y=array.get(id=P, index=_i + pr_step) + Pmin)
565
+ line.set_xy1(id=f_pr_upper_line_selector(_line), x=array.get(id=indices, index=_i), y=array.get(id=P, index=_i) + Pstdev)
566
+ line.set_xy2(id=f_pr_upper_line_selector(_line), x=array.get(id=indices, index=_i + pr_step), y=array.get(id=P, index=_i + pr_step) + Pstdev)
567
+ line.set_xy1(id=f_pr_lower_line_selector(_line), x=array.get(id=indices, index=_i), y=array.get(id=P, index=_i) - Pstdev)
568
+ line.set_xy2(id=f_pr_lower_line_selector(_line), x=array.get(id=indices, index=_i + pr_step), y=array.get(id=P, index=_i + pr_step) - Pstdev)
569
+
0 commit comments