enterLong (function, var v0, ...): TRADE*
enterShort (function, var v0, ... ): TRADE*
Enters a long resp. short trade position.
||Optional pointer of an int function for managing the trade. The function is called every tick with the TRADE* pointer as first argument, followed by further numbers or variables. It can react on price changes for closing the position or adjusting stop and profit limits. The function normally returns 0. A return value of 1 exits the trade. A return value of -1 causes the Stop, Profit, and Trail parameters to be ignored and leaves stop management completely to the trade function.
||Optional variables that are passed as further arguments to the trade function.
TRADE* - a pointer to the created trade struct.
See include\trading.h for the definition of trading specific structs.
- If parameters are not used, they can be omitted in the parameter list. For instance, when no trade function is used, only the name can be given, or no parameter at all.
- Every trade is linked to an algorithm identifier that can be set up through the Algo string. Identifiers are useful when the script trades with several different algorithms; they are then used for selecting strategy parameters or Kelly factors belonging to a certain trade algorithm, or to exit or identifiy particular trades. The performance report lists strategy results separated by their algorithm identifiers.
- The number of lots (1 lot = normally 10000 currency units) is automatically calculated through the Risk and Lots variables. If the risk of the trade is higher than twice the Risk value, no trade position is opened.
- The entry, stop loss, profit, and trail limits are set through the Entry, Stop, Profit, and Trail variables. If the stop limit is too close to or on the wrong side of the price, the trade can be rejected by the broker - this is indicated in the message window. Make sure that the stop loss has sufficient distance to the current price (priceClose()).
- If no Entry limit is given, trades are opened at the begin of the next bar in [Test] or [Train] mode. In [Trade] mode they are opened immediately.
- When the trade order can not be executed in [Trade] mode, the broker's error message - such as "There is no tradable price" - is given in the message window. No position is opened. This can happen f.i. when stock indices are traded at an unusual time and the market is closed, or when no quote is available. If TimeWait is set above 1, the buy attempt is repeated on the next bar.
- If Hedging is prohibited, as is the case with US based accounts, a position can not be bought when another position of the same asset is already open.
- If a broker(int,TRADE*) function is defined in the script, it is called with 1 for the first argument and the TRADE* pointer for the second argument at the moment when the buy order is sent to the broker. This function can f.i. open a message box for manually entering the trade, or control another broker's user interface.
- When converting scripts from other trading software, keep in mind that other trading programs use sometimes different names for trade functions. For instance, TradeStation® uses "Sell Short" for entering a short position and "Buy To Cover" for exiting a short position.
Algo = "WMA";
exitTrade, exitLong, exitShort, numLong, numShort, Lots, Risk, Entry, Stop