Function Not Visible From Within Script - Other Functions Are Though !?!

 

I have some functions in a script file some of which are visible and callable from within the same script.

Others though always throw the compile error -undeclared identifier.

I'm assuming that i have something wrong with programmatic flow.


Any help would be appreciated - the Copy File Function is not working either.

Here is me setting Global Variable in main.mq5 file

int OnInit () {
    cTrade. SetExpertMagicNumber(Magic);        
    
    double doesnMatter = 0;
    string myValue = EAname;     //to be persisted forever
    datetime w = GlobalVariableSet("MyVar " + myValue, doesnMatter);

    return (INIT_SUCCEEDED);    
}       


Here is full code of script -please see comment next to string "en" and function at end of code.

#include "Hedge_v2.00.03_DoubleHedgeOrders.mq5"


//--- input parameters
input string   InpDirectory = "C:\\Users\########\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\MQL5\\Experts\\MyExperts\\Hedge";
string SrcDir = "C:\\Users\\########\\AppData\\Roaming\\MetaQuotes\\Tester\\D0E8209F77C8CF37AD8BF550E51FF075\\Agent-127.0.0.1-3000\\MQL5\\Files";
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

string en = globalNameGet(); //This is throwing a compile error "undeclared identifier
string path_name = InpDirectory;
string time = (TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS));
int time2   = StringReplace(time,":","-");
int eaName  = StringReplace(en, ".mq5", "");
int eaName2  = StringReplace(en, " ", "");
string filename = string(time) + "_REPORT_" + en + ".csv";

void withDrawnFunc() 
{
        double withDrawnGV = GlobalVariableGet("Withdrawn");
        if(withDrawnGV == NULL){delFile(); para2();}
        if(withdrawn>withDrawnGV){delFile(); para2();}
}



void para2()
{  
    int file_handle=FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV); 
    
    string cuntface = string(eaName);
    FileWrite(file_handle,cuntface);
    
    cuntface =
    ("InpLotType\t" + "InpLotEqu\t" + "LotFactor\t" + "InpLotDiv\t" + "TslTriggerPoints\t" + 
    "TslPoints\t" + "TslFirstSLPoints\t" + "InpDblHedge\t" + "withType\t" + "withdrawn\t" + "Magic"
    );
    FileWrite(file_handle,cuntface);
    cuntface = 
    (string(string(InpLotType) + "\t" +  string(InpLotEqu) + "\t" + string(LotFactor) + "\t" + 
    string(InpLotDiv) + "\t" + string(TslTriggerPoints) + "\t" + string(TslPoints) + "\t" + 
    string(TslFirstSLPoints) + "\t" + string(InpDblHedge) + "\t" + string(withType) + "\t" + 
    string(withdrawn) + "\t" + string(Magic)));
    FileWrite(file_handle,cuntface);
    
    double StartingBalance      = TesterStatistics(STAT_INITIAL_DEPOSIT);
    double FinalBalance         = TesterStatistics(STAT_PROFIT);
    double FinalWithdrawn       = TesterStatistics(STAT_WITHDRAWAL);
    double NumberOfTrades       = TesterStatistics(STAT_DEALS);
    
    cuntface = 
    ("StartingBalance\t" + "FinalBalance\t" + "FinalWithdrawn\t" + "NumberOfTrades");
    FileWrite(file_handle,cuntface);
    cuntface = 
    (string(string(StartingBalance) + "\t" + string(FinalBalance) + "\t" + string(FinalWithdrawn) + 
    "\t" + string(NumberOfTrades)));
    FileWrite(file_handle,cuntface);
       
//--- Flush Data to File and Close the data file
    FileFlush(file_handle);
    FileClose(file_handle);

    GlobalVariableSet("withDrawnGV",withdrawn);

}
void delFile()
{
    int fileHandle = FileDelete(filename,0);
    if(fileHandle == INVALID_HANDLE)
        {
            Print("failed to delete file");
        }
}

void copyFile()
{
    bool fileExist = FileIsExist(string(SrcDir + "\\" + filename),0);
    if (fileExist == true)
    {
        int copied = FileCopy(string(SrcDir + "\\" + filename), 0, string(path_name + filename), 0);
    }
}

string globalNameGet()
{
    uint   n=GlobalVariablesTotal();

    datetime max = 0;

    string myVal;

    for(uint i=0;i<n;i++)  {

        string name = GlobalVariableName(i);

        datetime wDt = GlobalVariableTime(name);

        if (wDt>max) 
        {
            if (name == "MyVar") 
            {
                max = wDt;
                en = name;
        
            }
        }
    }
    return myVal;
}
//+------------------------------------------------------------------+
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

File functionality in MetaTrader is sandboxed, so don't use full file paths, because you will not be able to access them.

Use only relative naming from within the sandboxed folder location (usually "<Data Folder>\MQL5\Files" or "%APPDATA%\MetaQuotes\Terminal\Common\Files" ).

 
Benny Addams: Others though always throw the compile error -undeclared identifier. I'm assuming that i have something wrong with programmatic flow.

Please identify which line and character position is being identified as a compile error.

Please note that you have an extra space between the dot and method name in the line marked in red.

int OnInit () {
    cTrade. SetExpertMagicNumber(Magic);        
    
    double doesnMatter = 0;
    string myValue = EAname;     //to be persisted forever
    datetime w = GlobalVariableSet("MyVar " + myValue, doesnMatter);

    return (INIT_SUCCEEDED);    
}       
 
Fernando Carreiro #:
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

Sure will do there is just so much noise and things are not really labelled correctly it seems. 

Thank you for the response.

 
Fernando Carreiro #:

Please identify which line and character position is being identified as a compile error.

Please note that you have an extra space between the dot and method name in the line marked in red.

Thanks missed that.
 
Benny Addams #:
Thanks missed that.
Compiler errors are subsequent. Meaning, fix always the first warning/error the compiler notifies you about. Then compile and fix the next. And so on.
 

I found an easy fix to this and some other problems i was having with variables not being visible from the main .mq5 file in an included file either .mqh or .mq5.


Place your #include statement at the bottom of the main file and all variables and functions will be visible COMPUTED in the include file