자신만의 MetaTrader 확장 프로그램(dll) 생성 - 페이지 13

 
apprentice coder:
감사합니다 dll 함수에서 반환 값으로 배열을 얻는 방법이 있습니까?

메타트레이더를 사용하여 그렇게 하는 유일한 방법은 배열을 만들고 dll 함수 에 대한 참조로 전달하고 해당 배열을 채우는 것입니다. Metatrader는 dll 함수의 반환 값으로 배열을 허용하지 않습니다.

 
mladen:
메타트레이더를 사용하여 그렇게 하는 유일한 방법은 배열을 만들고 dll 함수에 대한 참조로 전달하고 해당 배열을 채우는 것입니다. Metatrader는 배열을 dll 함수의 반환 값으로 허용하지 않습니다.

알았어 고마워

 

mql#에 문제가 있습니다.

여기에 C#에 대한 문제 코드가 없습니다.

using System; using System.Text; using RGiesecke.DllExport; using System.Runtime.InteropServices; using System.Windows.Forms; namespace shine { class Test { [DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)] public static double AddDouble() { System.MetaTrader hano = new MetaTrader(); double Values1 = hano.iCustom(hano.Symbol(), 0, "Borohul", 60, 50, 6, 1.3, true, true, false, false, true, false, false, 1, 0); return (Values1); } } }[/CODE]

Here mql code.

[CODE]

//+------------------------------------------------------------------+ //| testDLL.mq4 | //| Copyright © 2011, Patrick M. White | //| https://sites.google.com/site/marketformula/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Patrick M. White" #property link "https://sites.google.com/site/marketformula/" #import "testUMD600.dll" double AddDouble(); #import //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- Alert(AddDouble()); //---- return(0); } //+------------------------------------------------------------------+

그러나 라이브 차트를 테스트하면 Metatrader 플랫폼이 자동으로 닫힙니다. 왜 나를 위해?

 

경험상 항상 C#의 각 DLL 함수 내에서 오류를 처리합니다. 그렇게 하지 않으면 Metatrader가 자동으로 닫히는 위치에서 보고 있는 효과가 발생합니다. 각 공개 dll 함수에 try/catch 블록을 넣으면 문제의 원인을 확인할 수 있습니다. 아마도 Metatrader에 피드백을 제공하여 종료시키는 dll의 처리되지 않은 오류일 것입니다. 오류 처리 및 오류 처리는 C#에서 MT4 dll 프로세스로의 가장 어려운 부분입니다. 저는 이 포럼을 자주 확인하지 않기 때문에 블로그에 댓글로 질문을 하면 알림을 받고 보다 신속하게 답변할 수 있습니다.

sosa247:
여기에 C#에 대한 문제 코드가 없습니다.

using System; using System.Text; using RGiesecke.DllExport; using System.Runtime.InteropServices; using System.Windows.Forms; namespace shine { class Test { [DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)] public static double AddDouble() { System.MetaTrader hano = new MetaTrader(); double Values1 = hano.iCustom(hano.Symbol(), 0, "Borohul", 60, 50, 6, 1.3, true, true, false, false, true, false, false, 1, 0); return (Values1); } } }[/CODE]

Here mql code.

[CODE]

//+------------------------------------------------------------------+ //| testDLL.mq4 | //| Copyright © 2011, Patrick M. White | //| https://sites.google.com/site/marketformula/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Patrick M. White" #property link "https://sites.google.com/site/marketformula/" #import "testUMD600.dll" double AddDouble(); #import //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- Alert(AddDouble()); //---- return(0); } //+------------------------------------------------------------------+
그러나 라이브 차트를 테스트하면 Metatrader 플랫폼이 자동으로 닫힙니다. 왜 나를 위해?
 
sosa247:
여기에 C#에 대한 문제 코드가 없습니다.

using System; using System.Text; using RGiesecke.DllExport; using System.Runtime.InteropServices; using System.Windows.Forms; namespace shine { class Test { [DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)] public static double AddDouble() { System.MetaTrader hano = new MetaTrader(); double Values1 = hano.iCustom(hano.Symbol(), 0, "Borohul", 60, 50, 6, 1.3, true, true, false, false, true, false, false, 1, 0); return (Values1); } } }[/CODE]

