Ranked order values are created by the execution of system.RankInstruments. Each time an instrument's ranking values are updated the system.RankInstruments function should be executed so the new order of instruments will be ranked using the updated ranking values.
instrument.longRank
instrument.shortRank
instrument.longRankingValue
instrument.shortRankingValue
instrument.customSortValue
instrument.SetLongRankingValue( )
instrument.SetShortRankingValue( )
instrument.SetCustomSortValue( )
Syntax: |
---|
system.SortInstrumentList( iMethod ) |
Parameter: |
Description: |
---|---|
iMethod |
The number listed in the next table describes the type of sorting that will happen. |
Sorts the physical instrument list that is used for the simulation loop using the method indicated:
Method Value: |
Sorting Method Description: |
---|---|
1 |
Long Ranked value sorts the instrument list by the current Long Rank number order. |
2 |
Long Ranking script assigned value will be sorted in ascending order. |
3 |
Dictionary assigned Original Order Sort value. |
4 |
Custom Sort Value order. |
5 |
Alphabetical by Symbol |
6 |
Alphabetical by Group. |
|
Note:All market symbols are sorted regardless of whether they are primed when the sorting happens.
Instruments for these Sort Types need a dictionary source for these methods: 3 Order Sort Value 4 Custom Sort Value 6 Group Name |
The ranking process that creates the Long Rank from the Long Ranking Value is the system.RankInstruments function and/or the Portfolio Manager internal process.
The Ranking process only ranks trading instruments (those that are primed and ready to be used in scripting). So as you said, you need to be aware of this if you set the Long Ranking Value, and then Rank the list, and then Sort the list by the Long Rank.
A more direct approach if you need the instrument list sorted, is to set the Long Ranking Value and then sort by the Long Ranking Value directly using the system.SortInstrumentList(2). Note that the Long Rank by definition is created by ranking the Long Ranking Value from highest to lowest, so the Long Rank is sorted "opposite" of Long Ranking Value.
As for markets that are not primed, you can check this when you use the Rank or Ranking Value, by checking the instrument.isPrimed property or the instrument.tradesOnTradeBar property if necessary. Note that the Entry and Exit scripts do not run if the instrument is not primed or does not trade on the trade date. So you only need these properties if looping over the instrument list manually. Likewise if you loop over the instruments manually to set the Long Ranking Value, you can set this to some out of bounds value as necessary to move to the back of the list. The only time you can't set the value is in the Portfolio Manager where the non primed instruments are not looped over.
In addition, the custom sort value is available for use by the system.SortInstrumentList( method# ) function.
Property: instrument.customSortValue
Function: instrument.SetCustomSortValue( value )
The Custom Sort Value can also be set in other scripts, just like the ranking Values.
-- Loop over each instrument setting the custom sort value
-- call system.sortInstrumentList(4)
-- Loop over each instrument and note how the instrument list has been sorted
Once the instrument list is sorted using the SortInstrumentList function, the Entry Orders script and other instrument scripts will execute in a new order.
Example: |
---|
' Create a BPV Instrument Variable Name ' Get Total Number of Instruments in Portfolio
|
Returns: |
---|
Mkt# Mkt-Symbol 1 EFA 2 GLD 3 IWM 4 LQD 5 MDY |
Links: |
---|
See Also: |
|
Edit Time: 11/19/2020 12:37:44 PM |
Topic ID#: 570 |