用 OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); 取出歷史單
多谢你的回复。
我对OrderSelcet有点儿疑问。我觉得中文参考翻译的和英文的有差别
bool OrderSelect( | int index, int select, int pool=MODE_TRADES) |
index | - | Order index or order ticket depending on the second parameter. |
select | - | Selecting flags. It can be any of the following values: SELECT_BY_POS - index in the order pool, SELECT_BY_TICKET - index is order ticket. |
pool | - | Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values: MODE_TRADES (default)- order selected from trading pool(opened and pending orders), MODE_HISTORY - order selected from history pool (closed and canceled order). |
index 中的 Order index 和 order ticket 有何区别。中文参考书只是说定单索引。
selcet 中 order pool,order ticek 的区别?
请赐教。
大家好,有个问题想请教。
我编了一个ea,想在每次交易后,把交易的结果输入一个文件内,以后好进行分析。
思想是这样的:判断上次交易是盈利还是损失,对盈利时的一些条件的信息写入文件内。
先弄了一个最简单的:如果上一次交易是盈利输出盈利值。
我用了orderselcet(),和orderprofit(),这两个函数。但这两个函数使用时需要指定订单号 ticket,
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,30,Ask-StopLoss*Point,Ask+TakeProfit*Point,"NEW",16384,0,Green);
我将每次交易的ticket传给全局变量TICKET,在下一次执行ea时再利用orderselcet(),和orderprofit(),读出上次交易情况。
估计ticket的值在缓存里已经没有了,所以无法读出之前的交易,只能读出最后的一次交易。
请问,怎么做能做到我想的这个功能,多谢!
顺便,将数据写入文件时,如何换行, 加空格?
以下是我写的部分代码:
start()
{…………
if(TICKET>0) //在上次交易成功时已将ticke传给了全局变量TICKET
{//1
if(OrderSelect(TICKET,SELECT_BY_TICKET)==true) // 选择上次交易
{//2
profit=OrderProfit(); //将盈亏传给profit
if(profit>0) //如果是盈利
{//3
st1= "TICKET"+TICKET+":"+profit+";"; //
NP=NP+1; //NP(全局变量) 初始值为0,用来记录盈利的次数
if((NP-NPCom)==1) //NPCom(全局变量) 初始值为0,写入文件成功后将NP值传给NPCom,以用来下次和NP比较,如果差等于1说明有新赢利
{//4
hFile = FileOpen(FileName, FILE_WRITE|FILE_CSV, ';');
FileSeek(hFile, 0, SEEK_END);
if(NP==1)
{//5
st = "TP;"; FileWrite(hFile, st);FileWrite(hFile,st1);
}//5
else FileWrite(hFile,st1);
FileClose(hFile);
NPCom=NP;
}//4
}//3
} //2
}//1
…………
}