Opening HTML pages created by the Expert Advisor in the browser

Opening HTML pages created by the Expert Advisor in the browser

14 January 2026, 09:09
Aleksei Kuznetsov
1
99

Created to open HTML pages from Advanced Optimization Report.

Opens *.htm or *.html pages in the default browser.

Performs a preliminary security check:

  1. It is allowed to run only from the "Advanced Optimization Report.ex5".
  2. If the file extension is not .htm or .html, it stops working.
  3. Opens pages only from the file sandbox: from the /MQL5/Files/ or /Common/Files/ folder.
  4. You see the contents of the code and you compile it yourself.

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); 
   if(len==0){Print("Empy file name. Return.");return;}
   string allowed_ex5 = "Advanced_Optimization_Report";
   if( ChartGetString(0, CHART_EXPERT_NAME) != allowed_ex5){
      Alert("Only ",allowed_ex5,".ex5 can open HTML pages."); return;
   }
   if(StringSubstr(file, len-4) !=".htm" && StringSubstr(file, len-5) !=".html"){
      Alert("Only .htm or .html pages allowed! Rename the page."); return;
   }
   if ((bool)::MQLInfoInteger(MQL_DLLS_ALLOWED)){
      string page;
      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.

Files:
HTML_Open.mq5  4 kb