Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1566

 

Good day!

Thank you very much for your reply!


Here is the code


int pos = PositionsTotal();
double swap = 0.0,
profit = 0.0;
for(int i = 0; i < pos; i++)
{
if(PositionGetSymbol(i) == _Symbol &&(PositionGetInteger(POSITION_MAGIC) == InpMagic))
{
PositionGetDouble(POSITION_PROFIT, profit);
ResetLastError();
if(!PositionGetDouble(POSITION_SWAP, swap))
{ {
Print(__FUNCTION__,"....ERROR swap. ",GetLastError());
return;
}
}
}


....and alas, it does not output swap and does not enter an error.

...profit outputs.


maybe it is connected with the data of the broker, ...rannforex , if anything ....

 
...or is there something wrong?
 

oops...

rookie mistake...when calculating in OnTick - did not count, put it in a separate function - it counts....


thanks again!

 

Help me understand the logic of MT5. I select orders in the history:

 //--- запросить всю историю 
   HistorySelect(0,TimeCurrent()); 
//--- переменные для получения значений из свойств ордера 
   ulong    ticket; 
   double   open_price; 
   double   initial_volume; 
   datetime time_setup; 
   datetime time_done; 
   string   symbol; 
   long   type; 
   long     order_magic; 
   long     positionID; 
//--- количество текущих отложенных ордеров 
   uint     total=HistoryOrdersTotal(); 
   Print("всего ордеров в истории", total);
//--- пройдем в цикле по всем ордерам 
   for(uint i=0;i<total;i++) 
     { 
      //--- получим тикет ордера по его позиции в списке 
      if((ticket=HistoryOrderGetTicket(i))>0) 
        { 
         //--- получим свойства ордера 
         open_price=       HistoryOrderGetDouble(ticket,ORDER_PRICE_OPEN); 
         time_setup=       (datetime)HistoryOrderGetInteger(ticket,ORDER_TIME_SETUP); 
         time_done=        (datetime)HistoryOrderGetInteger(ticket,ORDER_TIME_DONE); 
         symbol=           HistoryOrderGetString(ticket,ORDER_SYMBOL); 
         order_magic=      HistoryOrderGetInteger(ticket,ORDER_MAGIC); 
         positionID =      HistoryOrderGetInteger(ticket,ORDER_POSITION_ID); 
         initial_volume=   HistoryOrderGetDouble(ticket,ORDER_VOLUME_INITIAL); 
         type=             HistoryOrderGetInteger(ticket,ORDER_TYPE); 
         //--- подготовим и выведм информацию об ордере 
         printf("#ticket %d %s %G %s at %G was set up at %s => done at %s, pos ID=%d", 
                ticket,                  // тикет ордера 
                type,                    // тип 
                initial_volume,          // выставленный объем 
                symbol,                  // символ, по которому выставили 
                open_price,              // указанная цена открытия 
                TimeToString(time_setup),// время установки ордера 
                TimeToString(time_done), // время исполнения илм удаления 
                positionID               // ID позиции, в которую влилась сделка по ордеру 
                ); 
        } 
     } 

I get:

GR 0 20:16:50.551 HAVAL (XAUUSD,M5) total orders in history19

DI 0 20:16:50.551 HAVAL (XAUUSD,M5) #ticket 1225250047 (non-string passed) 0.1 XAUUSD at 0 was set up at 2024.10.08 19:19 => done at 2024.10.08 19:19, pos ID=1225250047

HR 0 20:16:50.551 HAVAL (XAUUSD,M5) #ticket 1225250049 (non-string passed) 0.1 XAUUSD at 0 was set up at 2024.10.08 19:19 => done at 2024.10.08 19:19, pos ID=1225250049

NL 0 20:16:50.551 HAVAL (XAUUSD,M5) #ticket 1225250054 (non-string passed) 0.1 XAUUSD at 0 was set up at 2024.10.08 19:19 => done at 2024.10.08 19:19, pos ID=1225250047

FI 0 20:16:50.551 HAVAL (XAUUSD,M5) #ticket 1225250146 (non-string passed) 0.1 XAUUSD at 0 was set up at 2024.10.08 19:21 => done at 2024.10.08 19:21, pos ID=1225250049

DR 0 20:16:50.551 HAVAL (XAUUSD,M5) #ticket 1225250188 (non-string passed) 0.1 XAUUSD at 0 was set up at 2024.10.08 19:23 => done at 2024.10.08 19:23, pos ID=1225250188

HL 0 20:16:50.551 HAVAL (XAUUSD,M5) #ticket 1225250221 (non-string passed) 0.01 XAUUSD at 0 was set up at 2024.10.08 19:25 => done at 2024.10.08 19:25, pos ID=1225250221

RK 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225250237 (non-string passed) 0.01 XAUUSD at 2614.83 was set up at 2024.10.08 19:26 => done at 2024.10.08 19:26, pos ID=1225250221

QP 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225250806 (non-string passed) 0.01 XAUUSD at 0 was set up at 2024.10.08 19:35 => done at 2024.10.08 19:35, pos ID=1225250806

JO 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225251596 (non-string passed) 0.02 XAUUSD at 0 was set up at 2024.10.08 19:50 => done at 2024.10.08 19:50, pos ID=1225251596

OD 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225252808 (non-string passed) 0.02 XAUUSD at 2610.16 was set up at 2024.10.08 19:56 => done at 2024.10.08 19:56, pos ID=1225251596

RS 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225252956 (non-string passed) 0.02 XAUUSD at 0 was set up at 2024.10.08 20:00 => done at 2024.10.08 20:00, pos ID=1225252956

CN 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225253906 (non-string passed) 0.03 XAUUSD at 0 was set up at 2024.10.08 20:05 => done at 2024.10.08 20:05, pos ID=1225253906

JE 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225254139 (non-string passed) 0.03 XAUUSD at 2607.03 was set up at 2024.10.08 20:06 => done at 2024.10.08 20:06, pos ID=1225253906

MS 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225254819 (non-string passed) 0.02 XAUUSD at 2610.26 was set up at 2024.10.08 20:08 => done at 2024.10.08 20:08, pos ID=1225252956

RH 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225254887 (non-string passed) 0.02 XAUUSD at 0 was set up at 2024.10.08 20:10 => done at 2024.10.08 20:10, pos ID=1225254887

MF 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225254980 (non-string passed) 0.02 XAUUSD at 2613.27 was set up at 2024.10.08 20:11 => done at 2024.10.08 20:11, pos ID=1225254887

IL 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225255101 (non-string passed) 0.01 XAUUSD at 2614.17 was set up at 2024.10.08 20:11 => done at 2024.10.08 20:11, pos ID=1225250806

IK 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225255635 (non-string passed) 0.01 XAUUSD at 0 was set up at 2024.10.08 20:15 => done at 2024.10.08 20:15, pos ID=1225255635

PP 0 20:16:50.552 HAVAL (XAUUSD,M5) #ticket 1225255684 (non-string passed) 0.01 XAUUSD at 2614.26 was set up at 2024.10.08 20:16 => done at 2024.10.08 20:16, pos ID=1225255635


although in the history


What is wrong?

 
sportoman #:
What is wrong?
In printf() compare the specified and passed parameter types
 
Artyom Trishkin #:
In printf() compare the specified and passed types of parameters

I have a question, why 19 orders in the history by brute force, but less in the terminal history and why the tickets in the terminal history do not coincide with the tickets in the cache.

 
sportoman #:

I have a question, why by brute force 19 orders in the history, but in the terminal in the history less and why the tickets in the history of the terminal do not coincide with the tickets in the cache

uint     total=HistoryDealsTotal();
https://www.mql5.com/ru/docs/trading
 
sportoman #:

I have a question, why by brute force 19 orders in the history, but in the terminal in the history less and why the tickets in the history of the terminal do not coincide with the tickets in the cache

Because the terminal does not show orders.

 
sportoman #:

Help me understand the logic of MT5. I select orders in the history:


What is wrong?

In the tester right-click to select orders, you must be looking at the history of trades

 
22746366 demo account).

The test was great... I saw all the results. Now I am using it on a demo account.
But in the app I only see orders.... and where the price should be, there is only the text "placed"... and no new stuff in the History tab.

I know this might be a very stupid question..... But I would be happy if someone could help me.

Thanks indeed!

Bless you :)