MichelT

Insertion sort and binary search

The script shows a workaround for arrays in pine-script via drawings.
There are few restrictions with them:
1. The length of the array cannot be more that amount of allowed drawings (about 40 by now)
2. Because the "array" shares the space of drawings throughout the whole script, using drawings with the "array" must be careful, with handly creating and removing of each drawing, because otherwise pine's garbage collector might break the "array"
3. Getter and Setter must be called on every bar, because of implementation of functions in pine there are inner serieses, which must be updated on every bar. So wherever you have a setter or getter in the code - it must be called on every bar. But if it's just an update, then you should pass 'false' as a param of the funtion.

The script also shows an example of implementation of Insertion sort of the array in pine: when the array have been created, it's filled with pseudo-random numbers and sorted on every bar. There are plotting of the array's numbers before/after soring to show the sorting result.

There's also an example of implementation of binary search: after generation elements of the array, the first element is kept in local variable and after sorting of the array, the scripts is looking for new element's position via binary search and then plot that new index in an array (last plotted value with the green color)
Skrip sumber terbuka

Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.

Ingin menggunakan skrip ini pada carta?