Position Info
CPositionInfo
Source code in strategytester5\trade_classes\PositionInfo.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
comment
property
Gets the comment of the position.
commission
property
Gets the commission amount of the position, if available.
identifier
property
Gets the ID of the position.
magic
property
Gets the ID of the expert that opened the position.
position_type
property
Gets the position type.
position_type_description
property
Gets the position type as a string.
price_current
property
Gets the current price by position symbol.
price_open
property
Gets the opening price of the position.
profit
property
Gets the current profit of the position.
stop_loss
property
Gets the Stop Loss price of the position.
swap
property
Gets the swap amount of the position.
symbol
property
Gets the position symbol.
take_profit
property
Gets the Take Profit price of the position.
ticket
property
Gets the ticket / identifier of the position.
time
property
Gets the time of position opening.
time_msc
property
Receives the time of position opening in milliseconds since 01.01.1970.
time_update
property
Receives the time of position changing in seconds since 01.01.1970.
time_update_msc
property
Receives the time of position changing in milliseconds since 01.01.1970.
volume
property
Gets the volume of the position.
__init__(position, terminal)
A lightweight Python wrapper that resembles the MQL5 Standard Library class
CPositionInfo and provides convenient, read-only access to MetaTrader 5
open position properties.
This class wraps a single already-selected/open position object returned by
the MetaTrader 5 Python API, such as from mt5.positions_get().
Parameters
position : Any
A position object returned by MetaTrader 5 Python API functions such as
mt5.positions_get().
terminal : Initialize native MetaTrader5 API or the simulated one from the StrategyTester instance
Notes
- This wrapper does not implement selection methods by design.
- If no position is supplied, properties return fallback values such as
-1,0.0,"", orNone, depending on the property. - Time values are returned as timezone-aware UTC datetimes where applicable.
Method groups mirror the MQL5 layout: - Integer properties: Time, TimeMsc, TimeUpdate, TimeUpdateMsc, PositionType, Magic, Identifier - Double properties: Volume, PriceOpen, StopLoss, TakeProfit, PriceCurrent, Swap, Profit - String properties: Symbol, Comment - Generic accessors: InfoInteger, InfoDouble, InfoString
Source code in strategytester5\trade_classes\PositionInfo.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
info_double(prop_name)
Gets the value of a specified double type property.
Parameters
prop_name : str Name of the position attribute.
Returns
Optional[float] Float value if present, otherwise None.
Source code in strategytester5\trade_classes\PositionInfo.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
info_integer(prop_name)
Gets the value of a specified integer type property.
Parameters
prop_name : str Name of the position attribute.
Returns
Optional[int] Integer value if present, otherwise None.
Source code in strategytester5\trade_classes\PositionInfo.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
info_string(prop_name)
Gets the value of a specified string type property.
Parameters
prop_name : str Name of the position attribute.
Returns
Optional[str] String value if present, otherwise None.
Source code in strategytester5\trade_classes\PositionInfo.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
print_all()
Print all @property values of the class.
Source code in strategytester5\trade_classes\PositionInfo.py
239 240 241 242 | |
to_dict()
Return all @property values as a dictionary.
Source code in strategytester5\trade_classes\PositionInfo.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |