Skip to main content
The Position model represents an open trading position in the MetaTrader 5 platform.

Properties

action
int
Position action typeAllowed values:
  • 0 - Buy
  • 1 - Sell
volume
float
Position volume (lot size)
symbol
string
Trading symbol (e.g., “EURUSD”, “GBPUSD”)
price
float
Opening price of the position
time
string
Time when the position was opened
id
int
Unique position identifier

Example

{
  "action": 0,
  "volume": 1.5,
  "symbol": "EURUSD",
  "price": 1.0850,
  "time": "2024-03-04T14:30:00Z",
  "id": 987654321
}

Action Values

The action field indicates the direction of the position:
ValueDescription
0Buy (Long)
1Sell (Short)

Methods

The Position model provides getter and setter methods for all properties:
  • getAction() / setAction($action) - Get/set the position action (buy/sell)
  • getVolume() / setVolume($volume) - Get/set the position volume
  • getSymbol() / setSymbol($symbol) - Get/set the trading symbol
  • getPrice() / setPrice($price) - Get/set the opening price
  • getTime() / setTime($time) - Get/set the opening time
  • getId() / setId($id) - Get/set the position ID

Usage Example

use D4T\MT5Sdk\Models\Position;

// Create a position instance
$position = new Position([
    'action' => 0, // Buy
    'volume' => 1.5,
    'symbol' => 'EURUSD',
    'price' => 1.0850,
    'time' => '2024-03-04T14:30:00Z',
    'id' => 987654321
]);

// Access properties
$symbol = $position->getSymbol();
$volume = $position->getVolume();
$action = $position->getAction();

// Update properties
$position->setVolume(2.0);
$position->setPrice(1.0860);

Build docs developers (and LLMs) love