Questions from a "dummy" - page 181

 

Help, I can't find any information anywhere.

How can I find out the weighted average opening price of a position after several trades? PriceOpen() from CPositionInfo shows the price of the first trade, but I need the current price, obtained after several trades.

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы - Документация по MQL5
 
class Parent1
{
public:
	virtual void Fn() {}
};

template <typename type>
class Parent2   // Какой-то библиотечный класс.
{
public:
	void Fn() {}     // Эту функцию хочу вызвать в Parent 1.
};

class Derived : public Parent2<type>, public Parent1
{

};

Parent1 *p = new Derived();
p->Fn();
The idea is that there is a class whose functionality we want (linked list Parent2). This class I want to connect in some other hierarchy (using multiple inheritance). Then, in the base class of this hierarchy, define virtual functions of the same name (the same as in the library class) to call these library functions. Since a library class is a template, consequently, we don't know the output type (after multiple inheritance) (there are many of them and they are different). But it all seems to be unrealizable.
 
sergeev:

the interest is probably purely academic

how to make Q3 in C++ : public Q1, public Q2

and at the same time make the compiler understand what is expected of it.

What's wrong with this note? It's called multiple inheritance.
 
220Volt:
What's wrong with this post? This is called multiple inheritance.

Yes, it's just that if prototypes have the same functions, it's more logical to do cascading inheritance.

Multiple inheritance is required if different set of virtual functions or explicit functions, and all virtuals or explicit functions must be available in descendant.

It is especially important when there already is a certain hierarchy, but it lacks some virtuals, not to rewrite the established classes multiple inheritance is done and the missing virtuals are virtualized in a parallel branch.

 
Urain:

Yes, it's just that if prototypes have the same functions, it's more logical to do cascading inheritance.

Multiple inheritance is required if different set of virtual functions or explicit functions, and all virtuals or explicit functions must be available in descendant.

It is especially important when there is already a certain hierarchy but it lacks some virtuals, to avoid rewriting established classes multiple inheritance is done and missing virtuals are virtualized in a parallel branch.

I'm not completely satisfied with the idea, in my understanding multiple inheritance is good for connecting some library functionality, everything would be fine if not for the template.
 
220Volt:
What's wrong with this entry? It's called multiple inheritance.

call it what you like, but you still need to negotiate with the compiler.

and it seems the only agreement is to define Fn in Q2

 

Good afternoon.

How do I select the volume of open positions for all symbols at once?

if(PositionSelect(Symbol_)) open_volume = PositionGetDouble(POSITION_VOLUME) - This function only outputs the result for each symbol individually.

 
abeiks:

Good afternoon.

How do I select the volume of open positions for all symbols at once?

if(PositionSelect(Symbol_)) open_volume = PositionGetDouble(POSITION_VOLUME) - This function gives a result only for each symbol separately.

I would loop through all symbols and summarize. Approximately like this:

double volume = 0;
for(int counter = PositionsTotal();  counter > 0;  counter --)
{
   if( PositionSelect(PositionGetSymbol(counter)) )
      volume += PositionGetDouble(POSITION_VOLUME);
}
Didn't check for correctness (didn't compile at all).
 
220Volt:

I would loop through all the characters and summarise. Like this:

I haven't checked it for correctness (I haven't compiled it at all).

I thought there might be something like AccountInfoDouble(ACCOUNT_BALANCE) only by open positions. But I see I will have to loop through all the characters. Thanks.

 

I can't figure out why the Print function prints 0 instead of 40?

//+------------------------------------------------------------------+
//|                                               test_deviation.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
CTrade trade;
trade.SetDeviationInPoints(40);
Print(trade.RequestDeviation());
  }
//+------------------------------------------------------------------+
Reason: