Position Information#
PowerLanguage provides several built-in functions to help obtain position status, entry price, exit price, unrealized and realized profits, and other position information.
Using Position Information to Open and Close Positions#
Position information and Moving Average (SMA) crossover to open or close positions.
| |
Position information and profit/loss to close positions.
| |
Displaying Position Information on the Chart#
The following code uses text drawing to display the position information (profit, entry price, exit price) of the last closed position on the chart.
| |
The above code will produce output similar to the following:

Common Position Functions#
Position Status#
MarketPosition(PosBack)#
Returns the status of the specified position. Can only be used in signal scripts; use i_MarketPosition in indicators. To get the position size, use CurrentContracts or CurrentShares.
| Item | Description |
|---|---|
PosBack | 0 or not specified: current position. 1: the last closed position. 2: the position closed before last, and so on |
| Return value | 1: long position. -1: short position. 0: no position |
CurrentContracts#
Returns the number of contracts held in the current position as an absolute value (no sign). To get the position size with a sign (positive or negative), multiply CurrentContracts by the value of MarketPosition. Can only be used in signal scripts; use i_CurrentContracts in indicators.
| |
Entry Price#
EntryPrice(PosBack)#
Returns the entry (opening) price of the specified position. Can only be used in signal scripts.
| Item | Description |
|---|---|
PosBack | 0 or not specified: current position. 1: the last closed position. 2: the position closed before last, and so on |
| Return value | The entry (opening) price of the specified position |
PosTradeEntryPrice(PosAgo, TradeNumber)#
Returns the entry price of the specified trade. Can only be used in signal scripts.
| Item | Description |
|---|---|
PosAgo | 0 or not specified: current position. 1: the last closed position. 2: the position closed before last, and so on |
TradeNumber | The TradeNumber-th trade of the position. 0 is the first trade (opening), and so on |
| Return value | The entry price of the specified trade |
| |
Exit Price#
ExitPrice(PosBack)#
Returns the exit (closing) price of the specified position. Can only be used in signal scripts.
| Item | Description |
|---|---|
PosBack | 1: the last closed position. 2: the position closed before last, and so on |
| Return value | The exit (closing) price of the specified position |
PosTradeExitPrice(PosAgo, TradeNumber)#
Returns the exit price of the specified trade. Can only be used in signal scripts.
| Item | Description |
|---|---|
PosAgo | 0 or not specified: current position. 1: the last closed position. 2: the position closed before last, and so on |
TradeNumber | The TradeNumber-th trade of the position. 0 is the first trade (opening), and so on |
| Return value | The exit price of the specified trade |
| |
Unrealized and Realized Profits#
OpenPositionProfit#
Returns the unrealized profit or loss of the current position. Can only be used in signal scripts.
PositionProfit(PosBack)#
Returns the realized profit or loss of the specified position. If the position is only partially closed, returns the realized portion of the profit or loss. Can only be used in signal scripts.
| Item | Description |
|---|---|
PosBack | 0 or not specified: current position. 1: the last closed position. 2: the position closed before last, and so on |
| Return value | The realized profit or loss of the specified position |
| |
Reference#
https://www.multicharts.com/trading-software/index.php?title=Category:Strategy_Position
https://www.multicharts.com/trading-software/index.php?title=Category:Strategy_Position_Trades