MichelT

Workaround for Arrays in pine and Bubble sort

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 bubble 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.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?