включение библиотеки из с++

 

Здравствуйте.

Я учусь писать библиотеки на с++. Нашел пример в инете http://www.forexfactory.com/showthread.php?p=4753580 . все хорошо. ошибок нет. Но если в индикаторе вставлена функция, то он не работает. как только ее отключить работает. Я тестирую работу просто на Alert

MQL4

//+------------------------------------------------------------------+
//|                                                      mySMA10.mq4 |
//|                                                 
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property indicator_chart_window
//+------------------------------------------------------------------+

// Import and declare the DLL, with its parameters defined
#import "mySMA10.dll"
void    GetSMAArray( double &Rates[][6],int MaximumRecords, int Periods, double& OutPut[]);
#import

// At the very beginning of the chart, before the MA has
// had enough data to draw itself properly, do not display
int nDrawBeginBar;

// Indicator Buffers
double OutPut[]; // custom indicator pre-defined buffer
extern int Periods = 10; // Default value - can be changed via GUI

//int ExtCountedBars = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer( 0, OutPut ); //Binds array variable declared at global level to the custom indicator pre-defined buffer
   
   // Drawing settings
   SetIndexStyle( 0, DRAW_LINE, 0, 1, Red); // Default values - can be changed via GUI
   SetIndexLabel( 0, "My SMA 10" );         // Description shown in the DataWindow and in the tooltip
   
   // Skip drawing at the beginning of a chart
    nDrawBeginBar = Periods;
    SetIndexDrawBegin(0, nDrawBeginBar);
    
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double Rates[][6];
  int MaximumRecords = ArrayCopyRates( Rates, Symbol(), 0 );
   for( int zz = MaximumRecords-1; zz >= 0; zz-- ) { OutPut[zz] = EMPTY; }
     GetSMAArray( Rates, MaximumRecords, Periods, OutPut ); // если отключить, то индикатор дает алерт, а так нет
     Alert("bbb"); 
   return(0); 
  
  } 
//+------------------------------------------------------------------+


С++
#include "stdafx.h"


#ifdef __cplusplus
extern "C" {
#endif

#include <windows.h>


#define WIN32_LEAN_AND_MEAN
#define MT4_EXPFUNC __declspec(dllexport)

//+-----------------------------------------------------------------------------------------------------------------------------+
//|                                                            MT4 DATA STRUCT                                                        |
//+-----------------------------------------------------------------------------------------------------------------------------+
#pragma pack(push,1)
struct RateInfo { unsigned int ctm; double open; double low; double high; double close; double vol; };
struct MqlStr   {          int len; char   * string;                                                };
#pragma pack(pop)
//+-----------------------------------------------------------------------------------------------------------------------------+

MT4_EXPFUNC void _stdcall GetSMAArray( RateInfo* Rates, int MaximumRecords, int Period, double Result[] )
{
      for( int ii = 0; ii < MaximumRecords; ii++)
      {
          double Sum = 0.0;
            for( int kk = 0; kk < Period ; kk++ )
            {
                Sum += Rates[MaximumRecords-ii-1-kk].close;
            }
        Result[MaximumRecords-ii-1] = Sum / Period ;
      }
}

#ifdef __cplusplus
}
#endif
Помогите пожалуйста
 
Посмотрите в папке Scripts\Examples\Dll там лежит пример.
 
double Rates[][6];

Вы создаёте массив, а нужно структуру.

MqlRates rates[];
 
спасибо
 
PozitiF:
Посмотрите в папке Scripts\Examples\Dll там лежит пример.
Алексей, а где такая папка ?
 
Вот тут посмотрите, посмотреть.