Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1045

 
Vladimir Baskakov:

Confused about the correct spelling of the condition, help:

There could be two options:

  1. "MA Slow" is higher than "MA Fast".
  2. "MA Slow" is lower than or equal to "MA Fast".


Accordingly the sign of the result will be "+" or "-". If the sign is "-", your condition will never be fulfilled since "-" will always be less than 5*Point().


In other words, the code will be

   if(ma_slow[0]>ma_slow[9])
      if(ma_slow[0]-ma_slow[9]>5*Point())
        {

        }
   if(ma_slow[9]>ma_slow[0])
      if(ma_slow[9]-ma_slow[0]>5*Point())
        {

        }
 
Vladimir Karputov:

There can be two options:

  1. "MA Slow" is higher than "MA Fast"
  2. "MA Slow" is lower than or equal to "MA Fast".


Accordingly the sign of the result will be "+" or "-". If the sign is "-", your condition will never be fulfilled since "-" will always be less than 5*Point()


In other words, the code will be

Exactly! The second condition I was thinking of doing that too ;) Thanks
 
Artyom Trishkin:

Maybe you posted the decompiled code? Maybe you asked for something else to do with decompiling the executable?

No, the questions were about translating code from mql4 to mql5
I did everything, but there was an error while working, I asked for help to figure it out

 
Roman Sharanov:

No, the questions were about translating code from mql4 to mql5
I did everything seemingly, but there was an error while working, I asked for help to figure it out

Strange. Was there a code? Maybe there were signs of decompilation in it?

 

I can'topen a position, I get a wrong volume response for any values.


   if(direction==0)
      open_label=open_label+"Buy  "+ "V = "+DoubleToString(V,2)+" price = "+DoubleToString(price_open,_Digits)+
                  " SL = "+DoubleToString(SL,_Digits)+"  TP = "+DoubleToString(TP,_Digits);
   else   
      open_label=open_label+"Sell  "+ "V = "+DoubleToString(V,2)+" price = "+DoubleToString(price_open,_Digits)+
                  " SL = "+DoubleToString(SL,_Digits)+"  TP = "+DoubleToString(TP,_Digits);
   
    Print(open_label);

   if(direction==0 && last.ask<=price_open)
      {
        if(!trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,V,price_open,SL,TP))
          Print("Метод PositionOpen() потерпел неудачу. Код возврата=",trade.ResultRetcode(),
            ". Описание кода: ",trade.ResultRetcodeDescription());
        else
          Print("Метод PositionOpen() выполнен успешно. Код возврата=",trade.ResultRetcode(),
            " (",trade.ResultRetcodeDescription(),")");
      }


2019.05.20 21:53:24.814 position_open (XAUUSD,M10) Wait for Buy V = 1.00 price = 1278.15 SL = 0.00 TP = 0.00

2019.05.20 21:53:34.002 position_open (XAUUSD,M10) CTrade::OrderSend: market buy 1.00 XAUUSD [invalid volume]

2019.05.20 21:53:34.002 position_open (XAUUSD,M10) PositionOpen() method failed. Return code=10014. Code description: invalid volume

Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
Hi guys, can you tell me how to calculate the commission for open trades in mt5 volume or tell me where there is a ready-made function
 
Aleksandr Egorov:
Hi guys, can you tell me how to calculate the commission for open trades in mt5 volume or tell me where there is a ready-made function
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

// Комиссия всех открытых позиций.
double GetSumCommission()
{
  double Sum = 0;
  
  for (int i = OrdersTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS))
      Sum += OrderCommission();
      
  return(Sum);
}
 
Aleksandr Egorov:
Hi guys, can you tell me how to calculate the commission for open trades in mt5 volume or tell me if there is a ready-made function
PositionGetDouble(POSITION_COMMISSION)

Or CPositionInf Commission

 
Konstantin Nikitin:

Or CPositionInf Commission

Hasn't been working for a long time.

 
fxsaber:

Not working for a long time.

I've tried it and your function works fine. Anyway, thanks a lot for your feedback,

I've got it figured out where to get the commission)) I'm new to MT5 so I'm not too keen on it, but I'd better check it if it's not right

i think i got it right

double PROFIT()     {

   double  rez=0, alprof=0,svap=0,commicion=0;

   ulong ticet=0,tikett=0;

   long  entry=0;

   string com="";

   ulong tik;

   ulong ord;

   int i=0;

   for(i=PositionsTotal()-1;i>=0;i--) 

     {

      if(PositionGetSymbol(i)==Symbol() || PositionGetSymbol(i)==Pair)

        {

         if((tik=PositionGetTicket(i))>0)

           {

            alprof+=PositionGetDouble(POSITION_PROFIT);

            svap+=PositionGetDouble(POSITION_SWAP);

           }

        }

     }

   HistorySelect(0,TimeCurrent());

   for(uint r=HistoryDealsTotal()-1;r>0;r--) 

     {

      if((tikett=HistoryDealGetTicket(r))>0) 

        {

         ord=HistoryDealGetInteger(tikett,DEAL_ORDER);

         entry =HistoryDealGetInteger(tikett,DEAL_ENTRY);

         if(entry==DEAL_ENTRY_IN)

           {

            for(int t=PositionsTotal()-1;t>=0;t--) 

              {

               if(tik==ord)

                 {

                  commicion+=HistoryDealGetDouble(tikett,DEAL_COMMISSION);

                 }

              }

           }

        }

     }

   rez+=alprof+commicion+svap;

   return(rez);   }

Reason: