Box contains a simple Test-Level String Array Example using numbers in a string format. Numbers were selected because they are the least understood when it comes to sorting strings that look like numbers. Numbers are generated using the Trading Blox Random Number generator. There are also options in this blox for changing how the numbers are sequenced, and for how they are stored in the string array.
Operation Notes: |
---|
When testing this blox, start off with the default settings to get an understanding of what it does. Once you've got a sense of how the blox operations, change the fix number option next so that the numbers will sort properly.
From here on, changes to the other parameters will help you get an understanding of how the character of the Trading Blox Random Number data series can change by changing the initial start value, or by changing the value of numeric Seed value supplied to the RandomSeed function.
When this blox is executed in a Simulation run, the only active script section is the Before Test Script. Before Test script location is the best place I've found for creating a Test-Level String array. It is also the best place for accessing selectable user parameters that can decide which scripts executes during a simulation run.
Any script section can be used to store, or access information in a Test-Level script once it has been created. There are no known restrictions on creating the Test-Level script array in other sections as long as you know it will be created before you need to store, or retrieve initialization information in the string array.
There are a lot of little script techniques available in this simple example along with the process for creating a Test-Level string array, storing data in each element in each column, sorting data in each column in either ascending, or descending orders, and for how to retrieve the values in each string element.
There are also some formatting techniques to make output more readable, or presentable for others. There are also two unique user functions. One user function is intended to return the value of the computer's time of day in the form of the number of seconds that have transpired since 12:00 AM midnight. This is useful for determining the differences between the two different times of the day, or even between days when a serialized date value is part of the calculations.
In the second function is a process for creating a unique random number seed value. To create a unique number the script function creates a date serialization process that uses an adjusted Julian date value appended to the value in the number of seconds from midnight. This unique number provides a good source for seeding the random number series with unique values so the random number generator will produce a unique series of number sequences each time the random number generator is operated.
|
User Parameters: |
Descriptions: |
---|---|
Random Series Sequencing |
In the default setting the numbers generated will always be the same for each simulation. This setting is using a fixed seed value. Fixed seed values initialize the Random Number series so that the same sequence of random numbers is generated each time the random number generator is accessed. Having a consistent number in a random series makes trouble shooting random number driven events easier to debug, but they aren't good for "Monte Carlo" type data methods.
A second option uses a unique number each time a series of numbers is generated. By using a unique seed value for each random number sequence the order of the numbers generated will not the be same for each simulation run. |
Random Number Start |
By default the settings use a small number to set the range of numbers that will be created for each series. This small number provides a higher probability that the range of random numbers in the sequence will be over a wider range of values. This was provided because of the limited number of numbers being generated to keep the example within tolerable reading range.
A larger start number is available to show that when the numbers have the same number of characters in their values, then the sorting option will sort those numbers correctly as long at the character count in a string number is the same for all string numbers. However, if the number of characters in the string-number changes, the sort operation is likely to not be sorted properly. |
Fix String Array Sorting |
First Option shows how numbers stored without regard for their ASCII character representation will not always sort correctly.
Second Option shows how to adjust for numbers that have different lengths so that when they are sorted they are in a correct ascending, or descending sequence. In the example shown, the number adjustments Are using variable number of leading zero values. However spaces, underscore characters could also have been used. There are other methods for adjusting string numbers, so if the examples aren't enough information, then try some math approaches, or post a question about your idea. |
Max Array Rows to Display |
Trading Blox has an upper limit of 10,000 rows that can be created with a Test-Level String Array.
However, each row will reserve memory space times that will equally the array element time the number of columns. In this example we are only using 2-columns. However, that can be changed by modifying the script code, and by adjusting how the loops handle the increased, or reduced number of column.
For this simple example, the minimum number of rows is set to 10-rows. You get to set the row count from any number between 5, and whatever value seems reasonable to scroll through once the blox has completed. |
Blox Use |
No Portfolio instruments are required to run this blox.
To test this blox, create a system name you want, or use the default system name "Chart" and attach this Blox. When this blox executes, it will generate information into the Trading Blox Log window on the Main screen of the program when the Log option under the Window menu item is selected. It will always generate and send information to the "Print Output.csv" file.
"Print Output.csv" file is easily opened using the Main menu File selection and then scrolling down until Result selection is highlighted. With the list visible, select the Print Output option and the output will appear in an Excel spreadsheet. While the data appears easily, it will look better if you access it with the Windows Notepad. File is in the Trading Blox Results folder and will easily open with Notepad, or WordPad. |
The code examples show ideas about the use of String Array Sorting. The examples execute the BEFORE TEST script section of the blox available in the Blox MarketPlace. When example code is executed it will produce something similar to the details shown below:
Example: |
---|
' ============================================================== |
Returns: |
---|
Blox: ,Example_String_Array_Sorting, Script Name: ,Before Test,
Computer Date & Time: ,2014-03-04, ,1:47:38 PM,
String Array Creation & String Number Sorting Examples,
PARAMETERS:, Array Rows : ,10, Random Start #: ,100.000000000, Fix # Sorting : ,DO NOT Fix Number Sorting, Seed Number : ,0.000000000,
ARRAY DEFAULTS:, String Element Size : ,512, Array Column Count : ,100,
-----------------------------------------------------------, String Array Created with 100 Columns, and 10 Element Rows.,
Generating Alpha-Numeric Data for Column 1 Rows:, 1, 55.33, in Row 1, 2, 59.69, in Row 2, 3, 71.81, in Row 3, 4, 84.59, in Row 4, 5, 60.67, in Row 5, 6, 85.94, in Row 6, 7, 54.94, in Row 7, 8, 84.88, in Row 8, 9, 42.94, in Row 9, 10, 62.73, in Row 10,
Generating Alpha-Numeric Data for Column 2 Rows:, 1, 64.94, in Row1, 2, 39.05, in Row2, 3, 44.32, in Row3, 4, 30.45, in Row4, 5, 89.29, in Row5, 6, 6.61, in Row6, 7, 96.41, in Row7, 8, 27.99, in Row8, 9, 38.96, in Row9, 10, 48.29, in Row10,
-----------------------------------------------------------, Sorting Array Elements in the Column #1 in Descending Order:, Sorting Array Elements in the Column #2 in Ascending Order:, -----------------------------------------------------------, Sorted Alpha-Numeric Data for Both Array Columns:,
Index Column 1 | Column 2, 1, 85.94, in Row 6, | 27.99, in Row8, 2, 84.88, in Row 8, | 30.45, in Row4, 3, 84.59, in Row 4, | 38.96, in Row9, 4, 71.81, in Row 3, | 39.05, in Row2, 5, 62.73, in Row 10, | 44.32, in Row3, 6, 60.67, in Row 5, | 48.29, in Row10, 7, 59.69, in Row 2, | 6.61, in Row6, 8, 55.33, in Row 1, | 64.94, in Row1, 9, 54.94, in Row 7, | 89.29, in Row5, 10, 42.94, in Row 9, | 96.41, in Row7, -----------------------------------------------------------, |
Links: |
---|
|
See Also: |
|
Available Downloads: |
Description: |
---|---|
There are two example blox (version 3.x & 4.x) available in Topic: |
|
TB4 - Example_String_Array_Sorting |
|
Information Shown Above |
|
TB Ver: 3.2.x Compatible String Array Creating, Access, Sorting, and Random Number details |
Edit Time: 9/13/2020 2:51:42 PM |
Topic ID#: 615 |