จากโค๊ดพวกนี้พอจะอ่านวิธีการทำงานของมันได้อย่างไรครับ
- ในโค๊ดนี้ไฟล์ .hst มีความเกี่ยวข้องและสำคัญอย่างไรครับ
- บรรทัดที่ 77
if(data[pos][1]>Open[0])
- บรรทัดที่ 87
if(data[pos][1]<Open[0])
data[pos][1] มันมีค่าอะไร มันอ่านจากอะไร ถึงได้ค่านี้ครับ
ขอความกรุณาด้วยครับ
//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//|
https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "
https://www.mql5.com"
#property version "1.00"
#property strict
#include <stderror.mqh>
#include <stdlib.mqh>
#import "kernel32.dll"
int CreateFileW(string Filename,int AccessMode,int ShareMode,int PassAsZero,int CreationMode,int FlagsAndAttributes,int AlsoPassAsZero);
int GetFileSize(int FileHandle,int PassAsZero);
int SetFilePointer(int FileHandle,int Distance,int &PassAsZero[],int FromPosition);
int ReadFile(int FileHandle,uchar &BufferPtr[],int BufferLength,int &BytesRead[],int PassAsZero);
int CloseHandle(int FileHandle);
#import
//+------------------------------------------------------------------+
//| Expert initialization function |
input double SL=500;
input double TP=70;
//+------------------------------------------------------------------+
union Price
{
uchar buffer[8];
double close;
};
double data[][2];
int BytesToRead;
string datapath;
string result_2;
Price m_price;
double g_Point;
int OnInit()
{
//---
ChartSetInteger(0,17,0,0);
ChartSetInteger(0,0,1);
string account_server=AccountInfoString(3);
if(account_server=="")
{
account_server="default";
}
datapath=TerminalInfoString(3)+"\\history\\"
+account_server+"\\"+Symbol()+"240"+".hst";
ReadFileHst(datapath);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
int pos = -1 ;
for(int i = 0 ; i < BytesToRead - 1 ; i++)
{
if(!(data
- <Time[0]))
break;
pos = i + 1;
}
if(data[pos][1]>Open[0])
{
double BuySL=NormalizeDouble(Ask - SL*g_Point,Digits);
double BuyTP=NormalizeDouble(Ask + TP*g_Point,Digits);
if(AccountFreeMarginCheck(Symbol(),OP_BUY,0.01)>0)
{
int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,0,BuySL,BuyTP,"",0,0,clrGreen);
}
}
if(data[pos][1]<Open[0])
{
double SellSL=NormalizeDouble(Bid + SL*g_Point,Digits);
double SellTP=NormalizeDouble(Bid - TP*g_Point,Digits);
if(AccountFreeMarginCheck(Symbol(),OP_SELL,0.01)>0)
{
int ticket=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,SellSL,SellTP,"",0,0,clrGreen);
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void ReadFileHst(string FileName)
{
int j=0;;
string strFileContents;
int Handle;
int LogFileSize;
int movehigh[1]= {0};
uchar buffer[];
int nNumberOfBytesToRead;
int read[1]= {0};
int i;
double mm;
//----- -----
strFileContents="";
Handle=CreateFileW(FileName,(int)0x80000000,3,0,3,0,0);
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
if(Handle==-1)
{
Comment("");
return;
}
LogFileSize=GetFileSize(Handle,0);
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
if(LogFileSize<=0)
{
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
if((LogFileSize-148)/60==BytesToRead)
{
return;
}
SetFilePointer(Handle,148,movehigh,0);
BytesToRead=(LogFileSize-148)/60;
ArrayResize(data,BytesToRead,0);
nNumberOfBytesToRead=60;
ArrayResize(buffer,60,0);
for(i=0; i<BytesToRead; i=i+1)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
{
ReadFile(Handle,buffer,nNumberOfBytesToRead,read,NULL);
if(read[0]==nNumberOfBytesToRead)
{
result_2=StringFormat("0x%02x%02x%02x%02x%02x%02x%02x%02x",buffer[7],buffer[6],buffer[5],buffer[4],buffer[3],buffer[2],buffer[1],buffer[0]);
m_price.buffer[0] = buffer[32];
m_price.buffer[1] = buffer[33];
m_price.buffer[2] = buffer[34];
m_price.buffer[3] = buffer[35];
m_price.buffer[4] = buffer[36];
m_price.buffer[5] = buffer[37];
m_price.buffer[6] = buffer[38];
m_price.buffer[7] = buffer[39];
mm=m_price.close;
data[j][0] = StringToDouble(result_2);
data[j][1] = mm;
j=j+1;
strFileContents=TimeToString(StringToTime(result_2),3)+" "+DoubleToString(mm,8);
}
else
{
CloseHandle(Handle);
return;
}
}
CloseHandle(Handle);
strFileContents=DoubleToString(data[j-1][0],3)+" "+DoubleToString(data[j-1][1],8)+" "+DoubleToString(data[j-2][1],3)+" "+DoubleToString(data[j-2][1],8);
result_2=strFileContents;
}
//ReadFileHst <<==-------- --------