COUNTOFPOSITION is a function in ProBuilder language used to determine the number of open shares or lots in the current trading position. It returns a positive value for long positions and a negative value for short positions. This function is particularly useful for strategies that need to monitor and control the size of positions dynamically.
COUNTOFPOSITION
myMACD = MACD[12,26,9](close)
short = myMACD crosses under 0
IF NOT ShortOnMarket AND short THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
MAXSHARES = abs(COUNTOFPOSITION) <= 10
IF TRADEINDEX(1) > 5 AND TRADEPRICE(1) - Close > 10 * pointsize AND ShortOnMarket AND MAXSHARES THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
SET STOP TRAILING 50
In this example, the MACD indicator is used to determine the entry point for a short position. The COUNTOFPOSITION function is then used to ensure that the total number of shares shorted does not exceed 10. Additional short orders are placed only if certain conditions are met, including a sufficient drop in price and a minimum number of bars since the last trade.
This function is essential for managing risk and ensuring that trading strategies do not exceed predefined exposure limits.