Questions from Beginners MQL5 MT5 MetaTrader 5 - page 741

 
fxsaber:
You asked without perversions. And if you did, then...
That's why it's like this.
double GetPositionCommission( void )
{
  double Commission = ::PositionGetDouble(POSITION_COMMISSION);

  // На случай, если POSITION_COMMISSION не работает
  if (Commission == 0)
  {
    const ulong Ticket = MT4ORDERS::GetPositionDealIn();

    if (Ticket > 0)
    {
      const double LotsIn = ::HistoryDealGetDouble(Ticket, DEAL_VOLUME);

      if (LotsIn > 0)
        Commission = ::HistoryDealGetDouble(Ticket, DEAL_COMMISSION) * ::PositionGetDouble(POSITION_VOLUME) / LotsIn;
    }
  }

  return(Commission);
}
Or

I realise the post is old, but it just now hit me with a splinter.

This bit here is not correct, the commission in forex can be zero

// На случай, если POSITION_COMMISSION не работает
  if (Commission == 0)
 
Artyom Trishkin:
ObjectGetValueByShift() (MT4 only), ObjectGetValueByTime() (MT4, MT5)

Thank you
 
Alexey Volchanskiy:

I realise the post is old, but it just now hit me with a splinter.

This bit here is not correct, the commission in forex can be zero


How is it incorrect?
 


Problem with copy constructor in MQL5

The dynamic array this.arr, in the copy constructor, is seen by the debugger as one-dimensional.

As a result, the size of ob2.arr equals 0 in the output.

Why?

The same fragment works correctly in MQL4.

MT5 Editor

MetaEditor 5.0 1578

MT4 editor

MetaEditor 5.0 1562

class obj
  {
public:
   double            arr[][2];
                     obj(){}
                     obj(obj &o)
     {
      ArrayCopy(this.arr,o.arr);
     }
   obj operator=(obj &o)
     {
      ArrayCopy(this.arr,o.arr);
      return &this;
     }
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
obj Copy(obj &o)
  {
   return o;
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   obj ob1,ob2;
   ArrayResize(ob1.arr,3);
   ob2=Copy(ob1);
   bool stop=true;
  }


 
Klimenko_a_e:

The result is that size ob2.arr is 0 in the output.

Why?

obj* Copy(obj &o)
  {
   return & o;
  };

Otherwise you are creating a new object.


   void operator=(obj &o)
     {
      ArrayCopy(this.arr,o.arr);
      return; // &this;
     }

Otherwise, unnecessary things happen.


I doubt that your code worked correctly in MQL4.

 
Good day! Can you please tell me how to open a single pending order?
How do I stop the loop if I need to open one pending order when the bay is open???

I can open a bunch of them until the deposit runs out!

I do not know how to open one pending order.

 
Akinak:
Good day! Can you please tell me how to open a single pending order?
How do I stop the loop if I need to open one pending order when the bay is open???

I can open a bunch of them until the deposit runs out!

Thanks in advance!


First you need to find out "who he is".

 
Vladislav Andruschenko:


First you have to find out "who he is".


Vladislav Andruschenko:


first you need to find out "who he is".


for(int i=0; i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()==Magic)
if(b>0)
{
int tak=OrderSend(Symbol(),OP_SELLSTOP,Lots_work,SOPrase,Slip,0,0,",Magic,0,clrRed);
if(tak>0)
Print("SELLSTOP Ok");
else
Print("SELLSTOP Error");
}
if(s>0)
{
OrderSend(Symbol(),OP_BUYSTOP,Lots_work,BOPrase,Slip,0,0,",Magic,0,clrBlue);
if(tik>0)
Print("BUYSTOP Ok");
else
Print("BUYSTOP Error");
}

}


 

Well, what you do in the cycle is this:

you open a position - you open an order, the number of positions is added, the cycle repeats - to infinity.

int OrderSTotal=OrdersTotal();
for(int i=0; i<OrderSTotal;i++)
  {
   if(OrderSelect(i,SELECT_BY_POS))
      if(OrderSymbol()==Symbol())
         if(OrderMagicNumber()==Magic)

           {
            if(b>0)
              {
               int tak=OrderSend(Symbol(),OP_SELLSTOP,Lots_work,SOPrase,Slip,0,0,"",Magic,0,clrRed);
               if(tak>0)
                  Print("SELLSTOP  Ok");
               else
                  Print("SELLSTOP  Error");
              }

            if(s>0)
              {
                int tik=OrderSend(Symbol(),OP_BUYSTOP,Lots_work,BOPrase,Slip,0,0,"",Magic,0,clrBlue);
               if(tik>0)
                  Print("BUYSTOP  Ok");
               else
                  Print("BUYSTOP  Error");
              }
           }
  }
//+------------------------------------------------------------------+


You need to know what b and s are

 
fxsaber:

Otherwise you are creating a new object.


Otherwise unnecessary things happen.


I doubt your code worked correctly in MQL4.

In real code - the function returns an object.

I think the copy constructor should create a temporary copy in this case.

The code works correctly in MQL5 build 1545.

In the new build, the copy constructor cannot resize even a one-dimensional array: Error 4007.

This is not correct in my opinion.