|
Unit Size Script |
Top Previous Next |
|
Called as part of the Broker object. When you use the broker object to place an order, the Unit Size script gets called to determine the size of the order.
Variables The Unit Size Script has access to the Order object. The following properties are commonly used:
order.orderPrice - The entry price of the order as placed by the broker object. If it is an open order, the close will be used.
order.stopPrice - The protective stop price of the order, as placed by the broker object.
order.entryRisk - The difference between the entry price and the stop. If there is no stop price specified in the broker call then the order.entryRisk will be zero.
order.position - The position of the order LONG or SHORT.
order.continueProcessing -- Returns TRUE if the order has not been rejected, returns FALSE if the order has been rejected and will not be processed.
order.processingMessage -- The rejection message if the order has been rejected. Blank if not rejected.
Functions order.SetStopPrice can be used to set the stop price, if it was not already set as part of the broker call, or it needs to be changed. order.SetQuantity is used to set the quantity for the order. Mandatory! order.Reject is used to reject/filter the order. A message can be passed into this function and will be printed in the Filtered Trade Log.
Note that the properties order.continueProcessing and order.processingMessage will be set when the order.SetQuantity function is called. When the quantity is set, the equity, volume, Portfolio Manager, and Risk Manager filters are called and checked. If any of these fail, then the status will be available at this time.
Example Unit Size Script The following is an example of a Unit Size script.
' Compute the amount of equity to risk. riskEquity = system.tradingEquity * riskPerTrade
' Compute the risk in dollars. dollarRisk = order.entryRisk * instrument.bigPointValue
' Adjust the unit size to this percentage. tradeQuantity = riskEquity / dollarRisk
IF tradeQuantity < 1 THEN ' Reject the order if the trade quantity is less than 1. order.Reject( "Trade Quantity is less than 1." ) ELSE ' Set this into the order if the quantity. order.SetQuantity( tradeQuantity )
|