SHORTONMARKET

Category: ProBacktest

SHORTONMARKET is a built-in function in the ProBuilder language used to determine if there are any short positions currently open in the trading system. This function is crucial for strategies that need to avoid opening multiple short positions simultaneously or to check the status before closing existing positions.

Syntax:

ShortOnMarket

Example Usage:

Consider a scenario where you want to initiate a short trade based on the MACD indicator, but only if there is not already a short position open. The following code demonstrates how to use SHORTONMARKET in this context:

myMACD = MACD[12,26,9](close)
short = myMACD crosses under 0
IF NOT ShortOnMarket AND short THEN
    SELLSHORT 1 CONTRACTS AT MARKET
ENDIF

Explanation:

  • The MACD function is used to calculate the Moving Average Convergence Divergence, which is a trend-following momentum indicator. It shows the relationship between two moving averages of a security’s price.
  • The code checks if the MACD line crosses below zero, which is a common signal used to suggest a potential downward trend.
  • The IF statement then checks whether there is no existing short position (using ShortOnMarket) and whether the MACD condition (short) is true.
  • If both conditions are satisfied, a new short position is opened by selling short 1 contract at the market price.

This function helps in managing trading actions by ensuring that the trading strategy does not open multiple short positions, which can be part of risk management and strategy effectiveness.

Related Instructions:

  • LONGONMARKET probacktest
  • MARKET probacktest
  • ONMARKET probacktest
  • Logo Logo
    Loading...