Variables Not Being Placed in Email Body

 

I have set out a load of variables which are to be sent out in an informational (is that even a word? It should be a word ;)) email when a position is executed.

Everything works as programmed and an email is indeed sent when a position has been successfully filled by the broker.

However, despite correctly declaring my variables, I'm getting blank spaces in my email where the variables should be.

  1. The `GlobalNamespace.mqh` file initially declares the variables and sets them as string variables.
  2. The EA (which, by the way, calls the `GlobalNamespace.mqh` file) and assigns each variable with MQL4's functions. The EA then passes control to the file containing the `SendMail()` Statement().
  3. The file containing the `SendMail()` statement also calls the `GlobalNamespace.mqh` file in order to determine that they are string variables, and sends the email but without the variables.

I don't see any reason whatsoever as to why there are blank spaces where these variables should be placed in the email body, as they are correctly initialised and the appropriate #include files are ...well, included.

Why is Metaeditor refusing go play ball?

It makes no sense.

My MQH `GlobalNamespace.mqh` file is as follows:

string            ExecutionPrice;
string            ExecutionTimeframe;
string            ExecutionSymbol;

My MQL File (EA) is as follows

#include <GlobalNamespace.mqh>

void OnTick(){
//---
   //Data pertaining to the executed position.
   ExecutionSymbol              =  Symbol();
   ExecutionTimeframe      	=  IntegerToString(Period()/60,0);
   ExecutionPrice               =  DoubleToString(OrderOpenPrice(),Digits);
 //---
}

This is the MQH file which sends the email upon an event:

#include <GlobalNamespace.mqh>


SendMail("<subject>,"Symbol"+ExecutionSymbol+"  Price"+ExecutionPrice+"  Timeframe"+ExecutionTimeframe);

These variables are used in a number of files, therefore I do not wish to declare them locally.

Custom Graphical Controls. Part 1: Creating a Simple Control
Custom Graphical Controls. Part 1: Creating a Simple Control
  • www.mql5.com
This article covers general principles of development of graphical controls. We are going to prepare tools for a quick and convenient work with graphical objects, analyze an example of creation of a simple control for entering text or numeric data as well as the ways of using it.
 

There are a few things with your code... but basically, each program is using its own set of variables. With mqh you are reusing code, but that doesn't mean that every EA that includes that mqh has the same instances of variables. Try substituting your includes with the content of the include file... that's basically what happens when compiling.

For such a simple event it would be better to just have it in the EA. If you really need to communicate between different programs check things like EventChartCustom or file functions

Documentation on MQL5: Working with Events / EventChartCustom
Documentation on MQL5: Working with Events / EventChartCustom
  • www.mql5.com
EventChartCustom - Working with Events - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Manuel Alejandro Cercos Perez #:
here are a few thing

Solution: Bypassed the EA file by declaring and dictionarying (now is THIS even a word?! Well it is now.) all variables in the GlobalNamespace file and called the  GlobalNamespace from the module which manages the `SendMail()` statement.

Essentially, the less files you pass control over to, the less likely the information will be lost.

Boom!