Reference a function in EA from library - page 2

 
Alain Verleyen:

Seems interesting but honestly I don't understand Anyone else ?

Can you provide some demo code ?

I'll try to explain best I can.

I make my EA and have many functions. In specific parts of the EA, I have where customer work should be done so that it changes global variables such as colors which I use to make trading signals to trade by. I also make objects with customer info. So I made a library named "CustomerToDonBridgeLibrary.mq4" (see below for complete source code), compile it and import those functions in the 2 areas I have made for customer stuff in my library (see below for code I import into my library. I won't show my other library code). So I have an "Empty" version of this bridge library imported into my library "DonsFunctionsLibrary.mq4". I can then compile my library for later import into EA. No need to re-compile "DonsFunctionsLibrary.mq4" after this unless I actually need to make a change to my code.

I then make my "CustomerActualName_CustomerJobName_Library.mq4", do work to get signals for exit and entry, draw objects specific to customer, etc., and export 2 functions, compile, and import them into "CustomerToDonBridgeLibrary.mq4" (see below for complete source code).

Finally, I import the same functions I did into "DonsFunctionsLibrary.mq4" into the EA, and then import my 3 modified functions (DonOnInit, DonOnDeinit and DonOnTimer, where together all my work is done) from "DonsFunctionsLibrary.mq4" into EA (see below for complete source code). So if I just need to change signals or customer objects, I can go back to "CustomerActualName_CustomerJobName_Library.mq4", make changes, and compile. No need to re-compile "DonsFunctionsLibrary.mq4", CustomerToDonBridgeLibrary.mq4", or EA (unless a user input was changed).

I hope this helps your understanding. Does it?

Kindest regards,

Don 

#property copyright "Copyright 2015, Donald R. Isbell, Jr."
#property link      "disbellj@gmail.com"
#property strict

void CustomerWorkAreaBridge(int bar) export
   {
   
}

void CustomerObjectsBridge(string add, int step, int n, int& Return_n) export
   {
   
}

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
 
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  
  }
//+------------------------------------------------------------------+
#import "CustomerToDonBridgeLibrary.ex4"
   void CustomerWorkAreaBridge(int bar); 
   void CustomerObjectsBridge(string add, int step, int n, int& Return_n);
#import
#property copyright "Copyright 2015, Donald R. Isbell, Jr."
#property link      "disbellj@gmail.com"
#property strict

#import "CustomerActualName_CustomerJobName_Library.ex4"
   void CustomerWorkArea(int bar);
   void CustomerObjects(string add, int step, int n, int& Return_n);
#import

void CustomerWorkAreaBridge(int bar) export
   {
   CustomerWorkArea(bar);
}

void CustomerObjectsBridge(string add, int step, int n, int& Return_n) export
   {
   CustomerObjects(add,step,n,Return_n);
}

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
 
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  
  }
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Donald R. Isbell, Jr."
#property link      "disbellj@gmail.com"
#property version   "1.00"
#property description ""

#import "CustomerToDonBridgeLibrary.ex4"
   void CustomerWorkAreaBridge(int bar); 
   void CustomerObjectsBridge(string add, int step, int n, int& Return_n);
#import

// Customer-specific user inputs here

#import "DonsFunctionsLibrary.ex4"
   void DonsOnInit();
   void DonsOnDeinit();
   void DonsOnTimer();
#import

// DonFunctionsLibrary user inputs here (with customer-specific settings if they were changed from defaults)
   
int OnInit()
  {
   DonsOnInit();
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
  {
   DonsOnDeinit();
  }
  
void OnTimer()
  {
   DonsOnTimer();
  }
Reason: