Hello friends,
i have a big problem to get all Bars of Chart into DLL. In the Files DLLSample.cpp and DLLSampleTester.mq4 in MT4-folder is an Example to do that but it doesn´t work. I take the code from this files to pass all Bars to DLL but in MT4 EA-Backtest i get this Error:
Cannot find 'GetRatesItemValue' in 'testdll.dll'
unresolved import function call
Testing pass stopped due to a critical error in the EA
i create the DLL with MVS 2015.
It would be great when you can help me to solve this Error, I spend very lot of time to get a solution but it doesn´t work.
Code MQL:
//+------------------------------------------------------------------+
//| DLLSampleTester.mq4 |
//| Copyright © 2005-2014, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005-2014, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#import "testdll.dll"
double GetRatesItemValue(MqlRates &rates[],int,int,int);
#import
#define TIME_INDEX 0
#define OPEN_INDEX 1
#define LOW_INDEX 2
#define HIGH_INDEX 3
#define CLOSE_INDEX 4
#define VOLUME_INDEX 5
//+------------------------------------------------------------------+
//| array functions call |
//+------------------------------------------------------------------+
int start()
{
double price;
MqlRates rates[];
//--- get current close
ArrayCopyRates(rates);
price=GetRatesItemValue(rates,Bars,0,CLOSE_INDEX);
Print("Returned from Close ",price);
//---
return(0);
}
//+------------------------------------------------------------------+
int init()
{
return(0);
}[/CODE]
Code DLL C++:
[CODE]//+------------------------------------------------------------------+
//| Sample DLL for MQL4 |
//| Copyright 2001-2015, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include "stdafx.h"
#include
#include
#include
//---
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#pragma pack(push,1)
struct RateInfo
{
__int64 ctm;
double open;
double low;
double high;
double close;
unsigned __int64 vol_tick;
int spread;
unsigned __int64 vol_real;
};
#pragma pack(pop)
MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates, const int rates_total, const int shift, const int nrate)
{
//---
if (rates == NULL)
{
printf("GetRatesItemValue: NULL array\n");
return(0.0);
}
//---
if (rates_total<0)
{
printf("GetRatesItemValue: wrong rates_total number (%d)\n", rates_total);
return(0.0);
}
//---
if (shift= rates_total)
{
printf("GetRatesItemValue: wrong shift number (%d)\n", shift);
return(0.0);
}
//---
if (nrate5)
{
printf("GetRatesItemValue: wrong rate index (%d)\n", nrate);
return(0.0);
}
//---
int nitem = rates_total - 1 - shift;
switch (nrate)
{
case 0: return double(rates[nitem].ctm);
case 1: return rates[nitem].open;
case 2: return rates[nitem].low;
case 3: return rates[nitem].high;
case 4: return rates[nitem].close;
case 5: return double(rates[nitem].vol_tick);
}
//---
return(0.0);
}The problem is not in the function, but in the way you compiled the dll. You need to export the "GetRatesItemValue" function in order to make it accessible from mt4
The problem is not in the function, but in the way you compiled the dll. You need to export the "GetRatesItemValue" function in order to make it accessible from mt4
Thank you. How does this work? I need to change specific settings in MVS 2015 ?
You need to specify that in a project file
What exactly do you mean? I am not a professional in Visual Studio, I try to change some settings when i create the Projekt but there is every time the same failure when i start the EA in Mt4.
The files in the Project are:
Header Files: stdafx.h and targetver.h
Source Files: dllmain.cpp, stdafx.cpp, testdll.cpp
When I create a dll Function with only 1D Array or simple Variables it works. The Problem is only with the code/function obove to pass all bars (2D Array?).
The sample code from Metaquotes is wrong.
That was hard but I have the solution:
Use
Instead of
[CODE]#define MT4_EXPFUNC __declspec(dllexport)
MT4_EXPFUNC double __stdcall GetRates...- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello friends,
i have a big problem to get all Bars of Chart into DLL. In the Files DLLSample.cpp and DLLSampleTester.mq4 in MT4-folder is an Example to do that but it doesn´t work. I take the code from this files to pass all Bars to DLL but in MT4 EA-Backtest i get this Error:
Cannot find 'GetRatesItemValue' in 'testdll.dll'
unresolved import function call
Testing pass stopped due to a critical error in the EA
i create the DLL with MVS 2015.
It would be great when you can help me to solve this Error, I spend very lot of time to get a solution but it doesn´t work.
Code MQL:
//+------------------------------------------------------------------+
//| DLLSampleTester.mq4 |
//| Copyright © 2005-2014, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005-2014, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#import "testdll.dll"
double GetRatesItemValue(MqlRates &rates[],int,int,int);
#import
#define TIME_INDEX 0
#define OPEN_INDEX 1
#define LOW_INDEX 2
#define HIGH_INDEX 3
#define CLOSE_INDEX 4
#define VOLUME_INDEX 5
//+------------------------------------------------------------------+
//| array functions call |
//+------------------------------------------------------------------+
int start()
{
double price;
MqlRates rates[];
//--- get current close
ArrayCopyRates(rates);
price=GetRatesItemValue(rates,Bars,0,CLOSE_INDEX);
Print("Returned from Close ",price);
//---
return(0);
}
//+------------------------------------------------------------------+
int init()
{
return(0);
}[/CODE]
Code DLL C++:
[CODE]//+------------------------------------------------------------------+
//| Sample DLL for MQL4 |
//| Copyright 2001-2015, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include "stdafx.h"
#include
#include
#include
//---
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#pragma pack(push,1)
struct RateInfo
{
__int64 ctm;
double open;
double low;
double high;
double close;
unsigned __int64 vol_tick;
int spread;
unsigned __int64 vol_real;
};
#pragma pack(pop)
MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates, const int rates_total, const int shift, const int nrate)
{
//---
if (rates == NULL)
{
printf("GetRatesItemValue: NULL array\n");
return(0.0);
}
//---
if (rates_total<0)
{
printf("GetRatesItemValue: wrong rates_total number (%d)\n", rates_total);
return(0.0);
}
//---
if (shift= rates_total)
{
printf("GetRatesItemValue: wrong shift number (%d)\n", shift);
return(0.0);
}
//---
if (nrate5)
{
printf("GetRatesItemValue: wrong rate index (%d)\n", nrate);
return(0.0);
}
//---
int nitem = rates_total - 1 - shift;
switch (nrate)
{
case 0: return double(rates[nitem].ctm);
case 1: return rates[nitem].open;
case 2: return rates[nitem].low;
case 3: return rates[nitem].high;
case 4: return rates[nitem].close;
case 5: return double(rates[nitem].vol_tick);
}
//---
return(0.0);
}