Sets the Sort Value for the order that will assigned to the order.sortValue property.

 

Loop over the orders setting this value, and then use the system.SortOrdersBySortValue to sort the orders.

 

Syntax:

order.SetSortValue( sortValue )

 

TYPE:

Description:

sortValue

Assign a numeric sort value.  Number is any user value based upon how the user wants the orders sorted.  Orders are sorted in an ascending lowest to highest value sequence.

 

Returns:

Places the assigned sortValue in the order's sortValue property.

 

Example:

'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Before order Execution
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Create Column Header Titles
  PRINT "#", "ao.referenceID", "ao.symbol", "ao.SortValue"
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Get Total of Open Orders
totalOpenOrders = system.totalOpenOrders
 
'  Show Order Sequence Before Orders are Sorted
PRINT "Before Orders are Sorted"
'  Loop through the open orders & Assign Ranking
FOR x = 1 TO totalOpenOrders STEP 1
  '  Access each open order
  system.SetAlternateOrder( x )
 
  '  Generate a Random value for each order
  PRINT x, alternateOrder.referenceID, alternateOrder.symbol, alternateOrder.sortValue
Next '  x
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
'  Loop through the open orders & Assign a Random Ranking value
FOR x = 1 TO totalOpenOrders STEP 1
  '  Access each open order
  system.SetAlternateOrder( x )
 
  '  Generate a Random value for each order
  OrderRanking = Random( totalOpenOrders )
 
  ' Set the value as the order sort value.
  alternateOrder.SetSortValue( OrderRanking )
Next '  x
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
'  Sort All Open Orders in Ascending Order
system.SortOrdersBySortValue()
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
'  Show Order Sequence After Orders are Sorted
PRINT
PRINT "After Orders are Sorted"
'  Loop through the open orders & Assign Ranking
FOR x = 1 TO totalOpenOrders STEP 1
  '  Access each open order
  system.SetAlternateOrder( x )
 
  '  Generate a Random value for each order
  PRINT x, alternateOrder.referenceID, alternateOrder.symbol, alternateOrder.sortValue
Next '  x
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

Returns:

When script shown above is created it will show the order prior to being sorted and getting a random value for its order ranking property.  After the orders have been assigned a random sort value, all the orders are sorted in ascending numerical order.  After the sorting the orders are shown again.  All reporting output will be found in the Print Output.csv file in the Trading Blox/Results folder.

RandomOrderSortedResults_Output

 

Alternate Order Object:

Access to Order Object properties and functions in other scripts is made possible by using the AlternateOrder Object as the prefix ahead of the "." property or function. AlternateOrder Object is discussed below.

 

Notes:

Always check to be sure the order is available after a Broker function call using the system.orderExists function prior to accessing it.

 

Using the alternateOrder object when orders are not in context will provide the same access as the Order object.  However, the alternateOrder object must be brought into context using the system.SetAlternateOrder object function prior to any attempt to use is properties and functions.

 

Once orders are brought into context their properties and function are available to reference and changes.

 

 


 

Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software