|
Exit Orders Script |
Top Previous Next |
|
The Exit Orders script is called once each day for each instrument that has a position. The Exit Orders script is responsible for creating orders to exit existing positions.
The RSI Trend Exit block uses the following code in the Exit Orders script.
' --------------------------------------------- ' Exit Position if RSI crosses Threshold ' ---------------------------------------------
IF instrument.position = LONG AND relativeStrengthIndex <= exitThreshold THEN
' Exit the position. broker.ExitAllUnitsOnOpen ENDIF
IF instrument.position = SHORT AND relativeStrengthIndex >= (100 - exitThreshold) THEN
' Exit the position. broker.ExitAllUnitsOnOpen ENDIF
' --------------------------------------------- ' Enter stop if "holdstops" is true ' ---------------------------------------------
IF holdStops THEN
broker.ExitAllUnitsOnStop( instrument.unitExitStop )
ENDIF
This sample script has two common features. First, a check against the open position because of the differing logic for LONG and SHORT positions.
Second, the placing of stop orders using the instrument.unitExitStop price. You will need logic like this if you wish to have stops which are in effect for the duration of a trade. Trading Blox Builder requires that you place new orders for stops each day. |