好的,你需要
1.从代理接收源(希望您成功)
2.第二步。把它写进一个文件
**(两者都是-python)**
三。阅读并分析它
第四章。添加到历史中心/市场观察
**(两者均为-MT5)**
-
所以,在
I_want_money.get_candles(goal,60,111,time.time())
这个字符串可以是JSON或JSON数组。
-
重要的问题当然是您要放置数据的路径。mql45中的专家只能访问两个文件夹(如果不应用dll):
C:\users\my_name_is_daniel_kniaz\appdata\roaming\metaquotes\terminal\my_terminal_id_in_hex_format\mql4\files
和
C:\users\my_name_是\u daniel_kniaz\appdata\roaming\metaquotes\terminal\common\files
在后一种情况下,需要打开一个const int handle=file open的文件(
,请
|*|文件通用);
为了解析JSON,可以使用jason.mqh
https://www.mql5.com/en/code/13663
库(其他库很少),但据我所知,它有一个缺陷:它不能正确解析对象数组。为了克服这一点,我建议把每一个记号都写在一行上。
最后,您将随机从Python应用程序接收数据,并将其写入公共或直接文件夹。MT5机器人将读取并删除。为了避免混淆,最好确保文件具有唯一的名称。从datetime中随机(random.randint(11000))或毫秒都有帮助。
到目前为止,您有python代码:
receivedString = I_want_money.get_candles(goal,60,111,time.time())
filePath = 'C:\Users\MY_NAME_IS_DANIEL_KNIAZ\AppData\Roaming\MetaQuotes\Terminal\MY_TERMINAL_ID_IN_HEX_FORMAT\MQL4\Files\iqoptionfeed'
fileName = os.path.join(filePath,"_"+goal+"_"+str(datetime.now())+".txt")
file = open(fileName, "w")
for string_ in receivedString:
file.write(string_)
file.close()
如果您创建了一个线程,那么每次您从该线程收到答案时,都会编写这样的文件。
接下来,您需要MT5中的数据。
最简单的方法是循环访问现有文件,确保可以读取它们并读取(如果无法读取,则放弃)并在读取后删除,然后继续处理接收到的数据。
当然,最简单和更快的方法是使用0MQ,但是让我们不使用DLL。
为了读取文件,您需要设置一个计时器,使其尽可能快地工作,然后让它继续工作。由于不能使Windows应用程序睡眠时间少于15.6ms,因此计时器应睡眠此时间。
string path;
int OnInit()
{
EventSetMillisecondTimer(16);
path="iqoptionfeed\\*";
}
void OnDeinit(const int reason) { EventKillTimer(); }
string _fileName;
long _search_handle;
void OnTimer()
{
_search_handle=FileFindFirst(path,_fileName);
if(_search_handle!=INVALID_HANDLE)
{
do
{
ResetLastError();
FileIsExist(_fileName);
if(GetLastError()!=ERR_FILE_IS_DIRECTORY)
processFile(path+_fileName);
}
while(FileFindNext(_search_handle,_fileName));
FileFindClose(_search_handle);
}
}
这段代码循环文件夹并处理它设法找到的每个文件。
现在读取文件(两个函数)并处理其中的消息:
void processFile(const string fileName)
{
string message;
if(ReadFile(fileName,message))
processMessage(message,fileName);
}
bool ReadFile(const string fileName,string &result,const bool common=false)
{
const int handle = FileOpen(fileName,common?(FILE_COMMON|FILE_READ):FILE_READ);
if(handle==INVALID_HANDLE)
{
printf("%i - failed to find file %s (probably doesnt exist!). error=%d",__LINE__,fileName,GetLastError());
return(false);
}
Read(handle,result);
FileClose(handle);
if(!FileDelete(fileName,common?FILE_COMMON:0))
printf("%i - failed to delete file %s/%d. error=%d",__LINE__,fileName,common,GetLastError());
return(true);
}
void Read(const int handle,string &message)
{
string text="";
while(!FileIsEnding(handle) && !IsStopped())
{
text=StringConcatenate(text,FileReadString(handle),"\n");
}
//printf("%i %s - %s.",__LINE__,__FUNCTION__,text);
message=text;
}
最后但不是最不重要的:处理获得的文件。
正如上面所建议的,它为每个新标记都有一个JSON格式的标记,用\r\n分隔。
我们的目标是将其添加到符号中。为了解析JSON,jason.mqh是一个可用的解决方案,但是您当然可以手动解析它。
void processMessage(const string message,const string fileName)
{
string symbolName=getSymbolFromFileName(fileName);
if(!SymbolSelect(symbolName,true))
{
if(!CustomSymbolCreate(symbolName))
return;
}
string lines[];
int size=StringSplit(message,(ushort)'\n',lines);
for(int i=0;i<size;i++)
{
if(StringLen(lines[i])==0)
continue;
CJAVal jLine(jtUNDEF,NULL);
jLine.Deserialize(lines[i]);
MqlTick mql;
//here I assume that you receive a json file like " { "time":2147483647,"bid":1.16896,"ask":1.16906,"some_other_data":"someOtherDataThatYouMayAlsoUse" } "
mql.time=(datetime)jLine["time"].ToInt();
mql.bid=(double)jLine["bid"].ToDbl();
mql.ask=(double)jLine["ask"].ToDbl();
ResetLastError();
if(CustomTicksAdd(symbolName,mql)<0)
printf("%i %s - failed to upload tick: %s %s %.5f %.5f. error=%d",__LINE__,__FILE__,symbolName,TimeToString(mql.time),mql.bid,mql.ask,GetLastError());
}
}
string getSymbolFromFileName(const string fileName)
{
string elements[];
int size=StringSplit(fileName,(ushort)'_',elements);
if(size<2)
return NULL;
return elements[1];
}
不要忘记添加调试信息和请求
GetLastError()
因为某种原因你会出错。
这能在背部测试仪中工作吗?当然不是。拳头,
OnTimer()
在MQL测试仪中不支持。接下来,您需要一些历史记录才能使其运行。如果你没有任何历史-没有人可以帮助你,除非经纪人能给你;最好的办法是现在就开始收集和存储它,当项目准备好(可能再过几个月)时,你就可以准备好它,并且能够用AV测试和优化策略。可用数据集。您可以将收集的集合应用到测试仪中(与mql4相比,mql5实际上是Algo Trading开发的下一步),可以手动执行,也可以使用诸如TickDataSuite及其csv2fxt.ex4文件之类的文件来生成测试仪可以读取和处理的hst二进制文件;总之,这是另一个问题D没有人能告诉你你的经纪人是否把他们的数据存储在某个地方提供给你。