Opening HTML pages created by the Expert Advisor in the browser

14 January 2026, 09:09
Aleksei Kuznetsov
0
30

Opens *.htm or *.html pages in the default browser.
Performs a preliminary security check:

  1. If the file extension is not .htm or .html, it stops working.
  2. Opens pages only from the file sandbox: from the /MQL5/Files/ or /Common/Files/ folder.

Usage:

  1. Create an HTML file with your Expert Advisor or script and save it to /Files/ folder.
  2. Then call this indicator with the path from the /Files/ folder to the desired file and the Common or MQL5 folder type indicator.

Example code for opening an HTML page:

int HTMLOpen=-1;
void Open(string file,bool isCommon=true){
   if(HTMLOpen!=INVALID_HANDLE){IndicatorRelease(HTMLOpen);}//delete it if it was called earlier
   HTMLOpen=iCustom(NULL,0,"HTML_Open.ex5",file,isCommon);
}

Open("test.htm", true);
Open("test1.htm", true);

After that, the page will open in the browser.

The "HTML_Open" indicator code is small, and anyone can check its security:

#property indicator_chart_window
#property indicator_plots 0
sinput string file;//file in \Files\ folder
sinput bool isCommon;

int OnInit() { OpenHTML(); return(INIT_FAILED); }
int OnCalculate(const int32_t rates_total, const int32_t prev_calculated,const int32_t begin,const double &price[]){return(rates_total);}

#import "shell32.dll"
   int ShellExecuteW( int, string, string, string, string, int );
#import

void OpenHTML() {
   int len= StringLen(file); string page;
   if(StringSubstr(file, len-4) !=".htm" && StringSubstr(file, len-5) !=".html"){
      Alert("Only .htm or .html pages allowed! Rename the page.");
   }
   if ((bool)::MQLInfoInteger(MQL_DLLS_ALLOWED)){
      if(isCommon){
         page = ::TerminalInfoString(TERMINAL_COMMONDATA_PATH) + "\\Files\\"+file;
      }else{
         page = ::TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\"+file;
      }
      shell32::ShellExecuteW(0, "Open", page, NULL, NULL, 3);
   }else{
      Alert("DLL not allowed! Can't to open HTML page in browser. Allow the DLL in the settings.");
   }
}

To add an indicator to the terminal:

  1. Download the attached file
  2. Or create a new indicator, name it "HTML_Open" and paste the code from this page into it.
  3. Compile it.

I ask other programmers to comment on the indicator's security. In my opinion, all vulnerabilities have been closed.

A suggestion for MetaQuotes developers: please add a function for opening HTML pages in the terminal with similar checks.


Files:
HTML_Open.mq5  3 kb