TRADEPRICE is a function in ProBuilder language used to retrieve the execution price of a past trade. This function is particularly useful in trading strategies where the price at which previous trades were executed influences future trading decisions.
TRADEPRICE(N)
Where N is the index of the trade relative to the most recent one. N=1 refers to the most recent trade, N=2 to the second most recent, and so on.
myMACD = MACD[12,26,9](close)
long = myMACD crosses over 0
exit = myMACD crosses under 0
// First order
IF NOT LongOnMarket AND long THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
If LongOnMarket AND exit THEN
SELL AT MARKET
ENDIF
// Adding another order if the price is more than 10 points higher than the last order and 5 bars have elapsed
IF BARINDEX - TRADEINDEX(1) > 5 AND Close - TRADEPRICE(1) > 10 AND LongOnMarket THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Setting a trailing stop for all orders
SET STOP %TRAILING 1.5
This example demonstrates a trading strategy using the MACD indicator. It includes conditions for entering and exiting trades based on the MACD signals. Additionally, it uses the TRADEPRICE function to add another order if the closing price has increased by more than 10 points since the last trade, provided that at least 5 bars have elapsed since that trade.
Understanding the use of TRADEPRICE can enhance the effectiveness of a trading strategy by providing a method to reference historical trade execution prices directly in the trading logic.