I created an EA of Long/Short, that consists in buy and sell from two different symbols that have a good correlation. So, I use an indicator with the ratio, average and bollinger bands. The EA works fine, but the indicator sometimes need to be refreshed to show the correct values. Using the function "GetLastError" I noticed that the problem is the idification of the symbol 2. I thied to use the "CheckLoadHistory" but it also didn't worked. I read and tried a lot of thing to fix it, but I didn't get a good result until now.
Without full code, nobody knows how you declared/initialized your variables and buffers, and nobody can test run, even if they want to.
//-- PREÇOS DE FECHAMENTO Close1_Buffer[i] = iClose(symbo1, Tempo_Grafico, i); Close2_Buffer[i] = iClose(symbo2, Tempo_Grafico, i);
- You are mixing apples and oranges.
- On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073
errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.
On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum -
Comment(symbo1,"/", symbo1);
Without full code, nobody knows how you declared/initialized your variables and buffers, and nobody can test run, even if they want to.
Thank you Seng Joo. I attached my indicator, so you can check! Sorry for that!!
- You are mixing apples and oranges.
- On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073
errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.
On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
Thank you William for your reply!
1. I didn't get that you mean. I need that the information of iClose goes to an array, isn't it the best way to do that?
2. I read those articles before and this one (https://www.mql5.com/en/code/1251) was the only way to correct the problem, but I would like to understand what's happening, and not just copy and paste..
3. That was a litttle mistake when I was transfering the code to post here. Sorry!
Thank you again for your reply, it helped a lot, for sure. I'm gonna read again the articles and keep trying a way to solve the problem. I attached my indicator here, so if you have time to check it and maybe show me a way, i would really appreciate that!!
![CheckHistory - Check and load history function CheckHistory - Check and load history function](https://c.mql5.com/36/28/checkhistory-check-and-load-history.jpg)
- www.mql5.com
Thank you Seng Joo. I attached my indicator, so you can check! Sorry for that!!
Hmm... this file does not match the section of code you posted earlier (which looked better than this file, in fact)... but I ran it anyway, and set symbol1 to GBPUSD and symbol2 to EURUSD, and timeframe to M1 so I can see results quickly... and this is what I get:
Red vertical line denotes the time i started running... and looks like all new bars are updated without requiring refresh... am I missing something? What symbols/timeframes did you test on? Also, if you can, how about some screenshots to show what you meant by incorrect values?
Thank you Seng Joo. I attached my indicator, so you can check! Sorry for that!!
Anyway, try this version - I've removed/simplified some parts that seemed redundant/excessive... see if it runs fine (you can find my changes by searching for 'SJT').
Anyway, try this version - I've removed/simplified some parts that seemed redundant/excessive... see if it runs fine (you can find my changes by searching for 'SJT').
Thank you Seng Joo! I totally agree you you that this code iswith excessive/redundant loops, thats why I "cleaned" it before post here, hahah. I tried to use these loops to get the right data from the symbols, but I noticed that that was not the problem. The problem was to load the values from Symbol 2. I'll try your version and give you a feedback.
I use it for symbols from the Brazilian Market, with timeframe 1D.
Hmm... this file does not match the section of code you posted earlier (which looked better than this file, in fact)... but I ran it anyway, and set symbol1 to GBPUSD and symbol2 to EURUSD, and timeframe to M1 so I can see results quickly... and this is what I get:
Red vertical line denotes the time i started running... and looks like all new bars are updated without requiring refresh... am I missing something? What symbols/timeframes did you test on? Also, if you can, how about some screenshots to show what you meant by incorrect values?
I tried your code and it still didn't work. I did what you said and printed what i was trying to mean. These are before and after refresh.
I tried your code and it still didn't work. I did what you said and printed what i was trying to mean. These are before and after refresh.
From the screenshots, it looks like your MediaMovel_Buffer is assigned huge numbers at times... and you may be right to suspect Symbol 2. So perhaps you could add these lines (highlighted) to your code and see if there's any error being printed when the chart looks crazy:
if (iBars(ativo1,Tempo_Grafico)>i) { ResetLastError(); price1 = iClose(ativo1,Tempo_Grafico,i); if (_LastError!=0) Print ("i=", i, ", price1=", price1, ", price1 error=", _LastError); } if (iBars(ativo2,Tempo_Grafico)>i) { ResetLastError(); price2 = iClose(ativo2,Tempo_Grafico,i); if (_LastError!=0) Print ("i=", i, ", price2=", price2, ", price2 error=", _LastError); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good evening,
I created an EA of Long/Short, that consists in buy and sell from two different symbols that have a good correlation. So, I use an indicator with the ratio, average and bollinger bands. The EA works fine, but the indicator sometimes need to be refreshed to show the correct values. Using the function "GetLastError" I noticed that the problem is the idification of the symbol 2. I thied to use the "CheckLoadHistory" but it also didn't worked. I read and tried a lot of thing to fix it, but I didn't get a good result until now.
Thank you in advance for any help!!