apozdnyakov

Sort pseudo-array

136 0 8
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)
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out