Hi Everyone I am a long term user of Metrader. Literally Since version two or three. I have been a ghost for the most part on forex factory for years. But several Epoch users have posted so much helpful code . I thought I had better share. In metatrader what i have spent most of my time on regrettably is error trapping and deBugging. Over the years I had to develop Extensive Error Traps with in the Eas. Also I would Never ever use a public or pay ea again with out these types of traps. Also the eas must integrate news or they will not work correctly.. With that Said I recently found out that they are going to metatrader five. I am fearful of a Hellish Upgrade cycle like build 600 . They have already put out two builds since august. Augh!. I am starting this thread to Help. I am hoping to help convert code over to metatrader five so we can all run it with confidence it is working correctly. I have not used metatrader five yet but I am sure I will be. I am not a professional coder. I just love trading. I am a self taught coder with good mentors. With that said. I will post some code that can help. The thread list below is motivating to me post this stuff. https://www.forexfactory.com/showthr...7#post12611487 . One Last thing . I am dyslexic and I dislike writing so If U are up set by spelling and grammar move along.. ) Oh the 1st code will be posting is how to prevent a upgrade and how to tell if you are being upgraded. Side note not all the code posted below is run all the time. It slows things down a lot.
Similar Threads
The real Basics - how to start and how avoid the traps 221 replies
EA error message (0) no error 6 replies
How to Access your Metatrader Platform MT4/MT5 Remotely 5 replies
MT4 EA error- when placing trade getting error 0 rate on ask 3 replies
:: Smithy's Live Trades :: (EMA's / Pivots / News Traps) 10 replies

