' Sort resultsIndex based on the values of the results series.
SortSeriesDual( resultsIndex, results, elementsToSort, elementsToSort, -1 )
' Sort the series element in descending order.
SortSeries( results, elementsToSort, elementsToSort, -1 )
This is an example of how a dual series numeric series can be used:
' ==============================================================
' _SortDualSeries_Example
' BEFORE TEST SCRIPT - START
' ==============================================================
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Create Character Spaces for Symbol Padding
iTxtLen = 5
sPad = ""
For x = 1 TO iTxtLen STEP 1
sPad = sPad + " "
Next ' x
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Determine How Many Symbols to Create
SymbolCount = system.totalInstruments
' Size Series To Symbol Count
SetSeriesSize(Series1, SymbolCount)
SetSeriesSize(Series2, SymbolCount)
SetSeriesSize(Series3, SymbolCount)
SetSeriesSize(Series4, SymbolCount)
PRINT
PRINT "Random Seed Value = ", RandomSeed(1)
PRINT
PRINT "--------------------------------------------"
PRINT "GENERATE RANDOM NUMBERS"
PRINT "--------------------------------------------"
PRINT
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Build Sample Dual Data Series
For x = 1 TO SymbolCount STEP 1
' Load Each Symbol in the Portfolio
Load_OK = Mkt.LoadSymbol( x )
' Assign Values to Each Series
Series1[x] = x
Series2[x] = Random( 0, 30000 ) * 0.001
' Randomly Convert To Negative Value
If Random(1, 10) < 5 THEN Series2[x] = Series2[x] * -1
' Duplicate Series2 Values in Series3
Series3[x] = Series2[x]
' Provide Character Third Column Sort
sTxt1 = Mkt.symbol
sTxt1 = sTxt1 + Left(sPad, iTxtLen - Len(sTxt1))
snum = ""
For y = 1 TO Len(sTxt1) STEP 1
snum = snum + ASCII(mid(sTxt1, y, 1))
Next ' y
Series4[x] = AsFloating(snum)
' Show Assembled Random Character Symbol
PRINT AsString(x,0), " - ", _
Series1[x], " - ", _
Series2[x], " - ", _
Series3[x], " - ", _
Series4[x], " - ", _
sTxt1
Next ' x
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRINT
PRINT "--------------------------------------------"
PRINT "SortSeriesDual"
PRINT "--------------------------------------------"
PRINT
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' PERFORM DUAL SERIES SORTING STEPS
' Sort Series1 based on the values in Series2
SortSeriesDual( Series1, Series2, SymbolCount, SymbolCount, 1 )
' To Finish DualSort, sort the results of Series2 to Match
' the sorted index in Series1.
SortSeries( Series2, SymbolCount, SymbolCount, 1 )
' Sort Series4 based on the values in Series3
SortSeriesDual( Series4, Series3, SymbolCount, SymbolCount, 1 )
' To Finish DualSort, sort the results of Series4 to Match
' the sorted index in Series1.
SortSeries( Series3, SymbolCount, SymbolCount, 1 )
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' SHOW SORTED RESULTS
' Display Column Titles
PRINT "Count", " - ", "GrpNdex", _
" - ", "Data 1", _
" - ", "Data 2"
' Display Sorted Series2 and the Aligned Series1 Index
For x = 1 TO SymbolCount STEP 1
' Get the series reference
sNum = AsString(Series4[x], 0)
Load_OK = Len(sNum)
sTxt1 = ""
For y = 1 TO Len(sNum) STEP 2
sTxt1 = sTxt1 + mid(sNum, y, 2)
Next ' y
PRINT AsString(x,0), " - ", AsString(Series1[x], 0), _
" - ", AsString(Series2[x], 3), _
" - ", Series4[x], _
" - ", sTxt1 )
Next ' x
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ==============================================================
' BEFORE TEST SCRIPT - END
' _SortDualSeries_Example
' ==============================================================
SortSeriesDual Usage Example The the link on the left to access the above example that is a posted in the Trading Blox Marketplace section.
|