how to close oldest and newest trade
hi,
if open order 10
i want calculate if (10th order - 1st order) = 1$ profit so close both trade, 2 to 9 order wait for profit
Loop through all open positions and check the open date/time.
Here is an example of such a loop: https://www.mql5.com/en/code/36010
Copy what you need and adjust it to your requirements.
- www.mql5.com
If (PositionsTotal()>0) { PositionGetTicket(0); //Oldest Opened Position PositionGetDouble(POSITION_PROFIT); // Get the position Profit PositionGetTicket(PositionsTotal()-1); //latest Opened Position PositionGetDouble(POSITION_PROFIT); // Get the position Profit }
Read documents to close positions
MT5 has positions, not opened orders.
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon.
hi,
if open order 10
i want calculate if (10th order - 1st order) = 1$ profit so close both trade, 2 to 9 order wait for profit