Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1565

 

How about this?

deals=HistoryOrders Total(); 
last_deal=HistoryDeal GetTicket((int)deals-1);
 
Aleksei Stepanenko #:

How about this?

Yes, that's right, I've already realised it's another error in the function description from MQ.

 
Aleksey Vyazmikin #:

Yes, that's right, I've already realised it's another error in the function description from MQ.

Where is it in the help?
 
Artyom Trishkin #:
Where is it in the Help?
MQL5 Reference Guide / Trading Functions / HistoryDealGetInteger
 
Aleksey Vyazmikin #:
MQL5 Reference Guide / Trading Functions / HistoryDealGetInteger
Got it, thanks.
 
Aleksey Vyazmikin #:

You are copying the code I gave you for what purpose, what does that explain?

I thought it was obvious. I will try to explain my thoughts more concretely, as you wrote above, you did a check on orders, and worked with deals. It's good that this "typo" will be corrected), although "typo" can be interpreted in such a way that the number of orders is not equal to the number of deals for the selected period).

 
Vladimir Deryagin #:
I thought it was obvious.

I don't work with trade functions usually, I use classes written for me - long time ago by other developers, so such a thing was not obvious to me at once. I ran through the functions, copied the code, modified it to suit myself and didn't realise that it didn't work as expected initially. In the beginning I sinned at another class with defines, searched there, consulted the author.... In general, if this code were not from MQ, I would have chosen a different strategy to find the error.

Thank you for helping me.

 

Good afternoon!


Help, who can!

I searched the forum, documentation, codobase - I couldn't find it.

.... I need to calculate swaps and commissions somehow.

I tried to get through PositionGetDouble(POSITION_SWAP) and through position.Swap() ..... but alas...


Can it be that in the tester when running the owl these data may not be present - and they are not output?


Thanks in advance, kind people!

 
YuryNov PositionGetDouble(POSITION_SWAP) and through position.Swap() ..... but alas...


Is it possible that in the tester when running the owl, this data may not be present - and they are not output?


Thank you in advance, kind people!

double amount_positions()
  {
   double resultat=0;
   for(int i=0; i<PositionsTotal(); i++)
     {
      string var_symbol;
      ulong var_magic;
      double var_swap=0,var_profit=0;
      if(PositionGetTicket(i)>0)
        {
         if(!PositionGetString(POSITION_SYMBOL,var_symbol))
           {/*Обработка ошибки*/}
         if(!PositionGetInteger(POSITION_MAGIC,var_magic))
           {/*Обработка ошибки*/}
         if(!PositionGetDouble(POSITION_SWAP,var_swap))
           {/*Обработка ошибки*/}
           if(!PositionGetDouble(POSITION_PROFIT,var_profit))
           {/*Обработка ошибки*/}
         if(var_symbol==_Symbol && var_magic==magic/*ваш magic*/)
           {resultat=var_swap+var_profit;}
        }
     }
   return NormalizeDouble(resultat,_Digits);
  }

The example includes all open positions, then it's just a matter of technique). Commission can be calculated only on completed trades.

            if(!HistoryDealGetDouble(ticket,DEAL_COMMISSION,var_comission))
              {/*Обработка ошибки*/}
 
I encountered a problem that in the strategy tester positions are opened instantly (even with a set delay), but on a real account each position is opened after 400ms +-. I divide one position into several, because in MT you can't open much more than 10k, and in crypto it's not enough. Has anyone encountered this problem and how to solve it? This is what I open positions with
 if  (условие)
         
          for  ( counter =  0 ; counter < iq; counter++)
         
         trader.Buy(); 

I attached a picture with a link because there is no other way.