I am trying to code 'correctly' and efficiently in MT5.
I have an EA that loops through different currency pairs and for each currency looks at an Indicator using the iCustom function.
As I understand I don't need to RELEASE a handle but ....
1. Do I need a separate HANDLE for each currency PAIR? [access via an Array perhaps]
2. If I wish to look at - for example - the MAX & MIN values over 100 and 250 bars can I use the same handle again with a different COPY statement.
Somewhere I have seen that MT5 doesn't doesn't require Release of the HANDLE whereas MT4 would.
Any help appreciated and thanks in advance
1 . yes
2. yes you can , or you can request 250 bars worth of data from the indicator with one call per pair , and iterate through the returned values
3. release all handles on deinit
Many thanks - fast and to the point.
Much appreciated
Lorentzos
Hi Hope you don't mind me returning on this one.
I am trying to utlise CLASSES more often and the above problem seemed to be an ideal opportunity.
I coded a very simple example
#include <Trade/Trade.mqh> #include <Arrays/ArrayLong.mqh> #include <Arrays/ArrayObj.mqh> string arrSymbols[]={ "","AUDCAD" , "AUDJPY" , }; input ENUM_TIMEFRAMES AtrTimeframe = PERIOD_H1; input int AtrPeriods = 14; class CSymbol : public CObject { public: CSymbol (string name) : symbol(name){}; ~CSymbol(){}; string symbol; CArrayLong tickets; int handleAtr; // added later }; CArrayObj symbols; int OnInit() { symbols.Clear(); Print ("ArraySize(arrSymbols) = ",IntegerToString(ArraySize(arrSymbols))); for (int i = ArraySize(arrSymbols)-1; i > 0; i--) { CSymbol* symbol = new CSymbol(arrSymbols[i]); //symbol.handleAtr = iATR(arrSymbols[i],_Period,20); int MyAtr = iATR(arrSymbols[i],AtrTimeframe,AtrPeriods); symbol.handleAtr = MyAtr; symbols.Add(symbol); Print("i = ",IntegerToString(i)," symbol = ",arrSymbols[i]," & symbol.handleAtr = "+IntegerToString(symbol.handleAtr)); } Print ("symbols.Total() = ",IntegerToString(symbols.Total())); for (int i = symbols.Total()-1; i>= 0; i--) { CSymbol* symbol = symbols.At(i); CTrade trade; double bid = SymbolInfoDouble (symbol.symbol,SYMBOL_BID); double atr[]; CopyBuffer(symbol.handleAtr,MAIN_LINE,1,5,atr); Print (" i = ",IntegerToString(i)," symbol = ",symbol,symbol," handleAtr = ",symbol.handleAtr," symbol = ",symbol); } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+
All compiles and runs but confused by the output and why "symbol or symbol.symbol" fails to produce anything recognisable (to me)
.....and do I need a different handle for each time frame? (I think I do but again want to make sure)
Again appreciate any help
Lorentzos
Hi Hope you don't mind me returning on this one.
I am trying to utlise CLASSES more often and the above problem seemed to be an ideal opportunity.
I coded a very simple example
All compiles and runs but confused by the output and why "symbol or symbol.symbol" fails to produce anything recognisable (to me)
.....and do I need a different handle for each time frame? (I think I do but again want to make sure)
Again appreciate any help
on the symbol,symbol line you are printing the object . should be symbol.symbol
yes you need a different handle for each timeframe
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying to code 'correctly' and efficiently in MT5.
I have an EA that loops through different currency pairs and for each currency looks at an Indicator using the iCustom function.
As I understand I don't need to RELEASE a handle but ....
1. Do I need a separate HANDLE for each currency PAIR? [access via an Array perhaps]
2. If I wish to look at - for example - the MAX & MIN values over 100 and 250 bars can I use the same handle again with a different COPY statement.
Somewhere I have seen that MT5 doesn't doesn't require Release of the HANDLE whereas MT4 would.
Any help appreciated and thanks in advance