Here mql code.

[CODE]

//+------------------------------------------------------------------+ //| testDLL.mq4 | //| Copyright © 2011, Patrick M. White | //| https://sites.google.com/site/marketformula/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Patrick M. White" #property link "https://sites.google.com/site/marketformula/" #import "testUMD600.dll" double AddDouble(); #import //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- Alert(AddDouble()); //---- return(0); } //+------------------------------------------------------------------+
그러나 라이브 차트를 테스트하면 Metatrader 플랫폼이 자동으로 닫힙니다. 왜 나를 위해?

이전 버전에서 작동한 예가 있습니까?

 

아마도 보호 문제

 
pipscooper:
경험상 항상 C#의 각 DLL 함수 내에서 오류를 처리합니다. 그렇게 하지 않으면 Metatrader가 자동으로 닫히는 위치에서 보고 있는 효과가 발생합니다. 각 공개 dll 함수에 try/catch 블록을 넣으면 문제의 원인을 확인할 수 있습니다. 아마도 Metatrader에 피드백을 제공하여 종료시키는 dll의 처리되지 않은 오류일 것입니다. 오류 처리 및 오류 처리는 C#에서 MT4 dll 프로세스로의 가장 어려운 부분입니다. 저는 이 포럼을 자주 확인하지 않기 때문에 블로그에 댓글로 질문을 하면 알림을 받고 보다 신속하게 답변할 수 있습니다.

그 코드만으로는 이유를 알 수 없습니다(일부 사용 리소스에 문제가 있을 수 있음)

 

안녕하세요 여러분,

DLL 표시기/MT4를 실행하려고 합니다... 재귀 SMA에 대한 코드이지만 작동하지 않습니다. 블로그에서 가져왔습니다.

왜 / 어디에 결함이 있는지 아는 사람이 있습니까?

DLL 파일은 C++로 작성되었으며 오류 없이 VC 2010에서 ( 프로젝트 로) 컴파일됩니다.

이 코드를 실행하려고 하면 MT4가 아무 작업도 수행하지 않습니다. 표시기가 표시되지 않습니다...

힌트가 있나요?

감사합니다 그리고 안녕, AT

MQL4 코드:

//sma_rec.mqh file begin

#import "sma_rec.dll"

void updateBuffer( double& Rates[], double& buffer[], int bars, int indicator_counted, int ma_period, double& internal_calcs[2] );

#import

//sma_rec.mqh file end

//sma_rec.mq4 file begin

#include

#property indicator_chart_window // indicator plotted in main chart window

#property indicator_buffers 1 // one indicator line to be plotted

#property indicator_color1 Red // plot colour is red - change via GUI

//+------------------------------------------------------------------+

// Import and declare the DLL, with its parameters defined

#import "sma_rec.dll"

// history, buffer and internal_calcs are passed by reference, this means the dll

// will receive pointers to the arrays

void updateBuffer(double& Rates[][6], double& buffer[], int bars, int indicator_counted, int period, double& internal_calcs[2] );

#import

extern int ma_period = 10; // default period is 10 - change via GUI

extern int ma_shift = 0; // default is no shift - change via GUI

double buffer[]; // the indicator buffer - the DLL will

// write to this and it will be plotted

double Rates[][6]; // this will later point to the complete

// chart history

double internal_calcs[2]; // this array will hold the values of the

// internal calculations of the DLL and will

// be read from and written to by the DLL.

// The size of the array is set at 2. If

// needs be, the size can be increased to

// accommodate more complicated calculations

// within the DLL.

int init(){

// set up the indicator buffer

SetIndexStyle(0, DRAW_LINE);

SetIndexShift(0, ma_shift);

SetIndexBuffer(0, buffer);

SetIndexLabel(0, "Recursive SMA");

IndicatorDigits(Digits);

}

int start(){

ArrayCopyRates( Rates, NULL, 0 );

updateBuffer( Rates, buffer, Bars, IndicatorCounted(), ma_period, internal_calcs );

//Print(buffer[]);

}

//sma_rec.mq4 file end

[/CODE]

Code in C++

//dllmain.cpp:

#include "stdafx.h"

