Errors, bugs, questions - page 1103

 
ingram:
Thanks for the tip! Everything works as it should through CTrade. But it's still not nice that documented functions don't work as they should. (((( lost 4 hours yesterday trying to make my Expert Advisor work properly, and it is not some random library, but a documented native function. Very strange!
The most important thing is that everything worked as it should.
 
MetaDriver:

1) What exactly is the running version of the terminal already installed?

2) And what kind of processor do you have? Does it support SSE2 instructions?

Sorry, no reply for a long time, it's been a lot of work.

1. terminal version 4.0 ticket 509 is installed.

2. AMD Duron 1.2 GHz processor SSE instructions are supported SSE2 is not supported...

Files:
fiwq5lfx.JPG  174 kb
Report.txt  31 kb
 
cichiniov:

Sorry I haven't replied for a long time, it's been a busy time.

1. terminal version 4.0 ticket 509 is installed.

2. AMD Duron 1.2 GHz processor SSE instructions are supported SSE2 is not supported...

That's the point. New builds will not work without SSE2 instructions support. You need to upgrade your hardware.
 
Can you please tell me what this error of the Expert Advisor means? "2014.02.13 05:29:06.885 stop_gambling EURUSD,H1: Error setting Sell trailing stop: 130" ??
 

It says in the help:

STAT_RECOVERY_FACTOR

The recovery factor is the STAT_PROFIT/STAT_BALANCE_DDratio

Maybe the help should be corrected. Checked it. The recovery factor is calculated by means.

 

The code (expert) is screwing up the 64 terminal... Developers, help! #956630

#import "msvcrt.dll"
   int memcpy(int &dst[], double &src[], int cnt);

#import "ntdll.dll"
   int RtlGetLastWin32Error();
   int RtlSetLastWin32Error(int dwErrCode);

#import "kernel32.dll"
   int   DeleteFileW (string lpFileName);
   
   int   CloseHandle(int hObject);
   int   CreateFileW(      string lpFileName,         int dwDesiredAccess, 
                           int dwShareMode,           int lpSecurityAttributes,
                           int dwCreationDisposition, int dwFlagsAndAttributes, 
                           int hTemplateFile
                     );

   int   SetFilePointer(int hFile, int lDistanceToMove, int& lpDistanceToMoveHigh[], int dwMoveMethod);
   int   SetEndOfFile (int hFile);
   int   ReadFile(int hFile, ushort& lpBuffer[], int nNumberOfBytesToRead, int& lpNumberOfBytesRead[], int lpOverlapped);
   int   WriteFile(int  hFile, int& lpBuffer[], int nNumberOfBytesToWrite, int& lpNumberOfBytesWritten[], int  lpOverlapped);
   int   GetFileSize(int hFile,  int notUsed = 0);
   
   int   FindFirstFileW(string path, int& answer[]);
   int   FindNextFileW(int handle, int& answer[]);
   int   FindClose(int handle);
   
   int   CreateDirectoryW(string path, int securityAttributes /*set to 0*/);
   
#import

#define  F_GENERIC_WRITE                0x40000000 // Доступ к файлу для записи.
const uint F_GENERIC_READ            = 0x80000000; // Доступ к файлу для чтения.

// ---- Параметр "dwShareMode".
#define  F_FILE_SHARE_NO                0x00000000 // Запрещает процессы открытия файла.
#define  F_FILE_SHARE_READ              0x00000001 // Подготавливает работу без ограничений в файле или устройстве для чтения.
#define  F_FILE_SHARE_WRITE             0x00000002 // Подготавливает работу без ограничений в файле или устройстве для записи.
#define  F_FILE_SHARE_DELETE            0x00000004 // Подготавливает работу без ограничений в файле или устройстве для удаления. 

// ---- Параметр "dwCreationDisposition".
#define  F_CREATE_NEW                   1          // Создает новый файл, если его ещё нет. Если файл есть, будет ошибка.
#define  F_CREATE_ALWAYS                2          // Создает новый файл, всегда.
#define  F_OPEN_EXISTING                3          // Открывает файл или устройство, если он существует.
#define  F_OPEN_ALWAYS                  4          // Открывает файл, всегда.
#define  F_TRUNCATE_EXISTING            5          // Открывает файл и исключает это чтобы размер - нулевые байты, только если он существует.

//==== Константы для функции "SetFilePointer()".
#define  F_FILE_BEGIN                   0          // От начала файла.
#define  F_FILE_CURRENT                 1          // От текущей позиции.
#define  F_FILE_END                     2          // От конца файла.

#define  INVALID_SET_FILE_POINTER -1
#define  INVALID_FILE_ATTRIBUTES -1
#define  INVALID_HANDLE_VALUE -1
#define  INVALID_FILE_SIZE 0xFFFFFFFF

#define  FILE_ATTRIBUTE_DIRECTORY 0x10

#define  ERROR_FILE_NOT_FOUND 2
#define  ERROR_PATH_NOT_FOUND 3

string StringFromBuffer(int& buffer[])
{
   string text = "";

   for (int pos = 11; pos < 75; pos++) 
   {
      int curr = buffer[pos];
      text = text + 
         CharToString(uchar(curr       & 0x000000FF)) +
         CharToString(uchar(curr >> 8  & 0x000000FF)) +
         CharToString(uchar(curr >> 16 & 0x000000FF)) +
         CharToString(uchar(curr >> 24 & 0x000000FF)); 
   }

   return (text);
}

int GetFileList(string path, string filter, string& list[])
{
   int Win32Data[80];
   ArrayInitialize(Win32Data, 0);

   RtlSetLastWin32Error(0);
   int hFind = FindFirstFileW(path + filter, Win32Data);
   
   if (INVALID_HANDLE_VALUE == hFind)
   {
      return (RtlGetLastWin32Error());
   }
   
   ArrayResize(list, 0);
   
   if ((Win32Data[0] & FILE_ATTRIBUTE_DIRECTORY) == 0) // if found item is file, not directory
   {
      ArrayResize(list, 1);
      list[0] = StringFromBuffer(Win32Data);
   }
   ArrayInitialize(Win32Data, 0);
   
   while (FindNextFileW(hFind, Win32Data) != 0)
   {
      if ((Win32Data[0] & FILE_ATTRIBUTE_DIRECTORY) == 0) // if found item is file, not directory
      {
         int size = ArraySize(list);
         ArrayResize(list, size + 1);
         list[size] = StringFromBuffer(Win32Data);
      }
      ArrayInitialize(Win32Data, 0);
   }
   
   FindClose(hFind);
   
   return (0);
}

int TryToCaptureFile(string fileName, int& err)
{
   RtlSetLastWin32Error(0);
   int hFile = CreateFileW(fileName, F_GENERIC_WRITE | F_GENERIC_READ, F_FILE_SHARE_NO, 0, F_OPEN_ALWAYS, 0, 0);
   err = RtlGetLastWin32Error();
   return (hFile);
}

bool CheckDirectoryExists(string path)
{
   int Win32Data[80];
   ArrayInitialize(Win32Data, 0);

   RtlSetLastWin32Error(0);
   int hFind = FindFirstFileW(path, Win32Data);

   if (INVALID_HANDLE_VALUE == hFind)
   {
      return (false);
   }

   FindClose(hFind);
   
   return ((Win32Data[0] & FILE_ATTRIBUTE_DIRECTORY) != 0); // if found item is directory
}

string LockFileName = "VolumeDataReceiver";

int hLockFile;
string ClusterDeltaPath;
string LockPath;

int UpdateIntervalSec;

int CheckLock()
{
   int err = 0;
   if (INVALID_HANDLE_VALUE != hLockFile) return (0);
   
   string path = StringSubstr(LockPath, 0, StringLen(LockPath) - 1);
   bool exists = CheckDirectoryExists(path);
   
   if (!exists)
   { // try to create if not available
      RtlSetLastWin32Error(0);
      int res = CreateDirectoryW(LockPath, 0);
      
      if (res == 0)
      {
         err = RtlGetLastWin32Error();
         if (err != 183) // ERROR_ALREADY_EXISTS
         {
            Print("Failed to create directory -- \"", LockPath, "\"");
         }
         return (err);
      }
   }
   
   if (INVALID_HANDLE_VALUE == hLockFile)
   {
      return (err);
   }
   
   return (0);
}

int OnInit()
{
   if (!MQL5InfoInteger(MQL5_DLLS_ALLOWED) ) 
   { 
      Alert("Dlls are not allowed. You should allow dll imports.");
      return (1); 
   }

   hLockFile = INVALID_HANDLE_VALUE;
   
   ClusterDeltaPath = TerminalInfoString(TERMINAL_DATA_PATH) + "\\ClusterDelta\\Volume\\";
   LockPath = TerminalInfoString(TERMINAL_DATA_PATH) + "\\ClusterDelta\\";

   if (UpdateIntervalSec < 30)
   {
      UpdateIntervalSec = 30;
   }

   int err = CheckLock();
   if (err != 0)
   {
      Alert("Failed initializing (Data Receiver already running?), error = ", err);
      return (1);
   }
   
   return (0);
}
 
TheXpert:

The code (expert) is screwing up the 64 terminal... Developers, help! #956630

Pointer must be long.
 
TheXpert:

The code (expert) is screwing up the 64 terminal... Developers, help! #956630


look in MSDN, where handles or pointers are - add versions to long

I do this.

#import "kernel32.dll"
    int   CloseHandle(int hObject);
    int   CloseHandle(long hObject);
#import 

int   CloseHandle(long hObject)
{
  if (_Is64) return(kernel32:: CloseHandle(hObject));
  else return(kernel32:: CloseHandle((int)hObject));
}

в коде
::CloseHandle(h); // где h - long типа
 
Thanks, got it. I think I looked at the pointers, but I'd forgotten about the handles. And it breaks in such a way that you can't tell what's causing it...
 
TheXpert:
The signposts seem to have been looked at
int lpOverlapped ???
Reason: