Denisx: but sometimes detects there is a gap without there is an actual gap. How can i accurately get the values?
- Where is your comparison code? There are no mind readers here.
- i should be one only, not in a loop, not zero.
- You must make sure other pairs are loaded. Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
- I recommendDo not trade multiple currencies in one EA
- You can't use any predefined variables,
can't use the
tester, must poll (not OnTick,) and usually other problems, e.g A problem with iBarShift - MQL4 and MetaTrader 4 - MQL4
programming forum - Page 2
- Code it to trade the chart pair only. Look at the others if you must. (Don't assume that Time[i] == iTime(otherPair,tf, i) always use iBarShift.)
- Then put it on other charts to trade the other pairs. Done.
- You can't use any predefined variables,
can't use the
tester, must poll (not OnTick,) and usually other problems, e.g A problem with iBarShift - MQL4 and MetaTrader 4 - MQL4
programming forum - Page 2
Carl Schreiber:
You have to use the functions iHighest and iLowest (which return an index!) and then High[] and Low[].
Read the example in the Reference (cursor in the function+F1).Thanks, ill try it!
whroeder1:
- Where is your comparison code? There are no mind readers here.
- i should be one only, not in a loop, not zero.
- You must make sure other pairs are loaded. Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
- I recommend
if(current_low > (previous_high + 0.00002))
Pairs are loaded because im hardcode-ing them in a array.
Checking for every pair is because thats my task. Doing intern and i'm just following orders.
Denisx: Pairs are loaded because im hardcode-ing them in a array. if(current_low > (previous_high + 0.00002)) |
|
whroeder1:
|
Oh thanks, well i don't really understand your code. What i'm supposed to change to get the history for PERIOD_M5 of all pairs so i can loop them and check for gap?
#define HR2400 PERIOD_D1 * 60 // 86400 = 24 * 3600 int TimeOfDay(datetime when=0) { if(when == 0) when = TimeCurrent(); return( when % HR2400 ); } datetime DateOfDay(datetime when=0) { if(when == 0) when = TimeCurrent(); return( when - TimeOfDay(when) ); } #define SYMBOL string #define THIS_SYMBOL "" string Currencies[] = {"AED", "AUD", "BHD", "BRL", "CAD", "CHF", "CNY", "CYP", "CZK", "DKK", "DZD", "EEK", "EGP", "EUR", "GBP", "HKD", "HRK", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JOD", "JPY", "KRW", "KWD", "LBP", "LTL", "LVL", "LYD", "MAD", "MXN", "MYR", "NOK", "NZD", "OMR", "PHP", "PLN", "QAR", "RON", "RUB", "SAR", "SEK", "SGD", "SKK", "SYP", "THB", "TND", "TRY", "TWD", "USD", "VEB", "XAG", "XAU", "YER", "ZAR"}; string Symbols[58]; int SymbolCount; int init() { CreateSymbolList(); return(0); } bool download_history(ENUM_TIMEFRAMES period=PERIOD_M5) { return download_history(_Symbol, period); } bool download_history(SYMBOL symbol=THIS_SYMBOL, ENUM_TIMEFRAMES period=PERIOD_CURRENT) { if(symbol == THIS_SYMBOL) symbol = _Symbol; if(period == PERIOD_CURRENT) period = _Period; datetime today = DateOfDay(); ResetLastError(); datetime other = iTime(symbol, period, 0); if(_LastError == 0 && today == DateOfDay(other)) { return true; } if(_LastError != ERR_HISTORY_WILL_UPDATED && _LastError != ERR_NO_HISTORY_DATA) Print(StringFormat("iTime(%s,%i) Failed: %i", symbol, period,_LastError)); return false; } string CreateSymbolList() { string allsyms; int CurrencyCount = ArrayRange(Currencies, 0); int Loop, SubLoop; string TempSymbol; for(Loop = 0; Loop < CurrencyCount; Loop++) for(SubLoop = 0; SubLoop < CurrencyCount; SubLoop++) { TempSymbol = Currencies[Loop] + Currencies[SubLoop]; if(MarketInfo(TempSymbol, MODE_BID) > 0) { ArrayResize(Symbols, SymbolCount + 1); Symbols[SymbolCount] = TempSymbol; allsyms = allsyms + TempSymbol +"n"; SymbolCount++; } TempSymbol = Currencies[Loop] + Currencies[SubLoop] +"m"; if(MarketInfo(TempSymbol, MODE_BID) > 0) { ArrayResize(Symbols, SymbolCount + 1); Symbols[SymbolCount] = TempSymbol; allsyms = allsyms + TempSymbol +"n"; SymbolCount++; } } return(allsyms); } void OnTick() { while(!download_history(PERIOD_M5) ) { Sleep(1000); RefreshRates(); } int size = ArraySize(Symbols); for(int i = 0; i < size; i++) { int current_bar_index = iHighest(Symbols[i], PERIOD_M5, MODE_HIGH, 1, 0); int previous_bar_index = iHighest(Symbols[i], PERIOD_M5, MODE_HIGH, 2, 1); int current_bar_index_low = iLowest(Symbols[i], PERIOD_M5, MODE_LOW, 1, 0); int previous_bar_index_low = iLowest(Symbols[i], PERIOD_M5, MODE_LOW, 2, 1); double current_high = High[current_bar_index]; double previous_high = High[previous_bar_index]; double current_low = Low[current_bar_index_low]; double previous_low = Low[previous_bar_index_low]; if (current_low > (previous_high + 0.00002) || current_high < (previous_low - 0.00002)) { Print("There is a gap"); //SendMail("Gap!", "There is a gap at: " + Symbols[i]); } } }
Everything i made so far.
- Denisx: i don't really understand your code. What i'm supposed to change to get the history for PERIOD_M5 of all pairs so i can loop them and check for gap?That just makes sure the current pair/M5 minute data is current. If M5 is the period you are running on, that code does nothing.
while(!download_history(PERIOD_M5) ) { Sleep(1000); RefreshRates(); }
int current_bar_index = iHighest(Symbols[i], PERIOD_M5, MODE_HIGH, 1, 0);
You want all symbols downloaded. Move the code inside the loop and call it using Symbols[i].- Your iHighest has a length of one, starting at zero. What do you think that will return? Only zero.
- Make up your mind. Either you want to find the "High/Low of the last 10 bars" as your title says. Or you want to "loop them and check for gap"
- Just get the values and check.
double current_high = High[0]; double previous_high = High[1]; double current_low = Low[0]; double previous_low = Low[1];
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I need to create an EA that checks on every tick if there is a gap on every pair.
Im using for loop to loop 10 times and i'm using
to get the current bar's High value and the previous one by shifting. There is simple if to check if current bar's High is lower than previous bar's Low and vice versa. It works but sometimes detects there is a gap without there is an actual gap. How can i accurately get the values?
I'm using nested for loop. The first one gets the pair and the next one is looping 10 times to get the values and compare them if there is a gap. Symbols is the pairs array.