Download MetaTrader 5

Discussion of article "Cross-Platform Expert Advisor: The CExpertAdvisor and CExpertAdvisors Classes" - page 2

To add comments, please log in or register
mbjen
46
mbjen  
mbjen:


52959000 undeleted objects left

6619875 objects of type CExpertAdvisor left

6619875 objects of type CAccountInfo left

6619875 objects of type CSymbolManager left

6619875 objects of type COrderManager left

13239750 objects of type COrders left

6619875 objects of type CTradeManager left

6619875 objects of type CCandleManager left

1689399848 bytes of leaked memory


How do I fix these errors? The program is designed based on your sample.

In OnDeinit() function I have only experts.OnDeinit().

In OnInit() only experts.OnTick();

And in signal function I just create custom indicator objects same way as in your samples.


That's ok, my fault

mbjen
46
mbjen  

Let me report another possible bug if you don't mind.

It didn't return number of open orders. I began to check and discovered that problem is related to OrdersBase and sort mode.

I had to add the following code:

COrder *COrdersBase::NewOrder(const ulong ticket,const string symbol,const int magic,const ENUM_ORDER_TYPE type,const double volume,const double price)
  {
   COrder *order=new COrder(ticket,symbol,type,volume,price);
   if(CheckPointer(order)==POINTER_DYNAMIC)
     {
      order.SetContainer(GetPointer(this));
      if(SortMode()==-1)
         Sort(0);
      if(InsertSort(GetPointer(order)))
        {
         order.Magic(magic);
         if(type==ORDER_TYPE_BUY || type==ORDER_TYPE_SELL)
            order.Init(GetPointer(this),m_stops);
         else order.Initialized(false);
         return order;
        }
     }
   return NULL;
  }


I don't know why it is not initialzed with proper sort mode or I have to initialize it additionally.. have no idea.

Enrico Lambino
6411
Enrico Lambino  
mbjen:

Let me report another possible bug if you don't mind.

It didn't return number of open orders. I began to check and discovered that problem is related to OrdersBase and sort mode.

I had to add the following code:


I don't know why it is not initialzed with proper sort mode or I have to initialize it additionally.. have no idea.

The COrdersBase constructor has the following code:

COrdersBase::COrdersBase(void)
  {
   if(!IsSorted())
      Sort();
  }

In the beginning, it sorts its internal object array if it is not yet sorted, but I am sure that you are already aware of this.

It can become unsorted if other items are added to it without using NewOrder() (e.g. Add()).

I cannot replicate the issue that you have. My results always return sorted all throughout the entire test. Try to find the point in time where the array becomes first unsorted in your test. It might provide a clue as to the problem source.

mbjen
46
mbjen  

Hello,

I will let you know if I face with the issue again.

I have another question. How do I get the current expert instance which calling signal module?

Let say I have signal class which has a function for checking previous orders results. I have several expert instances. So how do I get the current expert orders which is calling the signal check functions? 

Or maybe there is another proper solution. Can you please share some idea or piece of code for that.

My goal is to create a signal which would work differently depending on previous order/position result.

Enrico Lambino
6411
Enrico Lambino  

There are many ways to do that, it may vary from one programmer to another. By default, the experts instances act independently of each other. You may implement it so that the instances can share the same information.

If you want to differentiate trades opened by each of the experts, you may start by assigning a unique magic number for each instance. I cannot help you further unless you show your code. 

mbjen
46
mbjen  

Enrico,

My code is fully based on your last examples.

I have only one global definition CExpertAdvisors experts;

In OnInit() I initialize money/stops/signal module and next add them for each expert instance.

In OnTick() I have only experts.OnTick()

And I have my custom signal class with Calculate(), LongCondition(), ShortCondition() and others. This signal is added for each expert instance.

Now, I just want the logic of signal to depend on each specific expert instance last order/position result. It's not related to magic number (btw, all my expert instances have different magics.). In the signal called functions  Calculate(), LongCondition(), ShortCondition() I do not have magic or any other details which can help me to identify the expert instance and next find its orders.

As for the code, let it be Calculate() function like this:

bool SignalClass::Calculate()

{ //--- some code to find out if the expert last order was profitable or not return true;

}

I hope you understand. Is there any way to implement this with no modification of your library code?

mbjen
46
mbjen  

Hello Enrico,

I'm still trying to find a possible way to identify which expert instance calling signal check functions. How do I do that? Any hint please?

12
To add comments, please log in or register