- could someone help me out please on the code below... it has failed to work on the charts though it compiles with no errors at all.
- mt5 initialization of expert failed with code 0
- Validation state: Validation completed with errors
Your posted code is irrelevant. OnInit is your initialization code, and it is returning non-zero.
Your posted code is irrelevant. OnInit is your initialization code, and it is returning non-zero.
void OnInit() { if(!MQLInfoInteger(MQL_TESTER) || !MQLInfoInteger(MQL_OPTIMIZATION)) { if(NEWS_FILTER==true && READ_NEWS(NEWS_TABLE) && ArraySize(NEWS_TABLE)>0) DRAW_NEWS(NEWS_TABLE); //TIME_CORRECTION=((int(TimeCurrent() - TimeGMT()) + 1800) / 3600); TIME_CORRECTION=(-TimeGMTOffset()); } double min_lot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN); double lot_step = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP); Print("Minimum lot: ", DoubleToString(min_lot, 2), ", lot step: ", DoubleToString(lot_step, 2), "."); if ((Lots < min_lot) && (!MM)) Alert("Lots should be not less than: ", DoubleToString(min_lot, 2), "."); else CanTrade = true; if (ShowTimer) { ObjectCreate(ChartID(), "NewsTraderTimer", OBJ_LABEL, 0, 0, 0); ObjectSetInteger(ChartID(), "NewsTraderTimer", OBJPROP_CORNER, Corner); ObjectSetInteger(ChartID(), "NewsTraderTimer", OBJPROP_XDISTANCE, X_Distance); ObjectSetInteger(ChartID(), "NewsTraderTimer", OBJPROP_YDISTANCE, Y_Distance); ObjectSetInteger(ChartID(), "NewsTraderTimer", OBJPROP_SELECTABLE, true); EventSetMillisecondTimer(100); // For smooth updates. } else EventSetTimer(1); // If UseATR = false, these values will be used. Otherwise, ATR values will be calculated later. SL = StopLoss*10; TP = TakeProfit*10; Trade = new CTrade; Trade.SetDeviationInPoints(Slippage); Trade.SetExpertMagicNumber(Magic); }nit. Here is my OnInit code.
Nope, don't know how Sir.
https://www.metatrader5.com/en/metaeditor/help/development/debug // Code debugging
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5
https://www.mql5.com/en/articles/272 // Tracing, Debugging and Structural Analysis of Source Code
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"

- www.metatrader5.com
Nope, don't know how Sir.
It's pretty easy. Set stop points so that your code stops there when executing, then you can go line by line, step over a function call, step out of it, etc. It's slow, of course, but really useful when you're stuck or wanna see if your code is doing what you're expecting. As a faster method and something more general, I suggest you put "Print" everywhere with a text that's telling you something, so that you see at a first glance if your code is entering an "if" or "for" or going here or there... that's definitely faster, but the debugger is something you're probably gonna need at some point. Take a look at the article posted in the previous reply - debugging is an essential part of developping. Good luck!
ThankGod99 #: I posted this because it seems to be the source of the error, I also see array out of range error in the experts tab, this part of the code is not even called in OnI nit. Here is my OnInit code.
You said it's "fails to initialize" but posts initialize code that doesn't fail (void OnInit). Your initial statement is wrong.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
Code debugging - Developing programs - MetaEditor Help
Error Handling and Logging in MQL5 - MQL5 Articles (2015)
Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use