BOOL APIENTRY DllMain( HMODULE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

main function of SMA rec.cpp

[CODE]

#include

#include "stdafx.h"

#include

#define WIN32_LEAN_AND_MEAN

#define MT4_EXPFUNC __declspec(dllexport)

//+------------------------------------------------------------------+

//| MT4 HISTORY DATA STRUCT |

//+------------------------------------------------------------------+

#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)

//---

struct MqlStr

{

int len;

char *string;

};

static int CompareMqlStr(const void *left,const void *right);

//+------------------------------------------------------------------+

//|

EXTERN_C __declspec(dllexport) void __stdcall updateBuffer( RateInfo* Rates, double buffer[],int Bars, int IndicatorCounted, int ma_period, double internal_calcs[2] )

// MT4_EXPFUNC void _stdcall updateBuffer( RateInfo* Rates, double buffer[],int Bars, int IndicatorCounted, int ma_period, double internal_calcs[2] )

{

// check if the DLL is being called for the very first time

if ( IndicatorCounted == 0 )

{

// if so, calculate indicator values from the beginning of the array up to

// "current" bar - firstly for buffer[0] to buffer[ma_period - 1] fill the

// buffer with increasing moving average values up to the desired moving

// average period i.e. the second bar in buffer has value of ma_period = 2;

// the third bar in buffer array has value of ma_period = 3 etc.

buffer[0] = Rates[0].close;

buffer[1] = ( Rates[0].close + Rates[1].close ) / 2.0;

for( int ii = 2 ; ii < ma_period ; ii++ )

{

buffer = ( ( buffer * ii ) / (ii+1) ) + ( Rates.close/(ii+1) );

}

// secondly, after the initial part of the buffer is filled, the rest of the

// buffer is filled using a recursive SMA algorithm. If the SMA were

// calculated by looping over previous bar values there would be ma_period-1

// additions and one division operation per loop of a nested loop. This

// simple recursive algorithm does away with the need for a nested loop

// completely and reduces the number of arithmetic operations to four per

// bar. More importantly, for learning purposes, it will enable code to be

// shown for passing parameters that hold the state of internal calculations

// to and from the DLL.

for( int ii = ma_period ; ii < Bars - 1 ; ii++ )

{

buffer = ( buffer - (Rates.close/ma_period) ) + ( Rates.close/ma_period );

}

// now return the values of the internal calculations to the internal_calcs

// array pending the next call to the DLL

internal_calcs[0] = (Rates.close/ma_period);

// the value // to be used in the next SMA calculation

internal_calcs[1] = Bars - 1; // how many indicator values calculated so far

} // end of ( IndicatorCounted = 0 ) if statement for first call of the DLL.

// Once this piece of the code has been run once, on the initial call to the

// DLL, it will never be run again because the condition IndicatedCounted ==

// 0 will never be true again.

// this next piece of code will be evaluated on the second and all subsequent

// calls to the DLL because the condition IndicatorCounted > 0 will always be

// true after the DLL's initial call. Note that the second part of the

// logical AND, namely (Bars - 1) > internal_calcs[1], ensures that the code

// will only run when a bar has completely formed and a new bar has opened.

// This is important to ensure that values contained in the internal_calcs

// array are not overwritten by the constantly changing values of the

// currently forming bar. Note that, as above, this is a recursive SMA

// algorithm so there is no loop.

if ( IndicatorCounted > 0 && (Bars - 1) > internal_calcs[1] ) // evaluates to TRUE if there is a new bar

{

buffer = ( buffer - internal_calcs[0] ) + ( Rates.close/ma_period ); // calculate new SMA value

internal_calcs[0] = (Rates.close/ma_period); // update

// internal_calcs with new value for next SMA calc.

internal_calcs[1] = Bars - 1; // update how many indicator values calculated so

// far

} // end of ( IndicatorCounted > 0 && (Bars - 1) > internal_calcs[1]) if

// statement

} // end of main function call

 

저널 또는 전문가 탭에 어떤 오류가 표시됩니까?

 

안녕 믈라덴!

대답 해줘서 고마워요!

없음! 그게 문제야... :-/

표시창이 열리지만 인디가 표시되지 않습니다...

도움/아이디어 감사합니다. AT