Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1702

 
Valeriy Yastremskiy #:
I'll have a look at the print on Saturday. It's just that my EA is drawing. And it seems to draw on weekends too. Need to check it out.
Just unplugged the net and checked...

OnTick() does not work

 

I don't know why, but this kind of challenge doesn't strike me as a charman. That's the kind of sharman:

int OnInit()
   {
   DoSomething();
   return(INIT_SUCCEEDED);
   }

void OnTick()
   {
   DoSomething();
   }

void DoSomething()
   {

   } 
Predefined functions don't need to be yanked, that's not what they're designed for:)
 
Aleksei Stepanenko #:

I don't know why, but this kind of challenge doesn't strike me as a charman. That's the kind of sharman:

That's what I do. I get it) it's a bit disrespectful to OnTick)
 
Valeriy Yastremskiy #:
It's a bit disrespectful to OniTik)

Exactly, Valery! Some people don't like a loaf of bread turned upside down, but we ontik through ontik:)

 

A simple question that has stumped me.

How do you get the average price between two open orders, three, four

 
Порт-моне тв #:

A simple question that has stumped me.

How do you get the average price between two open orders, three, four

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
     {
      for(int i = OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType()==ot||ot<0)
                 {
                  order_lots += OrderLots();
                  order_price += OrderOpenPrice() * OrderLots();
                 }
              }
           }
        }
     }
   avg_price = NormalizeDouble(order_price / order_lots, Digits);
   return(avg_price);
  }
 
Valeriy Yastremskiy #:

What might be the secret meaning of such a design?

I've seen some bulk content on a forum where the author created an OOP library and a robot, and it initialized a virtual method and everything in it...
 
MakarFX #:
Thanks for the reply, but somehow it doesn't count right... Was referring to the opening price.
 
Порт-моне тв #:
Thanks for the reply, but somehow it doesn't count right... I meant the opening price.

I'm sorry, it's correct now.

 
Порт-моне тв #:

I'm sorry, that's correct now.

Yes, as long as no swaps have been accrued.

Reason: