if(called == false) { ArrayCopyRates(rates,NULL,0); called = true; }
ACR you could do in OnInit and drop the rest.if(called == false)
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. "if called" is incomplete. if isFirstTick or if needACR are not.- In MT4 rates[0] is the current value (a series array,) in the DLL rates[0] is the oldest.
WHRoeder:
- ACR you could do in OnInit and drop the rest.
- You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. "if called" is incomplete. if isFirstTick or if needACR are not.
- In MT4 rates[0] is the current value (a series array,) in the DLL rates[0] is the oldest.
thank you for your input. Strangely the DLL only returns correct values for rates[0] (oldest MqlRates). All other entries (rates[1,x]) return some "random" numbers which are obviously not random but just don't make sense to me.
Here is the updated code
MQL
int OnInit() { ArrayCopyRates(rates,NULL,0); int i = 0; while(i <= 5) { Print(StringConcatenate( "mql: ",iHigh(NULL,0,ArraySize(rates)-i-1), " | c++: ",ihigh(rates,ArraySize(rates)+i,ArraySize(rates)) )); i++; } return(INIT_SUCCEEDED); }
C++
_DLLAPI double __stdcall ihigh(RateInfo* rate, int pos, int size) { return rate[(size - pos)].high; }
Output:
mql: 0.73693 | c++: -3.967731946867355e-270 mql: 0.73693 | c++: 0 mql: 0.7370600000000001 | c++: 5.896060841714434e-316 mql: 0.73714 | c++: 0 mql: 0.73716 | c++: 0 mql: 0.73717 | c++: 0.73717
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
Hi,
I have a problem passing the current MqlRates to a C++ DLL. Here is what I have done so far:
MQL
C++
I would expect the DLL to have the current MqlRates for calculation. The values returned by the dll are totally different of the actual mqlrates however. Any hints on what I am doing wrong?
Best Regards