- | Joined Nov 2012 | Status: Member | 65 Posts
1st off on int . Set a gvar for BuildNumber and on It. At least you will know a new build is out.
Second Run batch file that will remove every thing in the \AppData\Roaming\MetaQuotes\WebInstall\ On your testing pc move the contents some place else You need to Keep these files so U can roll back...... Now on the trading pc. I remove everything and replace it with the build I am complied 2. In the code above You should also Check the compiler version. I am going to bed tonight But I will add more code tomorrow on error trapping. Last Thing for those of you who did not know your upgrades come in as .PNG files. Also I keep a file that is updated with every new function I make and what build it is compiled 2 . I will post that tomorrow.
Inserted Code
if(dGetGVar(string sParamName) != _MQL4BUILD_ ) {bSetGvar("Build",_MQL4BUILD_);Comment("Build has changed "); //+-------------------------------------------------------------------+ //| | //| Function Name: bSetGvar.. | //| | //+----------------------------------------------------------------- --+ bSetGvar("Build",_MQL4BUILD_); bool bSetGvar(string sParamName, double dParamStore = 0 ) { //+-------------------------------------------------------------------+ //| Local Variables Initialization | //+-------------------------------------------------------------------+ bool bReturnThis = True; //+----- Else true int iError = 0; string szGlobalVar = ""; //+-------------------------------------------------------------------+ //| Main body | //+-------------------------------------------------------------------+ if(dParamInfo2 == deLogAllSymbols ) { sParamSymbol = "MasterSym"; iPramaTimeFrame = 1; } szGlobalVar = sParamName ; if(GlobalVariableSet(szGlobalVar, dParamStore) == 0) { iError = GetLastError(); ResetLastError(); // if( iError !=0) Print(__FUNCTION__+" "+IntegerToString(iError)+" "+ IntegerToString(__LINE__)+" "+szGlobalVar); bReturnThis = false; } //+-------------------------------------------------------------------+ //| Deinitialization of Function | //+-------------------------------------------------------------------+ //+----- Close files and release arrays //+-------------------------------------------------------------------+ //| End of Function | //+-------------------------------------------------------------------+ return(bReturnThis); } //+-------------------------------------------------------------------+ //| | //| Function Name: dGetGVar.. | //| | //+-------------------------------------------------------------------+ double dGetGVar(string sParamName) { //+-------------------------------------------------------------------+ //| Local Variables Initialization | //+-------------------------------------------------------------------+ double dReturnThis = 0.0; //+----- Else return int int iError = 0; string szGlobalVar = ""; //+-------------------------------------------------------------------+ //| Main body | //+-------------------------------------------------------------------+ if(dParamInfo2 == deLogAllSymbols ) { sParamSymbol = "MasterSym"; iPramaTimeFrame = 1; } szGlobalVar = sParamName ; if(GlobalVariableCheck(szGlobalVar) == True) { dReturnThis = GlobalVariableGet(szGlobalVar); } else { iError = GetLastError(); ResetLastError(); // if( iError !=0) Print(__FUNCTION__+" "+IntegerToString(iError)+" "+ IntegerToString(__LINE__)+" "+szGlobalVar); dReturnThis = 0.0; } //+-------------------------------------------------------------------+ //| Deinitialization of Function | //+-------------------------------------------------------------------+ return(dReturnThis); }
Second Run batch file that will remove every thing in the \AppData\Roaming\MetaQuotes\WebInstall\ On your testing pc move the contents some place else You need to Keep these files so U can roll back...... Now on the trading pc. I remove everything and replace it with the build I am complied 2. In the code above You should also Check the compiler version. I am going to bed tonight But I will add more code tomorrow on error trapping. Last Thing for those of you who did not know your upgrades come in as .PNG files. Also I keep a file that is updated with every new function I make and what build it is compiled 2 . I will post that tomorrow.
1
- | Joined Nov 2012 | Status: Member | 65 Posts
This is the code you need to import shell execute. U can write the batch file
ShellExecuteW(0, (int)("open"), sPath + "\\Move.bat", 0, . "C:\Users\<<me>>\AppData\Roaming\MetaQuotes\WebInstall", 1);
you use TerminalInfoString(TERMINAL_COMMONDATA_PATH) and subtract back to metaquotes and add on "WebInstall". I hard coded mine. C:\Users\<<me>>\AppData\Roaming\MetaQuotes\WebInstall
Inserted Code
#import "shell32.dll" //---- defining ShellExecute /* Normally we should define ShellExecute like this: int ShellExecuteA(int hWnd,string lpVerb,string lpFile,string lpParameters,string lpDirectory,int nCmdShow); But, we need to keep lpVerb,lpParameters and lpDirectory as NULL pointer to this Function*/ //---- So we need to define it as (look: "string" Parameters defined as "int" to keep them NULL): int ShellExecuteW(int hWnd,int lpVerb,string lpFile,int lpParameters,int lpDirectory,int nCmdShow); #import
you use TerminalInfoString(TERMINAL_COMMONDATA_PATH) and subtract back to metaquotes and add on "WebInstall". I hard coded mine. C:\Users\<<me>>\AppData\Roaming\MetaQuotes\WebInstall
- | Joined Nov 2012 | Status: Member | 65 Posts
Ok Here is a Bunch of Code for trapping errors and Debugging. It is an Array . mcaGOD[]
In the public section of my main includes I call
Next I have several functions that add the index one uses sql one use the local drive. I am posting the one to the local drive. a quick Note 'm' means it is a member of a class ca for lack of a better word is a class array.
This loades the Array on Int. OR when the function is not found.
Inserted Code
//+-------------------------------------------------------------------+ //| Function Name: CAStackTrace. | //| Description: Global Operation Debugger / Stack Trace | //| CAStackTrace.mqh mcaGOD[]; | //+-------------------------------------------------------------------+ #include <\FATTools Type Cast\caBNForexClass Array\caStackTrace.mqh>
Inserted Code
CAStackTrace mcaGOD[2000]; //+----- [ iIndexKey ] iIndexKey = iFunction / Not meant to change the program at all but stop
Inserted Code
//+-------------------------------------------------------------------+ //| | //| Function Name: iAddGodFuncNum.. | //| Purpose: GOD Global Operation debugger / StackTrace | //+-------------------------------------------------------------------+ int CBNForexFunctions::iAddGodFuncNum(string sParamFunction, string sParamLocation , string sParam_Function_SIG) { //+-------------------------------------------------------------------+ //| Initialization of Function | //+-------------------------------------------------------------------+ //+----- It is a script or indicator leave //+-------------------------------------------------------------------+ //| Local Variables Initialization | //+-------------------------------------------------------------------+ //+---- Standard variables Names ----+// bool bFileWriteResults = false; bool bFileSeekResults = false; bool bFoundAnother = False; int iReturnThis = 0; int iLastRecord = 0; int iCount = 0; int y = 0; int z = 0; int iStringReplaceResults = 0; int iFileHandle = 0; string sModSIG = sParam_Function_SIG; string sModType = sParamLocation; string sPath = ""; string sFileName = ""; string sFileOut = ""; string sFileIn = ""; uint uintFileWriteResults = 0; //+-------------------------------------------------------------------+ //| Main body | //+-------------------------------------------------------------------+ iStringReplaceResults = StringReplace(sParam_Function_SIG,Comma," "); //+-------------------------------------------------------------------+ //| Loads array | //+-------------------------------------------------------------------+ //+-1- Function Name +-6- Parameter inputed +-11- sDebuggerURL2 //+-2- Type Function +-7- Defines Used +-12- sNetInfo //+-3- Location +-8- What is Returned +-13- Build Number //+-4- Description +-9 - Vaddress +-14- Number //+-5- Function Status +-10- sDebuggerURL1 //+-------------------------------------------------------------------+ sPath = "FATTools\\Developer Information\\Library\\"; sFileName = sPath + "Function library.csv"; iFileHandle = FileOpen(sFileName,FILE_READ|FILE_CSV,","); if( iFileHandle>0 ) { bFileSeekResults = FileSeek(iFileHandle,0,SEEK_SET); while(!FileIsEnding(iFileHandle)) { sFileIn = FileReadString(iFileHandle,0); if( sFileIn != "") { z++; if( z == 1 ) mcaGOD[ y ].sFutName = sFileIn; if( z == 2 ) mcaGOD[ y ].sFutType = sFileIn; if( z == 3 ) mcaGOD[ y ].sFutPath = sFileIn; if( z == 4 ) mcaGOD[ y ].sDescOfFunction = sFileIn; if( z == 5 ) mcaGOD[ y ].sFunctionStatus = sFileIn; if( z == 6 ) mcaGOD[ y ].sParameterInputed = sFileIn; if( z == 7 ) mcaGOD[ y ].sDefineUsed = sFileIn; if( z == 8 ) mcaGOD[ y ].sWhatisReturned = sFileIn; if( z == 9 ) mcaGOD[ y ].sAddress = sFileIn; if( z == 10) mcaGOD[ y ].sDebuggerURL1 = sFileIn; if( z == 11) mcaGOD[ y ].sDebuggerURL2 = sFileIn; if( z == 12) mcaGOD[ y ].sNetInfo = sFileIn; if( z == 13) mcaGOD[ y ].sBuildNumberDrive = sFileIn; if( z == 14) mcaGOD[ y ].iFunNum = (int)sFileIn; mcaGOD[ y ].sEAName = msEAName; mcaGOD[ y ].sEASymbol = msEASymbol; mcaGOD[ y ].iEATimeFrame = miEATimeFrame; mcaGOD[ y ].iEATypeOfTrade = miEATypeOfTrade; mcaGOD[ y ].sCurrentBuild = (string)__MQL4BUILD__ ; mcaGOD[ y ].sStalllKillWait = (string)menTradingStatus; if( z == 14) { z = 0; y++; } } } //<---- FileIsEnding(iFileHandle) ----> } if(iFileHandle>0) { FileClose(iFileHandle); iFileHandle = 0; } //+---- read the string into sSplitResults array //+-------------------------------------------------------------------+ //| Information about Function | //+-------------------------------------------------------------------+ //+-1- Function Name +-6- Parameter inputed +-11- sDebuggerURL2 //+-2- Type Function +-7- Defines Used +-12- sNetInfo //+-3- Location +-8- What is Returned +-13- Build Number //+-4- Description +-9 - Vaddress +-14- Number //+-5- Function Status +-10- sDebuggerURL1 //+-------------------------------------------------------------------+ for ( z=1 ; z<= miGODMaxRecords-1; z++) { if( iLastRecord < mcaGOD[ z ].iFunNum ) iLastRecord = mcaGOD[ z ].iFunNum ; ; } //+----- Move it up one iLastRecord = iLastRecord+1; //+-------------------------------------------------------------------+ //| Is it already in the file No | //+-------------------------------------------------------------------+ sPath = "FATTools\\Developer Information\\Logs\\"; sFileName = sPath + "No Function library Documentation.csv"; iFileHandle = FileOpen(sFileName,FILE_WRITE|FILE_READ|FILE_CSV,","); if( iFileHandle >0) bFileSeekResults = FileSeek(iFileHandle,0,SEEK_SET); //+-------------------------------------------------------------------+ //| Have we Reported this in older logs | //+-------------------------------------------------------------------+ if( iFileHandle> 0 && bFileSeekResults) { while(!FileIsEnding(iFileHandle)) { sFileIn = FileReadString(iFileHandle,0); if(sParamFunction == sFileIn) { bFoundAnother = true; break;} z++; } //+----- End While if( !bFoundAnother ) { sFileOut = "Please Enter the information about this Function " + Comma + sParamFunction + Comma + sParamLocation + Comma + "Time inserted" + Comma + TimeToStr(TimeCurrent()); bFileSeekResults = FileSeek(iFileHandle,0,SEEK_END); if(bFileSeekResults) uintFileWriteResults = FileWrite(iFileHandle,sFileOut); if( uintFileWriteResults>0 ) bFileWriteResults = True; if( uintFileWriteResults == 0) bFileWriteResults = False; }//+----- Found one } if( iFileHandle >0) { FileClose(iFileHandle); iFileHandle = 0 ;} //+-------------------------------------------------------------------+ //| Have we Reported this in older logs no | //+-------------------------------------------------------------------+ sPath = "FATTools\\Developer Information\\Library\\"; sFileName = sPath + "Function library.csv"; iFileHandle = FileOpen(sFileName,FILE_WRITE|FILE_READ|FILE_CSV,","); if(iFileHandle>0) { bFileSeekResults = FileSeek(iFileHandle,0,SEEK_END); sModType = sStringRepalceAscii(sModType); } //+-------------------------------------------------------------------+ //+-1- Function Name +-7- Defines Used //+-2- Type Function +-8- What is Returned +-11- sNetInfo //+-3- Location +-9- Vaddress +-12- Build Number //+-4- Description +-10- sDebuggerURL2 +-13- bRrecursive //+-5- Function Status +-11- sDebuggerURL2 //+-6- Parameter inputed +-12- sNetInfo +-14- iFunNum //+-------------------------------------------------------------------+ if( iFileHandle>0 && bFileSeekResults ) { sFileOut = sParamFunction + Comma + //+----- Function Name sModType + Comma + //+----- Function Type sParamLocation + Comma + //+----- Includes File "n/a " + Comma + //+----- Desc Of Function "n/a " + Comma + //+----- Function Status sParam_Function_SIG + Comma + //+---- Parameter inputed "n/a " + Comma + //+----- Defines Used "n/a " + Comma + //+----- What is Returned "n/a " + Comma + //+-Debugger---- vAddress "n/a " + Comma + //+----- Debugger URL1 "n/a " + Comma + //+----- Debugger URL2 "n/a " + Comma + //+----- NetInfo sI2S(TerminalInfoInteger(TERMINAL_BUILD)) + Comma + //+----- __MQL4BUILD__ sI2S(iLastRecord); //+----- sTrackingNumber if(bFileSeekResults) uintFileWriteResults = FileWrite(iFileHandle,sFileOut); if( uintFileWriteResults>0 ) bFileWriteResults = True; if( uintFileWriteResults == 0) bFileWriteResults = False; iReturnThis = iLastRecord+1; mcaGOD[ iLastRecord ].sFutName = sParamFunction; mcaGOD[ iLastRecord ].sFutType = sModType; mcaGOD[ iLastRecord ].sFutPath = sParamLocation; mcaGOD[ iLastRecord ].sDescOfFunction = deSpace; mcaGOD[ iLastRecord ].sFunctionStatus = "n/a"; mcaGOD[ iLastRecord ].sParameterInputed = sParam_Function_SIG; mcaGOD[ iLastRecord ].sDefineUsed = deSpace; mcaGOD[ iLastRecord ].sWhatisReturned = deSpace; mcaGOD[ iLastRecord ].sAddress = deSpace; mcaGOD[ iLastRecord ].sDebuggerURL1 = deSpace; mcaGOD[ iLastRecord ].sDebuggerURL2 = deSpace; mcaGOD[ iLastRecord ].sNetInfo = deSpace; mcaGOD[ iLastRecord ].iFunNum = iLastRecord; mcaGOD[ iLastRecord ].sEAName = msEAName; mcaGOD[ iLastRecord ].sEASymbol = msEASymbol; mcaGOD[ iLastRecord ].iEATimeFrame = miEATimeFrame; mcaGOD[ iLastRecord ].iEATypeOfTrade = miEATypeOfTrade; mcaGOD[ iLastRecord ].sCurrentBuild = (string)__MQL4BUILD__ ; } //+----- End not found for( z = 1; z<=miGODMaxRecords-1; z++) { if( mcaGOD[ z ].sFutName == sParamFunction && sParamFunction!= "" ) { piFunc = mcaGOD[ z ].iFunNum; mcaGOD[ z ].sEAName = msEAName; mcaGOD[ z ].sEASymbol = msEASymbol; mcaGOD[ z ].iEATimeFrame = miEATimeFrame; mcaGOD[ z ].iEATypeOfTrade = miEATypeOfTrade; mcaGOD[ z ].sFutName = sParamFunction; mcaGOD[ z ].dtGodTimeInt = dtGetTimeCurrent(); } }//+----- End for( z = 0; z<=iMaxRecords-1; z++)) //+-------------------------------------------------------------------+ //| Deinitialization of Function | //+-------------------------------------------------------------------+ iReturnThis = iLastRecord ; piFunc = iReturnThis; if( iFileHandle >0) { FileClose(iFileHandle); iFileHandle =0 ;} return(iReturnThis); }
Inserted Code
//+-------------------------------------------------------------------+ //| | //| Function Name: bLoadGodFuncNum.. | //| Purpose: GOD Global Operation debugger | //|| Function number | //+-------------------------------------------------------------------+ bool CBNForexFunctions::bLoadGodFuncNum() { //+-------------------------------------------------------------------+ //| Initialization of Function | //+-------------------------------------------------------------------+ //+-------------------------------------------------------------------+ //| Local Variables Initialization | //+-------------------------------------------------------------------+ //+---- Standard variables Names ----+// bool bReturnThis = True; bool bFileSeekResults = false; int iMaxRecords = 0; int z = 0; int y = 0; int iFileHandle = 0; string sFileIn = ""; string sPath = ""; string sFileName = ""; //+-------------------------------------------------------------------+ //| Loads array | //+-------------------------------------------------------------------+ //+-1- Function Name +-6- Parameter inputed +-11- sDebuggerURL2 //+-2- Type Function +-7- Defines Used +-12- sNetInfo //+-3- Location +-8- What is Returned +-13- Build Number //+-4- Description +-9 - Vaddress +-14- Number //+-5- Function Status +-10- sDebuggerURL1 //+-------------------------------------------------------------------+ sPath = "FATTools\\Developer Information\\Library\\"; sFileName = sPath + "Function library.csv"; iFileHandle = FileOpen(sFileName,FILE_READ|FILE_CSV,","); if( iFileHandle>0 ) { bFileSeekResults = FileSeek(iFileHandle,0,SEEK_SET); while(!FileIsEnding(iFileHandle)) { sFileIn = FileReadString(iFileHandle,0); if( sFileIn != "") { z++; if( z == 1 ) mcaGOD[ y ].sFutName = sFileIn; if( z == 2 ) mcaGOD[ y ].sFutType = sFileIn; if( z == 3 ) mcaGOD[ y ].sFutPath = sFileIn; if( z == 4 ) mcaGOD[ y ].sDescOfFunction = sFileIn; if( z == 5 ) mcaGOD[ y ].sFunctionStatus = sFileIn; if( z == 6 ) mcaGOD[ y ].sParameterInputed = sFileIn; if( z == 7 ) mcaGOD[ y ].sDefineUsed = sFileIn; if( z == 8 ) mcaGOD[ y ].sWhatisReturned = sFileIn; if( z == 9 ) mcaGOD[ y ].sAddress = sFileIn; if( z == 10) mcaGOD[ y ].sDebuggerURL1 = sFileIn; if( z == 11) mcaGOD[ y ].sDebuggerURL2 = sFileIn; if( z == 12) mcaGOD[ y ].sNetInfo = sFileIn; if( z == 13) mcaGOD[ y ].sBuildNumberDrive = sFileIn; if( z == 14) mcaGOD[ y ].iFunNum = (int)sFileIn; mcaGOD[ y ].sEAName = msEAName; mcaGOD[ y ].sEASymbol = msEASymbol; mcaGOD[ y ].iEATimeFrame = miEATimeFrame; mcaGOD[ y ].iEATypeOfTrade = miEATypeOfTrade; mcaGOD[ y ].sCurrentBuild = (string)__MQL4BUILD__ ; mcaGOD[ y ].sStalllKillWait = (string)menTradingStatus; if( z == 14) { z = 0; y++; } } } //<---- FileIsEnding(iFileHandle) ----> } //+---- read the string into sSplitResults array //+-------------------------------------------------------------------+ //| Deinitialization of Function | //+-------------------------------------------------------------------+ if(iFileHandle<0) bReturnThis = False; if(iFileHandle>0) { FileClose(iFileHandle); iFileHandle = 0; } return(bReturnThis); }
Attached File(s)
- | Joined Nov 2012 | Status: Member | 65 Posts
Errors.MQH is all the errors in common english and a list of the user defined errors
erDefines is broken into sections for Types of Errors not caught by metatrader.
Validate.MQH is the all of the user defined error traps. It calls mcaUI[ miEANumber ] . that array has all the user inputs in it
Global Operation'a Initialization Checks if it is loaded . vGOperationIn(__FUNCTION__,__PATH__,sGod); checks for errors and debugging. It Ranks the errors and changes the state of the EA from trading, To
Waitting which means no new trades no Money management.
Stall no new trades. But money MGT works.
Disable which means shut down EA. Nothing is working
Below is the enum for the State of the EA
The "level of Error " trips a a Gvar is set for the state of Each EA. I have Left cout code that uses Sql to reference the Error.
The main Idea of this whole thread is That one array Tracks the state of the function What version it was a complied to. The Sql stuff also Sets on Int the vars below. One Error I did not think I had to trap BUT IS A MUST.. is if terminal is running out of memory this happens mostly on VPS and if that happens all bets are off as to what Metatrader 4 will do. I have seen older versions go into a Wonky state skipping around in the code. Meaning the array that tracks what is happening to a function may have a value in one function and not another
erDefines is broken into sections for Types of Errors not caught by metatrader.
Validate.MQH is the all of the user defined error traps. It calls mcaUI[ miEANumber ] . that array has all the user inputs in it
Global Operation'a Initialization Checks if it is loaded . vGOperationIn(__FUNCTION__,__PATH__,sGod); checks for errors and debugging. It Ranks the errors and changes the state of the EA from trading, To
Waitting which means no new trades no Money management.
Stall no new trades. But money MGT works.
Disable which means shut down EA. Nothing is working
Below is the enum for the State of the EA
Inserted Code
enum ENUM_CONTROL_SIGNAL { ENUM_SIGNAL_UNKNOWN = -1, ENUM_SIGNAL_INT, ENUM_SIGNAL_DISABLE, ENUM_SIGNAL_STALL, ENUM_SIGNAL_TRADE, ENUM_SIGNAL_WAIT };
The main Idea of this whole thread is That one array Tracks the state of the function What version it was a complied to. The Sql stuff also Sets on Int the vars below. One Error I did not think I had to trap BUT IS A MUST.. is if terminal is running out of memory this happens mostly on VPS and if that happens all bets are off as to what Metatrader 4 will do. I have seen older versions go into a Wonky state skipping around in the code. Meaning the array that tracks what is happening to a function may have a value in one function and not another
Inserted Code
int iAccountNumber; string sTerminal_Build;; string sTerminal_CPU_Cores; string sTerminal_disk_space;; string sTerminal_maxbars;; string sTerminal_memory_available;; string sTerminal_memory_physical;; string sTerminal_memory_total;; string sTerminal_memory_used; string sTerminal_path;
Inserted Code
//+-------------------------------------------------------------------+ //| Gobal Operation'a Initialization | //+-------------------------------------------------------------------+ //+----- Gobal Operation Flow Tracking vGOperationIntArray(__FUNCTION__,__PATH__,__FUNCSIG__); int iFunc = piFunc; string sGod[]; //+----- Stack Control of Errors Initialization vGOperationIn(__FUNCTION__,__PATH__,sGod); //+-------------------------------------------------------------------+ //| Gobal Operation'a Deinitialization | | //+-------------------------------------------------------------------+ //+----- Gobal Operation Deinitialization vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); if(ArraySize(sGod)>0) ArrayFree(sGod); //+----- End God
Attached File(s)
- | Joined Nov 2012 | Status: Member | 65 Posts
This is a List of functions with in the error Includes
Inserted Code
//+---------------------------------------------------------------------------+ //| * Errors. | //| Include\\FATTools Type Cast\\BNForex Includes\\Errors.mqh | //+---------------------------------------------------------------------------+ void vErrorHub(int iParamError, int iParamFunc); bool bSetErrorClearError( int iParamError, int iParamFunc , string sParamFunction, string sParamPath , int iParamLine = 0 ); void vSetStallKillWait( int iParamError , int iParamFunc ); string sErrorDefines2String(int iParamDefines, int iParamUseTwo = 1); int iSetProgramType( ); void vDevDefinedStallKillWait( int iParamErrorCode ); string sDevDefinedErrorDescription(int iParamErrorCode, int iParamFunc); void vSetMetatraderStallKillWait(int iParamErrorCode, int iParamFunc); string sMetatraderErrorDescription(int iParamErrorCode, int iParamFunc); int iError_TrapTrade( int iParamErrorCode ); int iError_TrapVars( int iParamErrorCode ); bool bIsTemporaryError( int iParamErrorCode ); bool bMGTWaitOnError( int iParamError, ENUM_TRADEOPERATION enParamTradeOperation) ; void vReoloadShowAlert(); bool bError4066( ); bool bError4073(); void vErrorLog();
- | Joined Nov 2012 | Status: Member | 65 Posts
If a function is referenced and I did not post it Ask about it. I kept the sql stuff out because it has my IPs and servers embedded in the Code . I can remove it and post. Also . I could not Post the code from Ekion. I am a Long long term user of Metastock Pro. and Use some code from reuters for news and Watching the spread. Before I post that code I need to have a Talk with the people at Metstock. That is a super important to trap. Many many years ago two of us got IBFX to eat a large sum of money for a error on there side by carefully tracking this stuff. (IBFX is now out of business. FXCM bought them ) I am sure some of you have done the same. Most desks make U sign a nondisclosure if that happens. They are out of business so I feel ok posting that statement . I have one more file that is older called checkRules. Will try to find it and post it. The Scan section is for Profiling. Setuser error is a easy way to track where it stopped in the code.
Inserted Code
//+---------------------------------------------------------------------------+ //| * Validate. | //| Include\\FATTools Type Cast\\BNForex Includes\\Validate | //| Validate Type: User | //+---------------------------------------------------------------------------+ //+---- User - User error //+---- Dev - Programer //+---- Desk - Desk errors //+---- mMt4 - metatrader //+---- Scan - scanning not critical no fail bool bUseMaximumDrawDownOpen ( ); bool bUseMaximumDrawDownClosed( ); bool bUserAlreadyRunningEA(); bool bUserTrendCheck( ); bool bUserDllsAllowed(); bool bUserTradeAllowed(); bool bUserLotRiskInput(); bool bUserUserValidateEmail(); bool bUserInputFile(int iParamFileHandle); bool bUserRegister(); bool bUserCheckTradingEA(); bool bUserOrderZeroVal( string sParamSymbol,int iParamCMD, double dPramLots, double dParamEntryPrice, int iParamSlippage, double dParamDistanceToStop_Pip, double dParamDistanceToTarget_Pip, string sParamComment = NULL, int iParamMagicNumber = 0, datetime dtParamExpiration = 0, color cParamColor = clrNONE); //+---------------------------------------------------------------------------+ //| Validate Type Metatrader .. | //+---------------------------------------------------------------------------+ //+---- User - User error //+---- Dev - Programer //+---- Desk - Desk errors //+---- mMt4 - metatrader //+---- Scan - scanning not critical no fail void vMT4Validate_VersionNumber ( ); bool bMT4CheckOutOfSync(); bool bMT4StopCheckMT( ); bool bMT4TargetCheckMT() ; bool bMT4CheckQuoteTime(); //+---- User - User error //+---- Dev - Programer //+---- Desk - Desk errors //+---- mMt4 - metatrader //+---- Scan - scanning not critical no fail bool bDevValidateSQl(); bool bDevLoadGod(); bool bDevConnected(); bool bDeAuthenticationResult(); bool bDevFileGmt( int iParamFileHandle); bool bDevValidate_Stall ( ); bool bDevValidate_StopTooTight ( ); void vDevCheckLocked(string sParamOperation ); bool bDevValidate_FailedFiveTimes(); bool bDevValidate_DisabledEA ( ); void vDevSetErrorWeb(); bool bDevValidateLocalInt(); bool bDevCheckTradingEA(); bool bDevOverUnder(double dParmaEntry, int iPramCmd); //+---- User - User error //+---- Dev - Programer //+---- Desk - Desk errors //+---- mMt4 - metatrader //+---- Scan - scanning not critical no fail bool bDeskValidate_PreMargin( ); bool bDeskValidate_SymbolOn(); bool bDeskMaxLots(double dPramLots ); bool bDeskMinLots(double dPramLots ); bool bDeskTradeAllowedBusy( ); bool bDeskFifoError(bool bParamSendOk ); bool bDeksPassFreeMarginCheck () ; //+---- Wait for error to clear //+---- User - User error //+---- Dev - Programer //+---- Desk - Desk errors //+---- mMt4 - metatrader //+---- Scan - scanning not critical no fail bool bScanValidate_HVBox(); bool bScanValidate_TimeBetweenTrade ( ); bool bScanScanValidate_TimeOfDayHV ( ); bool bScanValidate_TimeToTrade ( int iParamDateTime ); bool bScanValidate_TimeBetweenError ( ); bool bScanValidateLiarsWairs(); bool bScanValidate_MaximumOpenTrade ( ); bool bScanValidate_MaximumLotPerTrade ( ); bool bScanValidate_TotalLotSize ( ); bool bScanValidate_TooWideSpreadSLTP ( ); bool bScanValidate_Volatility ( ); bool bScanValidate_Spread( double dParamMaxSpread = 10.0 ); // in pips bool bScanCheckNewBar(); bool bScanDayofWeekCheckUI(); bool bScanLiarsWiars( int iParamLiars, int iParamWiars); //+----- Not reporting a error bool bPassOrderValidationHub () ; bool bMGTIsTradeAllowed ( int iParamMaxWaiting_Sec ) ; bool bValidateDuplicateSymbols(); void vValidatePair ( string &ParamSymbolList[], ENUM_SYMBOL &sParamSymbol, ENUM_SYMBOL &ParamCounterSymbol, ENUM_SYMBOL &ParamTriSymbol ); //+----- Not reporting a error double dTooCloseToCall ( ) ;
- | Joined Nov 2012 | Status: Member | 65 Posts
Sorry to spam I forgot something. All My Orders information, Errors, user communications debugging is done in a central location. The error trap at every function Makes the Code run slow. I have Not posted the debugging that is tripped at a level one two or three errors. Also For Developers that Make stuff for the Public. ( I did Once for metatrader but never again. I still do some times for metastock ) Anyway Developers around 2009 I called the NFA, Utah's regulatory Body ( shaking my damn head . AUGH! they just wanted my name ect ) and CFTC about. Direct investment advice and EAs. I Spoke on and off to the kansas city Division of the CTFC ( brand new kid No one knew what a ea was back then ). They told me the Had no court cases of a a EA being treated as direct investment advice but the EA should be given to a customer with the configuration of the Ea set to Null. Much the same way as a OCO order at a major brokerage house. Point being I make friends that use EAS up load how they configured the EA into a data base on Int or a change to a user input. I have no desire to be the Cuy ( peruvian for Guinea pig) for the CFTC. Out side us do what U want inside Us it can be risky making people eas. My Point is Use this on your own accord. So Enough Posts for today. Sorry about it being piecemeal . It is hard to to all this out it would be easier with multi inheritance . With that said a lot of things I am doing are now being pulled out of metrader. I feel the code base is doing things now that it should not. Also If this type of stuff is done out side metatrader it can be multi threaded. Oh Hell I forgot to post the Race condition.stuff . Those are very hard errors to find. I can post that in a min ANY THING that calls a DLL in metatrader 4 should be locked for multex
Inserted Code
//+ ----------------------------------------------------------------------------------------- + //+ GOALS: + //+ 1. Ensure it keeps locking if there is trade operation in other thread + //+ 2. Ensure it keeps locking if there is dll correlation calculation busy in other thread + //+ 3. Ensure it keeps locking if there is dll Pivot Calulation busy in other thread + //+ 4. Ensure it keeps locking if there is dll Pattern Calulation busy in other thread + //+ + //+ 4 TRADE OPERATION REQUIRED LOCKING: + //+ 1. OrderSend, + //+ 2. OrderModify, + //+ 3. OrderClose, and + //+ 4. OrderModify + //+ Return + //+ True: Successfully lock trade to resume the operation + //+ False: Failed to lock trade and wait time expires + //+ ----------------------------------------------------------------------------------------- + bool CBNForexFunctions::bMGTLockOperation(string sParamOperation, int iParamMaxWaiting_Sec = 30) { //+-------------------------------------------------------------------+ //| Local Variables Initialization | //+-------------------------------------------------------------------+ bool bReturnThis = True; int StartWaitingTime = (int)GetTickCount(); //+-------------------------------------------------------------------+ //| Main body | //+-------------------------------------------------------------------+ //+ ------------------------------------------------------------------- + //+ Make sure the global variable TradeLocked has been once created + //+ ------------------------------------------------------------------- + while( bIsReadyToInit() ) { //+----- Waiting time has expired if ( ((int)GetTickCount() - StartWaitingTime) > (iParamMaxWaiting_Sec * 1000) ) { bReturnThis = False; return(bReturnThis);} //+----- Global variable TradeLocked doesn't exisit if ( !GlobalVariableCheck(sParamOperation) ) { //+----- Successfully created global variable TradeLock = 1 to lock if ( GlobalVariableSet(sParamOperation, 0) > 0 ) { break; } else Sleep(5); } //+----- Global variable TradeLocked exisit else break; } //+ ------------------------------------------------------------------- + //+ Queueing for its turn to occupy to proceed trade operation + //+ TradeLocked = 0: It's free + //+ TradeLocked = 1: It's being used by other process + //+ ------------------------------------------------------------------- + while( bIsReadyToInit() ) { //+----- Waiting time has expired if ( ((int)GetTickCount() - StartWaitingTime) > (iParamMaxWaiting_Sec * 1000) )break; //+ Sets the new value of the existing global variable "Locked" //+ if the current value = 0. If there is no global variable //+ the function will generate an error if ( GlobalVariableSetOnCondition(sParamOperation, 1, 0) ) { //+----- Mark TradeLock performed by EA. This allows us to do proper clean up if EA is removed while global TradeLocked is set to 1 //+----- This allow proper release of global TradeLocked so other EA can place trade if ( sParamOperation == DEF_TRADE_LOCKED ) mbTradeLocked = True; if ( sParamOperation == DEF_PATTERN_LOCKED ) mbPatternLocked = True; if ( sParamOperation == DEF_PIVOT_LOCKED ) mbPivotLocked = True; if ( sParamOperation == DEF_CORRELATION_LOCKED ) mbCorrelationLocked = True; if ( sParamOperation == DEF_SQL_LOCKED ) mbSQLLocked = True; break; } Sleep(5); } if ( sParamOperation != DEF_TRADE_LOCKED ) bReturnThis = True; return(bReturnThis);; if ( sParamOperation == DEF_TRADE_LOCKED ) { if ( bMGTIsTradeAllowed ( iParamMaxWaiting_Sec ) ) { bReturnThis = True; }else bReturnThis = False; } //+-------------------------------------------------------------------+ //| Deinitialization of Function | //+-------------------------------------------------------------------+ return(bReturnThis); } //+ ----------------------------------------------------------------------------------------- + //+ GOALS: + //+ 1. Ensure it unlock after trade operation completes + //+ 2. Ensure it unlock after dll correlation calculation completes + //+ 3. Ensure it unlock after dll Pivot Calulation calculation completes + //+ 4. Ensure it unlock after dll Pattern Calulation calculation completes + //+ + //+ 4 TRADE OPERATION REQUIRED UNLOCK: + //+ 1. OrderSend, + //+ 2. OrderModify, + //+ 3. OrderClose, and + //+ 4. OrderModify + //+ + //+ Void function + //+ ----------------------------------------------------------------------------------------- + void CBNForexFunctions::vMGTUnLockOperation(string sParamOperation, int iParamMaxWaiting_Sec = 30) { //+-------------------------------------------------------------------+ //| Gobal Operation'a Initialization | //+-------------------------------------------------------------------+ //+----- Gobal Operation Flow Tracking vGOperationIntArray(__FUNCTION__,__PATH__,__FUNCSIG__); int iFunc = piFunc; string sGod[]; //+----- Stack Control of Errors Initialization vGOperationIn(__FUNCTION__,__PATH__,sGod); //+-------------------------------------------------------------------+ //| Local Variables Initialization | //+-------------------------------------------------------------------+ bool bSkipCode = False; int iStartWaitingTime = (int)GetTickCount(); //+-------------------------------------------------------------------+ //| Main body | //+-------------------------------------------------------------------+ iStartWaitingTime = (int)GetTickCount(); while( bIsReadyToInit() ) { //+----- Waiting time has expired if (( (int)GetTickCount() - iStartWaitingTime) > (iParamMaxWaiting_Sec * 1000)) {vDevCheckLocked(sParamOperation);vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); break;} //+ Unlocking current correlation operation so other thread can take turn if ( GlobalVariableSetOnCondition(sParamOperation, 0, 1) ) { //+----- Clear Mark performed by EA. This allows us to do proper clean up if EA is removed while global TradeLocked is set to 1 //+----- This allow proper release of global TradeLocked so other EA can place trade if ( sParamOperation == DEF_TRADE_LOCKED ) mbTradeLocked = False; if ( sParamOperation == DEF_PATTERN_LOCKED ) mbPatternLocked = False; if ( sParamOperation == DEF_PIVOT_LOCKED ) mbPivotLocked = False; if ( sParamOperation == DEF_CORRELATION_LOCKED ) mbCorrelationLocked = False; if ( sParamOperation == DEF_SQL_LOCKED ) mbSQLLocked = False; break; }//+----- End ( GlobalVariableSetOnCondition(sParamOperation, 0, 1) ) Sleep(5); }//+----- End while //+-------------------------------------------------------------------+ //| Gobal Operation'a Deinitialization | | //+-------------------------------------------------------------------+ //+----- Gobal Operation Deinitialization vGOperationOut(iFunc,__FUNCTION__, __PATH__,sGod); if(ArraySize(sGod)>0) ArrayFree(sGod); } //+-----
- | Joined Nov 2012 | Status: Member | 65 Posts
ERROR TRAPS I DID NOT POST: All of these involve cross referencing what we are shown on a chart and it cannot be done from with in metatrader it MUST be some other place.
bDeskOutofSyncNow() I have not also included the bad Data Checks. in Real Time it involves Ekion and Metatrader. I did included a data check for iClose to Markertinfo(Symbol(),MODE_BID) being out of sync with the chart data. This is not so bad but it used to be.
bOutofSyncCharts() Historical data is spot checked and compared to metrader data. are we getting bad highs and lows on the graph is used to be really bad until they started posting aggregation of chart data and stopped using the charts form the deal desk itself. That causes u 2 get out of sync. CHART DATA IS DIFFERENT than Marketinfo(symbol(),Mode_bid). Like I said not so bad now days
bLabelOutliarCHF() This it involves BaseLine volatility Versus a outlier . Since all tradeable data has a long tail or is skewed when displayed in a standard deviation / Bell Curve. It involves how that data is Labeled a Outlier and What we do when we have a Outlier. I set alarms based on The Top of data cluster and the bottom of data Cluster. Then I check for normal news events. I will Ask if I can post a link to database that Deals with news events . it is every news event from 2005 - 2016. It came from scrapping yahoo finance Which used reuters until the buy out by Verizon then they cut back the data offering. I get it from Ekion directly now . .The Function above. works like this if Not news and outlier . Should I close or Hedge. Itis meant to prevent a Leheman event or chf event. SCARY
bNewsEventSpread() .I use that data to help me mine the normal spread for each news event. dukascopy has tick or pip data it can be compared to. So this data check was removed. This came from a spread of 90 pips I saw on devisia capitol years ago.
bDeskOutofSyncNow() I have not also included the bad Data Checks. in Real Time it involves Ekion and Metatrader. I did included a data check for iClose to Markertinfo(Symbol(),MODE_BID) being out of sync with the chart data. This is not so bad but it used to be.
bOutofSyncCharts() Historical data is spot checked and compared to metrader data. are we getting bad highs and lows on the graph is used to be really bad until they started posting aggregation of chart data and stopped using the charts form the deal desk itself. That causes u 2 get out of sync. CHART DATA IS DIFFERENT than Marketinfo(symbol(),Mode_bid). Like I said not so bad now days
bLabelOutliarCHF() This it involves BaseLine volatility Versus a outlier . Since all tradeable data has a long tail or is skewed when displayed in a standard deviation / Bell Curve. It involves how that data is Labeled a Outlier and What we do when we have a Outlier. I set alarms based on The Top of data cluster and the bottom of data Cluster. Then I check for normal news events. I will Ask if I can post a link to database that Deals with news events . it is every news event from 2005 - 2016. It came from scrapping yahoo finance Which used reuters until the buy out by Verizon then they cut back the data offering. I get it from Ekion directly now . .The Function above. works like this if Not news and outlier . Should I close or Hedge. Itis meant to prevent a Leheman event or chf event. SCARY
bNewsEventSpread() .I use that data to help me mine the normal spread for each news event. dukascopy has tick or pip data it can be compared to. So this data check was removed. This came from a spread of 90 pips I saw on devisia capitol years ago.
- | Joined Nov 2012 | Status: Member | 65 Posts
Ok This is a Link to my personal google Drive
https://drive.google.com/open?id=1Ua...>&usp=drive_fs
It is called the super news data base. It is all events back to 2016. they are good. there are some 2018 and 2017 events but they Got flaky after verizon bought yahoo. if U are using metastock pro. U can go into eikon hit EM stands for economic monitor. then export to excel. . They changed the format from EE to EM in april of this year. I stream this data directly to Metatrader But I can not redistribute it. They is why I had to call. Now some of the issues with the data. the Unit changes. Meaning jobs lost or percent of jobs loss. Make sure all the data is the same unit. GRRR reuters should do better. Also NEVER use the name of the event it has changed tons of times over the years. Use the R.I.C. Which is short for reuters instrument code. they work like this. USADP=ECI !st two Characters are the country code. Next is the name of event and =ECI is type of event. pUSADP= { bank code } is the poll number of that bank. pUSADP=E is the smart estimate of the poll number EM page gives predicted surprise. Now in the database I posted it is meant to give you ideas on how you can get information about a normal spread as a side benefit. I put a quick example of a trading idea. For example Actual - Poll Number = surprise number
if you take a standard deviation of the surprise number then do something like ( top of Standard deviation- suprise number or actual ) / ( top of Standard deviation - Bottom of Standard deviation) = get a ranking of the news events strength .50 is normal will not move. 1. > will move for multi days <0 will move multi days. Do not look back before 2010 U will get data for financial crisis and it will skew your data . I am posting it so you can mine and set a Error trap for spread 2 wide. During news events. In my opinion most eas will not work unless u address news head on. Oh the data is in EST time. . I have attached also all the commands for Ekhon to get which bank is on the bid and the fixing rates. that data I use for intra bank spread to check how far my desk is off the Bid and ask . the fixing rates I used to use until they changed the rules on how they are posted after deutsche bank was fined . they are just in the file. 2 lazy to remove them. I am playing with how fast the banks cross each other for an alarm of a MAJOR news event like CHF down turn. I also attached a sample of the new format . U may be able to find this online on a calendar some place. Yahoo had one. 1st 2016 file is EM or new format that ekion uses. I should state this I consider a error trap a preventive measure to some thing I did not know was going to happen. It may not be a classical error at all
https://drive.google.com/open?id=1Ua...>&usp=drive_fs
It is called the super news data base. It is all events back to 2016. they are good. there are some 2018 and 2017 events but they Got flaky after verizon bought yahoo. if U are using metastock pro. U can go into eikon hit EM stands for economic monitor. then export to excel. . They changed the format from EE to EM in april of this year. I stream this data directly to Metatrader But I can not redistribute it. They is why I had to call. Now some of the issues with the data. the Unit changes. Meaning jobs lost or percent of jobs loss. Make sure all the data is the same unit. GRRR reuters should do better. Also NEVER use the name of the event it has changed tons of times over the years. Use the R.I.C. Which is short for reuters instrument code. they work like this. USADP=ECI !st two Characters are the country code. Next is the name of event and =ECI is type of event. pUSADP= { bank code } is the poll number of that bank. pUSADP=E is the smart estimate of the poll number EM page gives predicted surprise. Now in the database I posted it is meant to give you ideas on how you can get information about a normal spread as a side benefit. I put a quick example of a trading idea. For example Actual - Poll Number = surprise number
if you take a standard deviation of the surprise number then do something like ( top of Standard deviation- suprise number or actual ) / ( top of Standard deviation - Bottom of Standard deviation) = get a ranking of the news events strength .50 is normal will not move. 1. > will move for multi days <0 will move multi days. Do not look back before 2010 U will get data for financial crisis and it will skew your data . I am posting it so you can mine and set a Error trap for spread 2 wide. During news events. In my opinion most eas will not work unless u address news head on. Oh the data is in EST time. . I have attached also all the commands for Ekhon to get which bank is on the bid and the fixing rates. that data I use for intra bank spread to check how far my desk is off the Bid and ask . the fixing rates I used to use until they changed the rules on how they are posted after deutsche bank was fined . they are just in the file. 2 lazy to remove them. I am playing with how fast the banks cross each other for an alarm of a MAJOR news event like CHF down turn. I also attached a sample of the new format . U may be able to find this online on a calendar some place. Yahoo had one. 1st 2016 file is EM or new format that ekion uses. I should state this I consider a error trap a preventive measure to some thing I did not know was going to happen. It may not be a classical error at all
Attached File(s)