|
Broker |
Top Previous Next |
|
The broker object is used to place orders. All orders are good for the day only. But since the scripts are run every day, your order will get placed every day.
Risk and Broker Orders Stops are used to calculate the risk of the trade. The difference between the order price and stop price is the risk of the trade. This is used to generate risk/reward calculations and sometimes used for position sizing in the Money Manager. For instance, the Fixed Fractional Money Manager uses the entry risk to determine the unit size. If you have no stops, undefined risk is assumed.
Examples: broker.EnterLongOnOpen ' Places an order to buy at ' the open with no stop.
broker.EnterLongOnOpen( stopPrice ) ' Places an order to buy at ' the open with a protective ' stop at stopPrice.
The quantity of each order is determined by the Money Manager. The Broker object calls the Money Manager, and the Money Manager sets the quantity for each order. If there is no Money Manager Block in the system, the unitSize defaults to 0. You must set the order quantity using order.SetQuantity() in the Unit Size script or the size will be 0 which will result in a trade that has no effect on your equity.
When a protective stop price is used in the entry order, that value is saved with the instrument and can be accessed using the instrument's unitExitStop property. The stop order itself, however, is only placed for the entry day. To 'hold' the stop and place it in the market every day, use the following code in your Exit Orders script:
broker.ExitAllUnitsOnStop( instrument.unitExitStop )
Many of our built-in systems use this method to "hold" stops. NOTE: this example is for a single unit system.
Advanced Note: for all these broker functions, the symbol can be passed in as the first parameter. This will trade the symbol if it is part of the system portfolio. It will be ignored if the symbol is not part of the portfolio. If no symbol is passed in, the current default instrument context will be used. This is the recommend approach. |