dingmaotu / mql4-lib Goto Github PK
View Code? Open in Web Editor NEWMQL4/5 Foundation Library For Professional Developers
License: Apache License 2.0
MQL4/5 Foundation Library For Professional Developers
License: Apache License 2.0
Hi Ding Li,
still I dont know how to make pull requests, so here is what I did local to make Set work again. I dont know, if that is all what is todo. But at least it should be the compatibility with the new iterator interface and with the new Collection constructor.
Greetings
Martin
` Collection/Set.mqh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Collection/Set.mqh b/Collection/Set.mqh
index efe3ee0..b6234c7 100644
--- a/Collection/Set.mqh
+++ b/Collection/Set.mqh
@@ -34,7 +34,7 @@ public:
// Iterator interface
Iterator*iterator() const {return new SetIterator(m_array);}
// for Set initial buffer set to zero
Set(int buffer=0):m_array(buffer){}
Set(bool owned=true,int buffer=0,EqualityComparer<T>*comparer=NULL):Collection<T>(owned,comparer),m_array(buffer){}
Issues with pull request #27:
Nil
constant is unknown;SafeDelete()
checks the pointer by CheckPointer()
and does nothing with NULL pointer.@dingmaotu: please check the build is ok before accepting pulls.
Mql\Format\Json.mqh
bool parseInt(int &sign,int &value)
{
sign=1;
unichar c=m_stream.nextChar();
if(c=='-')
{
sign=-1;
c=m_stream.nextChar();
}
value=0;
if(c=='0') // 0
{
// sign=1; // 上面預設就是sign=1這裡還做sign=1會把負數變為正
return true;
}
else if(c<='9' && c>='1') // onenine 0..9
{
do
{
value*=10;
value+=(int)(c-'0');
c=m_stream.nextChar();
}
while(c<='9' && c>='0');
m_stream.pushChar(c);
return true;
}
else
{
return false;
}
}
Great job! there is no get method in Map interface,but pop() work.it would be better if add get method as java.
Order *o=map.get("800100");
Hi,
having little experience with MQL, I'm having difficulty using the collection classes with custom classes. I'm trying to store custom class instances in a Vector without success. This is one of the many variants I have tried so far:
#property strict
#property indicator_chart_window
#include <Mql\Collection\Vector.mqh>
class CSignal
{
private:
datetime _timestamp;
string _message;
color _color;
public:
datetime getTimestamp(){ return _timestamp; }
string getMessage(){ return _message; }
color getColor() { return _color; }
string getDisplayMessage()
{
MqlDateTime date;
TimeToStruct(_timestamp, date);
return StringFormat("%s : %02i/%02i %02i:%02i", _message, date.mon, date.day, date.hour, date.min);
}
CSignal() : _timestamp(0), _message(NULL), _color(clrNONE) {}
CSignal(datetime timestamp, string message, color clr){ _timestamp = timestamp; _message = message; _color = clr; }
CSignal(const CSignal & other) {
_timestamp = other._timestamp;
_message = other._message;
_color = other._color;
}
~CSignal(){}
};
Vector<CSignal> _signals;
int OnInit()
{
for (int i=0; i<10; i++)
{
CSignal signal(TimeCurrent(), "This is a message", clrBlue);
_signals.add(signal);
}
foreachv(CSignal, s, _signals)
Print(s.getDisplayMessage());
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
return(rates_total);
}
This gives me a bunch of errors:
⛔ : 'CSignal' - objects are passed by reference only (43,18)
⛔ : 'const' - objects are passed by reference only (29,21)
⛔ : 'const' - objects are passed by reference only (29,34)
⛔ : 'const' - objects are passed by reference only (30,19)
⛔ : 'CSignal' - objects are passed by reference only (137,26)
⛔ : 'const' - objects are passed by reference only (139,29)
⛔ : 'const' - objects are passed by reference only (145,31)
⛔ : 'const' - objects are passed by reference only (157,27)
⛔ : 'CSignal' - objects are passed by reference only (39,26)
⛔ : 'const' - objects are passed by reference only (40,29)
⛔ : 'CSignal' - objects are passed by reference only (43,37)
⛔ : 'CSignal' - objects are passed by reference only (46,32)
⛔ : 'CSignal' - objects are passed by reference only (50,27)
⛔ : 'CSignal' - objects are passed by reference only (53,30)
⛔ : 'CSignal' - objects are passed by reference only (100,26)
⛔ : 'const' - objects are passed by reference only (101,29)
⛔ : 'CSignal' - objects are passed by reference only (124,37)
⛔ : 'CSignal' - objects are passed by reference only (138,32)
⛔ : 'CSignal' - objects are passed by reference only (143,27)
⛔ : 'CSignal' - objects are passed by reference only (146,30)
⛔ : 'CSignal' - objects are passed by reference only (112,26)
• in template 'Iter<CSignal>' specified with [T=CSignal] (112,26)
⚠️ : possible use of uninitialized variable 's' (47,2)
⛔ : 'const' - objects are passed by reference only (39,30)
• in template 'GenericEqualityComparer<CSignal>' specified with [T=CSignal] (39,30)
⛔ : 'const' - objects are passed by reference only (39,43)
• in template 'GenericEqualityComparer<CSignal>' specified with [T=CSignal] (39,43)
⛔ : 'const' - objects are passed by reference only (40,28)
• in template 'GenericEqualityComparer<CSignal>' specified with [T=CSignal] (40,28)
⛔ : 'SafeDelete' - no one of the overloads can be applied to the function call (44,31)
• could be one of 2 function(s) (44,31)
• void SafeDelete(T*) (44,31)
• void SafeDelete(T) (44,31)
⛔ : 'CSignal' - objects are passed by reference only (195,26)
• in template 'VectorIterator<CSignal>' specified with [T=CSignal] (195,26)
⛔ : 'SafeDelete' - no one of the overloads can be applied to the function call (71,13)
• could be one of 2 function(s) (71,13)
• void SafeDelete(T*) (71,13)
• void SafeDelete(T) (71,13)
⛔ : 'SafeDelete' - no one of the overloads can be applied to the function call (117,22)
• could be one of 2 function(s) (117,22)
• void SafeDelete(T*) (117,22)
• void SafeDelete(T) (117,22)
⛔ : 'val' - objects are passed by reference only (125,35)
⛔ : 'm_array' - objects are passed by reference only (29,39)
⛔ : 'ArrayInsert' - cannot to apply template (125,13)
• see declaration of 'ArrayInsert' (125,13)
⛔ : '==' - illegal operation use (39,85)
⛔ : 'Hash' - no one of the overloads can be applied to the function call (40,66)
• could be one of 15 function(s) (40,66)
• int Hash(const string) (40,66)
• int Hash(const char) (40,66)
• int Hash(const bool) (40,66)
• int Hash(const uchar) (40,66)
• int Hash(const short) (40,66)
• int Hash(const ushort) (40,66)
• int Hash(const int) (40,66)
• int Hash(const uint) (40,66)
• int Hash(const long) (40,66)
• int Hash(const ulong) (40,66)
• int Hash(const float) (40,66)
• int Hash(const double) (40,66)
• int Hash(const datetime) (40,66)
• int Hash(const color) (40,66)
• int Hash(T*) (40,66)
⛔ : object of 'CSignal' cannot be returned, copy constructor 'CSignal::CSignal(const CSignal &)' not found (193,60)
[Error] Result: 34 errors, 1 warnings
I also tried
Vector<CSignal> * _signals = new Vector<CSignal>();
...
CSignal * signal = new CSignal(TimeCurrent(), "This is a message", clrBlue);
_signals.add(signal);
but also without success.
I'm stuck and any help is greatly appreciated.
for (int i = fractalData.size()-1; i >= 0; i--)
{
Print(__FUNCTION__, " Current i: ", i, " fractal data size: ", fractalData.size());
if (fractalData.get(i).GetFractalType() == fractalType || fractalData.get(i).GetFractalType() == BIDIRECTIONAL) //
{
return fractalData.get(i);
}
}
2019.10.11 15:28:43.155 2017.04.21 12:05:16 FSharp EURUSD,H1: array out of range in 'Vector.mqh' (134,61)
2019.10.11 15:28:43.155 2017.04.21 12:05:16 FSharp EURUSD,H1: Vector<Fractal*>::get current element trying to fetch is: 4 array size: 6
2019.10.11 15:28:43.155 2017.04.21 12:05:16 FSharp EURUSD,H1: Vector<Fractal*>::get current element trying to fetch is: 4 array size: 6
2019.10.11 15:28:43.155 2017.04.21 12:05:16 FSharp EURUSD,H1: GetLatestFractal Current i: 4 fractal data size: 6
2019.10.11 15:28:43.155 2017.04.21 12:05:16 FSharp EURUSD,H1: Vector<Fractal*>::get current element trying to fetch is: 5 array size: 6
2019.10.11 15:28:43.155 2017.04.21 12:05:16 FSharp EURUSD,H1: Vector<Fractal*>::get current element trying to fetch is: 5 array size: 6
Unexpected behavior trying to get the same object multiple times like in the if above.
First of all, congratulations on such an amazing job!
I tried to compile the file 'HelloWorldServer.mq4' in MetaEditor version 5 build 2401 but I get the following error:
'=' - type mismatch GlobalVariable.mqh 292 12
In 'GlobalVariable.mqh', the line in question is this one:
m_hm = new HM;
Could it be that the pointer is expecting to receive a 'HandleManager' object but is receiving a 'Context' object? Or am I missing something in the implementation and use of this example?
Could you help me with this?
Thanks in advance
There is a class member declared HashMap<>, how can I make m_owner=true in order to auto release RuleNode* value?
class RuleManager {
HashMap<string, RuleNode*> ruleNodes_; // m_owner=false by default
HashMap<string, RuleNode*> ruleNodes_(NULL, true); // bad grammar in mql5
}
It would be nice to have a possibility to set collection, specifically Vector to handle its entries as series, so that the order of entries is inversed. Alternatively, a new type could be implemented implementing Stack
hi, sorry to tell you:
when the newest versiong MT4(build1210 2019.9.6,), the following errors occur.
https://github.com/dingmaotu/mql4-lib/
LinkedList.mqh
line 188:
_clear(void)
'clear' - unexpected token, probably type is missing? LinkedList.mqh 188 13
'clear' - function already defined and has different type LinkedList.mqh 188 13
consider add more example for OrderGroup and OrderTracker.if have a simple ea demo use api even better.
I try to trace the code of SymbolAnalyzer::buildCurrencyIndex
of FxSymbol
module then find symbol is added into m_spacials
HashMap rather than building m_index
if Base currency equals to Profit currency of the given symbol.
However, broker "IG Market" provides symbols all having Base currency being the same to Profit currency, which cause zero size to m_index HashMap, so Invalid Point access error occurs when calling SymbolAnalyzer::getConversionSymbol
, as the member function uses pointers to refer to a zero-size map (i.e., m_index
).
May I know what is m_spacials
used for? as I don't see any access or operation to it on given code. appreciated if you would like to provide example or explanation to SymbolAnalyzer
Hello,
Thanks for your great library!!
In your example, is it safe to use the below code?
Everytime a key is removed, does the under memory layout change, and hence invalid the iterator?
//--- after the update
foreachm(int,key,int,value,m)
{
if(value%2==0) it.remove();
}
ArrayList is mentioned in the implementation, however, it's not part of the code. Should be either added or removed from the documentation
// for simplicity, I will not use the Lang/Script class
void OnStart()
{
LinkedList<Order*> list; (OrderList error)
int total= OrdersTotal();//TradingPool::total();(here.. i dont know, just use the mql offical....) for(int i=0; i<total; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) (here.. i don
t know, just use the mql offical....)
{
OrderPrint(); // to compare with Order.toString
list.push(new Order());
}
}
PrintFormat("There are %d orders. ",list.size());
===============
plz update TradingPool() in ur convience. thx lots.
Hey,
I'm using the Vector with customized class, is there any way to save and load the vector to the disk?
Thanks
Hi, I have tried your repository. It will good. But I thought that it will help me in making my program run using GPU via OpenCL. But could not understand as my Optimization is utilizing all the CPU instead of GPU.
Can you help me in making optimization process work with GPU?
1st of all a great library.
Can the last bit of MQL4/5 compatibility issues be completed soon?
consider add isEmpty() method for Collection(Map,List,Vector).
in real complex ea,may be we have many Collection Group.
eg:
Vector hedgeOneGroup;
Vector hedgeTwoGroup;
Vector buyGroup;
Vector sellGroup;
Vector limitGroup;
other....
when we check group for manage other group,we need isEmpty().
HashMap能否在 value 中存放 List 对象?
例如:HashMap<string, LinkedList>
场景如下:
在 order 遍历的时候,取出订单注释,按订单注释来做分组。
Map 的 key 是 comment,value 是分组的订单号。
写了一个 test,编译一下很多错误。
请帮忙给下实现的建议,谢谢。
There is a call for OrderPool::selectByTicket(ticket) in MqlCommand.mqh, however, a declaration of this function can not be found in the abstract class OrderPool
The function compact() in OrderGroup.mqh is not definited....
void OrderGroup::clearClosed(void) { int s=size(); for(int i=0; i<s; i++) { Order::Select(get(i)); if(Order::CloseTime()!=0) { set(i,NULL); } } compact(); }
I hope this message finds you well. I am writing to inquire about the current functionality of your library, specifically about MQL4.
I have encountered some difficulties in initializing a LinkedList. My attempts so far have been unsuccessful, and I'm unsure if this is due to an issue on my end. To clarify, here is the code snippet I used:
LinkedList<int> intList;
If the problem lies with my approach, I would greatly appreciate it if you could provide a complete example code to guide me.
I would also like to take this opportunity to express my gratitude for the immense effort and dedication that has gone into developing this remarkable library. Your hard work is sincerely appreciated.
Hello,
I'm testing your framework and it is awesome.
But I have an issue when I need to access an indicator with multiples buffers.
Is it possible to explain if it is possible to access other buffer that the one in for example Demarker indicator
double operator[](const int index) {return ExtMainBuffer[ArraySize(ExtMainBuffer)-index-1];}
What about if I need to access ExtMaxBuffer[]?
Is it a limit in the design and do I need to create some getter to access supplementaries buffers?
Best Regards,
Hello, can you tell me if it is possible with the help of this libary to trade mt4 accounts without need to put a EA on chart, justwith useing mt4 login details? I would guess its not possible but please somebody let me know if it is possible.
Hi, I see that you have experience with MQL, maybe you will be interested:
https://github.com/Roffild/RoffildLibrary
P.S. Github does not allow sending messages.
after upgrading to Metatrader terminal 4 build 1280 my Zero MQ implementation from Darwinx (DWX_ZeroMQ_Server_v2.0.1_RC8.mq4) project will no longer compile. i receive this error:
'=' - type mismatch GlobalVariable.mqh
in line 292 "m_hm=new HM;"
Please help! :)
Mql5 had dropped api like OrderXXX() , "Order Access" part seems not compatible Mql5
When the OrderSend()
returns -1 and sets _LastError
, OrderManager::send()
uses GetLastError()
, sends Alert()
and returns -1. This leaves no clue about the error to the caller. For example, I may want to repeat send()
in case of context lock, or maybe I should abort due to server problems. Since GetLastError()
effectively resets _LastError
, this deprives the calling function of knowing the error.
The reason is this. Say we have two experts on different charts. If they try to issue orders simultaneously one of them would receive ERR_TRADE_CONTEXT_BUSY error and would have to retry. But if the expert gets ERR_ACCOUNT_DISABLED error, it would have to stop trading at all. Using OrderManager
as is doesn't allow to distinguish the trading behavour.
The proposed solutions:
Mql::getLastError()
should memorize the last error, or;send()
, modify()
etc., orGetLastError()
semantics.Any thoughts?
The doc looks outdated, I checked the codebase, there is no Iter<T> at all.
for(Iter<IndicatorValue*> iter(list); !iter.end(); iter.next()){
...
}
I wan to iterate the list and find the target node, and insert a new T before the target node. maybe like this
foreach(T, list) {
if (it.current match condistion) {
list.insert(it, new T()); // how to code ?
}
}
Hello, I'm trying to get a SortedArray with its own type and its own SortComparer to work, but unfortunately I'm failing miserably with the following error message:
'PositionSortComparer' - cannot instantiate abstract class
see declaration of class 'PositionSortComparer'
'int EqualityComparer<Position*>::hash(const Position*) const' is abstract EqualityComparer.mqh 30 14
'int SortComparer<Position*>::compare(const Position*,const Position*) const' is abstract SortComparer.mqh 36 22
My data class and SortComparer implementation look like this:
class position
{
public:
double Size;
double PNL;
int Ticket;
Position(){}
Position(int ticket, double size, double pnl) : Ticket(ticket), Size(size), PNL(pnl)
{}
Position(const Position & other)
{
Ticket = other.Ticket;
Size = other.Size;
PNL = other.PNL;
}
};
class PositionSortComparer : public SortComparer<Position*>
{
public:
int hash(const Position* value)
{
return value.Ticket;
}
int compare(const Position* left, const Position* right)
{
if (left.Size > right.Size) return 1;
if (left.Size < right.Size) return -1;
return 0;
}
bool equals(const Position* left, const Position* right)
{
return left.Ticket == right.Ticket;
}
};
// usage
PositionSortComparer* comparer = new PositionSortComparer();
SortedArray<Position*>* sorted = new SortedArray<Position*>(comparer);
What am I doing wrong?
I am grateful for any help, best regards
mrhoga
It's very convenient ecode data with RESP and send by Zmq.
RESP use char &a[]
in encode api.
virtual int encode(char &a[],int i) const=0;
ZmgMsg use uchar &data[]
in get/set api.
void getData(uchar &data[]);
string getData();
void setData(const uchar &data[]);
I think uchar
is reasonable for both.
2017.12.06 08:33:10.440 test2 USDJPY,Monthly: 4168 bytes of leaked memory
2017.12.06 08:33:10.440 test2 USDJPY,Monthly: 25 objects of type CurrencyIndexEntry left
2017.12.06 08:33:10.440 test2 USDJPY,Monthly: 25 undeleted objects left
SymbolAnalyzer member: HashMap<string,CurrencyIndexEntry*> m_index;
should set HashMap owned = true
Hi... it's woonder to insert the comments management in the OrderManager....
some Mql programmers use this for retain some variables
Regards
Line 36: ObjectAttr(string,comment,Comment);
...
Line 178: int ticket=OrderSend(s,cmd,Math::roundUpToMultiple(lots,MINLOT), price,m_slippage, OS::N(s,stoploss), OS::N(s,takeprofit), m_comment,m_magic,0,m_color[cmd&1]);
Vector<Fractal*> fractalData;
...
void UpdateFractalData(Fractal &fractal)
{
if (fractal.GetFractalPriceHigh() != 0.0 && fractal.GetFractalPriceLow() != 0.0 && fractal.GetFractalTime() != 0 && fractal.GetFractalType() != UNDEFINED)
{
fractalData.push(fractal);
}
Gives the following compiller errors:
C:\Program Files (x86)\MetaTrader 4 IC Markets\MQL4\Experts\FSharp\FSharp.mqh(152,17) : error 166: 'push' - no one of the overloads can be applied to the function call
C:\Program Files (x86)\MetaTrader 4 IC Markets\MQL4\Experts\FSharp\FSharp.mqh : information: info could be one of 2 function(s)
C:\Program Files (x86)\MetaTrader 4 IC Markets\MQL4\Include\mql4-lib\Collection\Vector.mqh : information: info void Vector<Fractal*>::push(Fractal*)
C:\Program Files (x86)\MetaTrader 4 IC Markets\MQL4\Include\mql4-lib\Collection\List.mqh : information: info void List<Fractal*>::push(Fractal*)
call these step, it failed to remove element #25.
class MyHash : public HashMap<int, int> {
public:
void test() {
set(1,1);
set(2,1);
set(3,1);
set(4,1);
set(5,1);
set(6,1);
set(7,1);
set(8,1);
set(9,1);
remove(3);
remove(4);
remove(5);
remove(6);
remove(7);
remove(8);
set(10,1);
set(11,1);
set(12,1);
set(13,1);
set(14,1);
set(15,1);
remove(12);
remove(13);
remove(14);
set(16,1);
set(17,1);
set(18,1);
set(19,1);
set(20,1);
set(21,1);
set(22,1);
remove(16);
remove(17);
remove(18);
remove(19);
remove(20);
remove(21);
remove(22);
set(23,1);
set(24,1);
set(25,1);
set(26,1);
set(27,1);
remove(23);
if (remove(25))
PrintFormat("remove 25 ok %d", this[25]);
else
Print("remove 25 failed"); <-- goes here, this[25] == -1 actually
}
}
Must the method implementation check for m_owned
and do SafeDelete()
?
mql4-lib/Collection/Collection.mqh
Line 136 in e7608fb
For example, here, you say:
mql4-lib/Collection/Vector.mqh
Line 112 in e7608fb
What's the expected behaviour here?
Hi!Excellent work!In MT5 work flawessly in MT4 before new update also work as well.Now MT4 Build 1280 makes this error in the title above.I Know MT4/5 very little.Using Your library to push data to Python and .NET.
In #1 , @janckerchen reported:
If I just wanna find something then break in iteration, SafeDelete(it) at the end of loop, as your foreach macro defined, have no chance to be executed then memory leak show up.
I am using mac os m1 and both mt4 and mt5 can run on this os system
but it seems this mql4-lib and mt4-zmq, mt4-python integration failed to work on mac os m1
Do you have interested in implementing on the mac os m1?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.