Download MetaTrader 5
To add comments, please log in or register
You don't know MQL5 but you do know how to sell? The affiliate program is at your service!
trader88888
131
trader88888 2014.11.18 00:56 

Hello,

I believe this is a simple issue (however I'm not a developer) but I'm trying to get this old code to compile on the new 600+ builds.  The error I'm getting is:

  'start' - function already defined and has body

 I don't understand this because i can't find a "start" anywhere else in the code so not sure how it's already define.  I was hoping that someone might be able to change it around and paste the full code again so I can just copy and paste it and try to compile again?  Thank you!!

 

//+------------------------------------------------------------------+
//|                                              RemotePublisher.mq4 |
//|                                                           Me     |
//+------------------------------------------------------------------+
#property copyright "Remote Publisher"
#property link      "email@me.com"
#property indicator_chart_window

#include "..\include\WinUser32.mqh"
#include "..\libraries\RemoteQueryLib.mq4"


extern   string Symbols          =  "EURUSD, GBPUSD";                            // The comma-separated list of symbols.
extern   string PUBLISH_URL      =  "http://localhost:1975/quotes_update.php";   // The PHP update URL.
extern   int    Update_Interval  =  5;                                           // Refresh interval in seconds.

#define  SINGLETON_SEMAPHORE     "RemoteQuotesPublisher"       // Global Variables for single instance.

bool     m_bCanRun            =  false;      // Whether the indicator can run - sufficient inputs ?      
int      m_nSymbolCount       =  0;          // The number of symbols to process.
datetime m_dtLastPublishTime  =  0;          // The last updated date time.

string   SYMBOLS[RQL_QUOTES_MAX_SYMBOLS];    // The array of symbols.
double   PRICES[RQL_QUOTES_MAX_SYMBOLS];     // The array of prices.


//////////////////////////////////////////////////////////////////////
// init
//////////////////////////////////////////////////////////////////////
int init()
{   
   Comment("");
   m_dtLastPublishTime = 0;
   
   // Ensure that Update_Interval is atleast 2 seconds.
   Update_Interval = MathMax(2, Update_Interval);
   
   // Run this indicator only if first instance.
   // The first instance of the indicator creates the global variable.
   m_bCanRun = !GlobalVariableCheck(SINGLETON_SEMAPHORE);   
   if( m_bCanRun )
      // Initialize global variable.
      GlobalVariableSet(SINGLETON_SEMAPHORE, 1);   
   else
   // An instance is already running. Show message and exit.
   {
      Alert(Symbol(), " : An instance of ", WindowExpertName(), " is already running. ",
            WindowExpertName(), " will be DISABLED on this chart.");
      Comment("\n ", WindowExpertName(), " ALREADY RUNNING on another chart.");
      return (0);
   }
   // Now parse the user input symbols.
   parseSymbols();
   if( m_nSymbolCount == 0 )
   // None of the user input symbols were found. Therefore exit.
   {
      m_bCanRun = false;
      Alert(Symbol(), " : No valid symbols selected. ", WindowExpertName(), " will be DISABLED.");
      Comment("\n ", WindowExpertName(), " NO VALID SYMBOLS.");
      return (0);
   }
   // Now publish the quotes for the first time.
   publishQuotes();
   return(0);
}


//////////////////////////////////////////////////////////////////////
// deinit
//////////////////////////////////////////////////////////////////////
int deinit()
{
   // If this is the first instance that, then delete the global semaphore.
   if( m_bCanRun ) GlobalVariableDel(SINGLETON_SEMAPHORE);
   return(0);
}

//////////////////////////////////////////////////////////////////////
// start
//////////////////////////////////////////////////////////////////////
int start()
{
   if( !m_bCanRun ) return (0);
   // If Update_Interval seconds have elapsed since the last publish,
   // the query and publish the quotes.
   if( TimeCurrent() - m_dtLastPublishTime >= Update_Interval )
      publishQuotes();
   return(0);
}

//////////////////////////////////////////////////////////////////////
// Function :  parseSymbols
// Parse the symbols provided by the user and store them 
// in the SYMBOLS array.
//////////////////////////////////////////////////////////////////////
void parseSymbols()
{
   // Retrieve the complete list of (selected) Symbols in MT4.
   string arrList[];
   int nSymbols = SymbolsList(arrList);
   string sUserList = StringToUpper(Symbols);
   m_nSymbolCount = 0;
   // Now iterate through every MT4 symbol and check whether it is in the user-input list.
   for( int i = 0; i < nSymbols; i++ )
   {
      // The symbol is in the user-input list, therefore we track and update it.
      if( StringFind(sUserList, StringToUpper(arrList[i])) >= 0 )
      {
         // Make sure the symbol has valid quotes.
         if( MarketInfo(arrList[i], MODE_BID)  > 0 || MarketInfo(arrList[i], MODE_ASK) > 0 ||
             MarketInfo(arrList[i], MODE_HIGH) > 0 || MarketInfo(arrList[i], MODE_LOW) > 0 )
         {
            SYMBOLS[m_nSymbolCount] = arrList[i];  // Add it to the Symbol list.
            PRICES[m_nSymbolCount] = 0.0;          // Initialize the price.   
            m_nSymbolCount++;                      // Increment the symbol count.
            // Maximum number of symbols that can be published at a time has reached
            // the limit.
            if( m_nSymbolCount >= RQL_QUOTES_MAX_SYMBOLS ) break;
         }      
      }   
   }
}

//////////////////////////////////////////////////////////////////////
// Function :  publishQuotes
// Iterates through the SYMBOLS array, queries the BID price for 
// each symbol. If it has changed from the last time published, then
// it publishes it.
//////////////////////////////////////////////////////////////////////
void publishQuotes()
{
   string sError = "";
   for( int i = 0; i < m_nSymbolCount; i++ )
   // Walk through the symbols.
   {
      // Get the BID price.
      double dNewPrice = MarketInfo(SYMBOLS[i], MODE_BID);
      double dOldPrice = PRICES[i];
      
      if( dNewPrice > 0.0 && (dOldPrice != dNewPrice) )
      // If BID has changed and is not zero.
      {   
         // Publish the quote to the server via the publishQuote function.
         if( !publishQuote(PUBLISH_URL, SYMBOLS[i], dNewPrice, TimeCurrent(), sError) )
         {
            Alert(WindowExpertName(), " : Publish Error for ", SYMBOLS[i], "[", 
                  DoubleToStr(dNewPrice, MarketInfo(SYMBOLS[i], MODE_DIGITS)), "] - ", sError);
            Print(WindowExpertName(), " : Publish Error for ", SYMBOLS[i], "[", 
                  DoubleToStr(dNewPrice, MarketInfo(SYMBOLS[i], MODE_DIGITS)), "] - ", sError);
         }
         else
            PRICES[i] = dNewPrice;  // Quote published to the server. Now update the local copy.
      }
   }
}
JDeel
228
JDeel 2014.11.18 01:35  
"extern" is now "input". init() is now OnInit(). start() is now OnTick(). deinit() is now OnDeinit();
whroeder1
13630
whroeder1 2014.11.18 02:28  
trader88888: i can't find a "start" anywhere else in the code so not sure how it's already define.  I was hoping that someone might be able to change it around and paste the full code again so I can just copy and paste it and try to compile again?
  1. Have you looked in your
    #include "..\libraries\RemoteQueryLib.mq4"
    
  2. We can't compile it unless you provide all the include files.
  3. JDeel:
    "extern" is now "input". init() is now OnInit(). start() is now OnTick(). deinit() is now OnDeinit();
    The old functions are still viable.
trader88888
131
trader88888 2014.11.18 03:57  
WHRoeder:
  1. Have you looked in your
  2. We can't compile it unless you provide all the include files.
  3. JDeel:
    "extern" is now "input". init() is now OnInit(). start() is now OnTick(). deinit() is now OnDeinit();
    The old functions are still viable.

WHRoeder, thank you, here is the file you mentioned for the includes.  I believe the others are standard in mt4 except for this one:  (..\libraries\RemoteQueryLib.mq4")

 

//+------------------------------------------------------------------+
//|                                               RemoteQueryLib.mq4 |
//+------------------------------------------------------------------+
#property copyright "me"
#property link      "me@me.com"

#define   RQL_VERSION               1.02        // Version of the RemoteQuery library.
#define   RQL_MAX_PARAMS            16          // Maximum number of parameters to retrieve.
                                                // Increase this number if you expect more parameters.
#define   RQL_KEY_VALUE_PAIR_TAG    "DATA"      // The XML node that encapsulates the key-value pair.
#define   RQL_KEY_TAG               "PARAM"     // The tag the encapsulates the parameter name.
#define   RQL_VALUE_TAG             "VALUE"     // The tag that encapsulates the parameter value.
#define   RQL_ERROR_TAG             "ERROR"     // The error tag.

#define   RQL_QUOTES_MAX_SYMBOLS    32          // Maximum symbols that can be published. Increase if you plan to publish more.
#define   RQL_QUOTES_SUCCESS_TAG    "SUCCESS"   // Quotes update success tag.

#include <stderror.mqh>
#include <stdlib.mqh>

#import "wininet.dll"
   int InternetAttemptConnect(int a0);
   int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
   int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
   int InternetReadFile(int a0, int& a1[], int a2, int& a3[]);
   int InternetCloseHandle(int a0);
#import


////////////////////////////////////////////////////////////////////////////////
// Function :  queryParams
//
// Inputs   :  sUrl - The HTTP URL (can be PHP, HTML, etc).
// Output   :  nParamCount - The number of parameters found on the URL
//             sParams[] - Array of the parameter names.
//             sValues[] - Array of the parameter values.
//             sError - The error message if any error occurred
// Result   :  TRUE if URL was successfully accessed and parameters queried.
//             FALSE if there was an error or no parameters were queried.
// The format of the URL data is
// <dbdata>
// <data><param>X1</param><value>44.25</value></data>
// <data><param>X2</param><value>12.15</value></data>
// </dbdata>
////////////////////////////////////////////////////////////////////////////////
bool queryParams(string sUrl, int &nParamCount, string &sParams[], string &sValues[], string &sError)
{
   bool bSuccess = false;           // Return value.
   nParamCount = 0; sError = "";    // Initialize.
   if( StringLen(sUrl) <= 3 )
   // The URL should be atleast 3 characters.
   {
      sError = "Invalid URL. The URL should be atleast 3 characters.";
      return (bSuccess);
   }
   
   string sData = "";
   int nKeyBeginIndex = 0;
   if( getUrlData(sUrl, sData, sError) )
   // Retrieve the URL page data.
   {
      string sSrcData = StringToUpper(sData);
      string sBeginPairTag = StringConcatenate("<", RQL_KEY_VALUE_PAIR_TAG, ">");
      string sEndPairTag = StringConcatenate("</", RQL_KEY_VALUE_PAIR_TAG, ">");
      nKeyBeginIndex = StringFind(sSrcData, sBeginPairTag, nKeyBeginIndex);
      // Keep search for <data></data>, and then parse the contents between them,.
      while (nKeyBeginIndex > 0)
      {
         int nKeyEndIndex = StringFind(sSrcData, sEndPairTag, nKeyBeginIndex + StringLen(sBeginPairTag)); 
         if( nKeyEndIndex > 0 )
         {
            string sPairTag = StringSubstr(sData, nKeyBeginIndex + StringLen(sBeginPairTag), 
                                           nKeyEndIndex - nKeyBeginIndex - StringLen(sBeginPairTag));
                                           
            nKeyBeginIndex = nKeyEndIndex + StringLen(sEndPairTag);
            string sKey = "", sValue = "";
            if( getXmlTagData(sPairTag, RQL_KEY_TAG, sKey) )
            {
               if( StringLen(sKey) > 0 )
               {
                  if( getXmlTagData(sPairTag, RQL_VALUE_TAG, sValue) )
                  {
                     sParams[nParamCount] = sKey;
                     sValues[nParamCount] = sValue;
                     nParamCount++;
                     if( nParamCount >= RQL_MAX_PARAMS ) break;
                  }            
               }
            }
         }
         else
            break;      
      }
   }
   if( nParamCount > 0 ) 
      bSuccess = true;
   else
   {
      if( !getXmlTagData(sData, RQL_ERROR_TAG, sError) )
         sError = "Invalid format or no data.";
   }
   return (bSuccess);
}

//////////////////////////////////////////////////////////////////////////////////////////
// Function :  getXmlTagData
// Purpose  :  Retrieves the data within the specified XML tag.
//             Returns TRUE if the tag was found, otherwise returns FALSE.
// Inputs   :  sInput - The input data.
//             sTag - The tag within which to search.
//             sData - The output data.
// E.g.        If sInput is "<param>S1</param><value>44</value>" and sTag = "param", then
//             returns "S1" since it is between <param> and </param>
//////////////////////////////////////////////////////////////////////////////////////////
bool getXmlTagData(string sInput, string sTag, string &sData)
{
   bool bFound = false;
   string sSrcData = StringToUpper(sInput);
   string sBeginPairTag = StringConcatenate("<", sTag, ">");
   string sEndPairTag = StringConcatenate("</", sTag, ">");
   int nBeginIndex = StringFind(sSrcData, sBeginPairTag);
   if( nBeginIndex >= 0 )
   {
      int nEndIndex = StringFind(sSrcData, sEndPairTag, nBeginIndex + StringLen(sBeginPairTag)); 
      if( nEndIndex > 0 )
      {
         string sItem = StringSubstr(sInput, nBeginIndex + StringLen(sBeginPairTag), 
                                     nEndIndex - nBeginIndex - StringLen(sBeginPairTag));
         sItem = StringTrimRight(StringTrimLeft(sItem));
         sData = sItem;
         return (true);         
      }
      else
         return (false);
   }
   else
      return (false);
}

//////////////////////////////////////////////////////////////////////////////////////////
// Function :  getUrlData
// Purpose  :  Retrieves the contents of the specified URL.
//             Returns true if successful, otherwise returns false.
// Inputs   :  sUrl - The URL to query.
// Outputs  :  sPageData - The URL contents.
//             sError - The error message in case an error was encounted.
//////////////////////////////////////////////////////////////////////////////////////////
bool getUrlData(string sUrl, string &sPageData, string &sError) 
{
   int sReadBuffer[256], lia_24[1], li_40;
   string sBuffer;
   sPageData = "";
   int hConnect = InternetAttemptConnect(0);
   if (hConnect != 0) 
   {
      sError = "Unknown error attempting to connect to Internet.";
      return (false);
   }
   int hInet = InternetOpenA("Microsoft Internet Explorer", 0, "", "", 0);
   if (hInet <= 0) 
   {
      sError = "Unknown error while attempting to acquire internet session.";
      return (false);
   }
   int hURL = InternetOpenUrlA(hInet, sUrl, "", 0, -2080374528, 0);
   if (hURL <= 0) 
   {
      InternetCloseHandle(hInet);
      sError = "Unable to find requested URL.";
      return (false);
   }

   while (!IsStopped()) 
   {
      for (int nIndex = 0; nIndex < 256; nIndex++) 
         sReadBuffer[nIndex] = 0;
      li_40 = InternetReadFile(hURL, sReadBuffer, 1024, lia_24);
      if (lia_24[0] == 0) break;
      sBuffer = "";
      for (nIndex = 0; nIndex < 256; nIndex++) 
      {
         sBuffer = sBuffer + CharToStr(sReadBuffer[nIndex] & 255);
         if (StringLen(sBuffer) == lia_24[0]) break;
         sBuffer = sBuffer + CharToStr(sReadBuffer[nIndex] >> 8 & 255);
         if (StringLen(sBuffer) == lia_24[0]) break;
         sBuffer = sBuffer + CharToStr(sReadBuffer[nIndex] >> 16 & 255);
         if (StringLen(sBuffer) == lia_24[0]) break;
         sBuffer = sBuffer + CharToStr(sReadBuffer[nIndex] >> 24 & 255);
      }
      sPageData = sPageData + sBuffer;
      Sleep(1);
   }
   InternetCloseHandle(hInet);
   if (sPageData == "")
   {
      sError = "No data.";
      return (false);
   }
   return (true);
}


//////////////////////////////////////////////////////////////////////////////////////////
// Function :  StringToUpper
// Purpose  :  Converts the passed string to upper case and returns it.
//////////////////////////////////////////////////////////////////////////////////////////
string StringToUpper(string sText) 
{
   int nFindIndex = 0;
   string sOutput = "";
   string sLowerSet = "abcdefghijklmnopqrstuvwxyz";
   string sUpperSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   for (int i = 0; i < StringLen(sText); i++) 
   {
      nFindIndex = StringFind(sLowerSet, StringSubstr(sText, i, 1), 0);
      if (nFindIndex >= 0) 
         sOutput = sOutput + StringSubstr(sUpperSet, nFindIndex, 1);
      else 
         sOutput = sOutput + StringSubstr(sText, i, 1);
   }
   return (sOutput);
}


//////////////////////////////////////////////////////////////////////////////////////////
// Function :  SymbolsList
// Purpose  :  Returns the list of Symbols supported by MT4.
//////////////////////////////////////////////////////////////////////////////////////////
int SymbolsList(string &Symbols[])
{
   string SymbolsFileName = "symbols.sel";
   int hFile = FileOpenHistory(SymbolsFileName, FILE_BIN|FILE_READ);
   if(hFile < 0) return(-1);
   int SymbolsNumber = (FileSize(hFile) - 4) / 128; 
   int Offset = 116;
 
   ArrayResize(Symbols, SymbolsNumber);
   FileSeek(hFile, 4, SEEK_SET);
   for(int i = 0; i < SymbolsNumber; i++)
   {
      Symbols[i] = FileReadString(hFile, 12);
      FileSeek(hFile, Offset, SEEK_CUR);
   }
   FileClose(hFile);
   return(SymbolsNumber);
}
 
//////////////////////////////////////////////////////////////////////////////////////////
// Function :  publishQuote
// Purpose  :  Publishes the quotes to the server, and returns the result.
// Inputs   :  sURL - The PHP publish URL.
//             sSymbol - The symbol string.
//             dPrice - The bid price.
//             dtTime - The Broker Time (UNIX timestamp).
// Outputs  :  sError - The error message if any.              
//////////////////////////////////////////////////////////////////////////////////////////
bool publishQuote(string sURL, string sSymbol, double dPrice, datetime dtTime, string &sError)
{
   // Create the HTTP PHP posting URL.
   string sPostUrl = StringConcatenate(sURL, "?s=", sSymbol, "&p=", dPrice, "&t=", dtTime);
   string sResult = "";
   sError = "";
   // Post the data.
   if( getUrlData(sPostUrl, sResult, sError) )
   {
      // We have got result.
      // Search for <success> tag. If we find it, then posting was successful.
      if( StringFind(StringToUpper(sResult), "<" + RQL_QUOTES_SUCCESS_TAG + ">") >= 0 )
         return (true);
      else
      {
         // Otherwise, search for <error>.....</error> tag.
         // If we find it return the error message.
         sError = "Unknown error.";      
         string sErrorCode = "";
         getXmlTagData(sResult, RQL_ERROR_TAG, sErrorCode);
         if( StringLen(sErrorCode) > 0 )
            sError = sErrorCode;
         return (false);
      }    
   } 
   else
      return (false);
}

 

 Thank you for any assistance in advance!

whroeder1
13630
whroeder1 2014.11.18 13:39  
   int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
   int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
  1. Don't know what/were your compile error is.
  2. Since build 600 all mt4 strings are Unicode. Those ANSI functions will not work. Find an updated library.
  3. Your  SymbolsList could be rewritten to use the new functions SymbolName - MQL4 Documentation


/
To add comments, please log in or register