DLL !!!

 

Помогите кто знает .

Написал такую DLL :

library WiliamsFunctions;


uses
Windows, // необходим для работы функции MessageBox
Dialogs, // необходим для работы процедуры ShowMessage из модуля Dialogs
SysUtils, // используется для константы UnixDateDelta
DateUtils, // используется для функции IncSecon, DateTimeToUnix
Classes;
type GreenBuffer = Array[1..6] of Double;
RedBuffer = Array[1..9] of Double;
BlueBuffer = Array[1..14] of Double;


{$R *.res}

//----------------------------------------------------------+
Function MQL5_Time_To_TDateTime(dt: Int64): TDateTime;
//----------------------------------------------------------+
begin
Result:= IncSecond(UnixDateDelta, dt);
end;

//----------------------------------------------------------+
Function TDateTime_To_MQL5_Time(dt: TDateTime):Int64;
//----------------------------------------------------------+
begin
Result:= DateTimeToUnix(dt);
end;



//----------------------------------------------------------+
Function AlligatorGreen(price : GreenBuffer) : Double ; stdcall;
//----------------------------------------------------------+
var i : Integer ;
prevsum,AVG : Double ;
begin
prevsum:=0;
for i:=2 to 6 do
begin
prevsum:=prevsum+price[i];
end;
AVG:=prevsum/5;
Result:=(prevsum-AVG+price[1])/5;
end;
//----------------------------------------------------------+

//----------------------------------------------------------+
Function AlligatorRed(price : RedBuffer) : Double ; stdcall;
//----------------------------------------------------------+
var i : Integer ;
prevsum,AVG : Double ;
begin
prevsum:=0;
for i:=2 to 9 do
begin
prevsum:=prevsum+price[i];
end;
AVG:=prevsum/8;
Result:=(prevsum-AVG+price[1])/8;
end;
//----------------------------------------------------------+


//----------------------------------------------------------+
Function AlligatorBlue(price : BlueBuffer) : Double ; stdcall;
//----------------------------------------------------------+
var i : Integer ;
prevsum,AVG : Double ;
begin
prevsum:=0;
for i:=2 to 14 do
begin
prevsum:=prevsum+price[i];
end;
AVG:=prevsum/13;
Result:=(prevsum-AVG+price[1])/13;
end;
//----------------------------------------------------------+
//----------------------------------------------------------+
exports
//----------------------------------------------------------+
AlligatorGreen,
AlligatorRed,
AlligatorBlue;
//----------------------------------------------------------+
begin


end.

и такой индикатор


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 Gray
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double GreenBuffer[6] ;
double RedBuffer [9] ;
double BlueBuffer [14];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+



#import "WiliamsFunctions.dll"

double AlligatorGreen(double Price[6] );
double AlligatorRed (double Price[9] );
double AlligatorBlue (double Price[14]);
#import





int init()

{
//---- indicators
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexShift (0,3);

SetIndexStyle (1,DRAW_LINE);

SetIndexBuffer(1,ExtMapBuffer2);
SetIndexShift (1,5);

SetIndexStyle (2,DRAW_LINE);

SetIndexBuffer(2,ExtMapBuffer3);
SetIndexShift (2,8);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit ;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0 || Bars<14) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
if(counted_bars<14) counted_bars=14;
limit=Bars-counted_bars;
for( i=limit-1; i>=0; i--)
{
ArrayCopySeries(GreenBuffer,MODE_CLOSE,Symbol(),Period());
ExtMapBuffer1[i]=AlligatorGreen(GreenBuffer);
}
return(0);
}



Терминал вырубается.


Для меня смысл не в том зачем это надо, а как его заставить работать . Для того чтобы набить руку в написании и подключении библиотек.

 

вероятно ругается на массивы

можно проверить, начав с одной-единственной простой функции в DLL, меняя типы параметров - найдёте, что не так

я когда разбирался с этим, решил запаковывать все входные-выходные данные в строки и передавать их как PChar - работает

возможно, что и на массивы нужны указатели, хотя не пробовал

 
спасибо попробую
 

вместо

#import "WiliamsFunctions.dll"
double AlligatorGreen(double Price[6] );
double AlligatorRed (double Price[9] );
double AlligatorBlue (double Price[14]);
#import

попробуй

#import "WiliamsFunctions.dll"
double AlligatorGreen(double &Price[] );
double AlligatorRed (double &Price[] );
double AlligatorBlue (double &Price[]);
#import

плюс почитай справку к ArrayCopySeries - в твоем случае НЕ происходит реального копирования данных, проблема может быть связана и с этим тоже.

 

начните с начала - почитайте https://www.mql5.com/ru/articles/96

 
Передавать массив по ссылке тоже ни к чему не приводит .
 
lucka88:
Передавать массив по ссылке тоже ни к чему не приводит .


? если Вы передаете данные по ссылке, то Вы разрешаете доступ к ним, как будет организован доступ - не Ваша проблема

посмотрите по ссылке:

Вызов для Object Pascal:
//----------------------------------------------------------+
function SetArray(var arr: IntegerArray; const len: Cardinal): PWideChar; stdcall;

type

IntegerArray= array[0..$effffff] of Integer;
DoubleArray = array[0..$effffff] of Double;

научитесь принимать и передавать массив в код советника, примерно:

в .dll {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} обратно {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}

если это сложно, тогда начните с еще проще:

double x=4; // типы разные

в x = mydll(); - результат кв.корень 

Причина обращения: