apozdnyakov

Sort pseudo-array

369 2 10
This pine script sorts pseudo-array a(). Kind of.
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study("Sort pseudo-array")
length = 5
a(i) => 
    close[i] + close[i+1]

sort(a, i) => 
    min = -10000
    for j = 0 to i
        min_local = 10000
        for l = 0 to length - 1
            if (a(l) <= min)
                continue
            min_local := min(min_local, max(min, a(l)))
        min := min_local
    min

plot(a(0))
plot(a(1))
plot(a(2))
plot(a(3))
plot(a(4))

plot(sort(a, 0), color=red, linewidth=3)
plot(sort(a, 1), color=orange, linewidth=3)
plot(sort(a, 2), color=green, linewidth=3)
plot(sort(a, 3), color=blue, linewidth=3)
plot(sort(a, 4), color=purple, linewidth=3)
Cool script. Every once a while a(4) gets 10,000 value, and even a(3) gets 10,000, which is shown in the graph. I couldn't figure out why. Do you know? For example, try GLD, IWM, Joe
Reply
Yes, this script was just example. I believe it =10000 when two values are the same. Try this one
Sort pseudo-array v2
Reply
United States
United Kingdom
India
Deutschland
España
France
Việt Nam
Italia
Polska
Brasil
Россия
Türkiye
Indonesia
Malaysia
日本
한국
简体
繁體
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing Priority Support Ideas Published Followers Following Private Messages Chat Sign Out