|
本来是显示交易记录的脚本,附加了可以搜索一个CSV文件,将其中的比如"长期",”中期”列中的单子,单独画出来的功能。 以防多周期的定单同图显示,看起来混乱(不能处理挂单)
- #property show_confirm
- extern string 显示周期="中期";
- string 临时数组[1000]; //作为全局变量--非常不规范
- //---------------
- int SignalBS =0; //1代表多头,-1代表空头
- datetime startTime=NULL, endTime = NULL;
- color SignalPriceBUY = OrangeRed;//Yellow;
- color SignalPriceSELL = DeepSkyBlue;//Cyan;//起点的标签
- double startPrice, endprice;
- int ticket;
- //-------------------
- int start()
- {
- //画图有关变量
- int orders=HistoryTotal();
- int i;
- //文件有关变量
- int Handle;
- string File_Name="EURUSD交易记录.csv";
- string 超长期[1000],长期[1000],中期[1000],短期[1000],超短期[1000],其他[1000];//默认设置1000条记录--非常不规范
- int ArrayIndex=0;
- //纠错代码(抄写)
- Handle=FileOpen(File_Name,FILE_CSV|FILE_READ,",");// File opening
- if(Handle<0) // File opening fails
- {
- if(GetLastError()==4103) // If the file does not exist,..
- Alert("No file named ",File_Name);//.. inform trader
- else // If any other error occurs..
- Alert("Error while opening file ",File_Name);//..this message
- return; // Exit start()
- }
- //读取文件内容到数组
- while(FileIsEnding(Handle)==false) // While the file pointer..
- { // ..is not at the end of the file
- 超长期[ArrayIndex] = FileReadString(Handle);
- 长期[ArrayIndex] = FileReadString(Handle);
- 中期[ArrayIndex] = FileReadString(Handle);
- 短期[ArrayIndex] = FileReadString(Handle);
- 超短期[ArrayIndex] = FileReadString(Handle);
- 其他[ArrayIndex] = FileReadString(Handle);
- ArrayIndex++; //数字从索引1开始,0是中文,这部分无关紧要
- if(FileIsEnding(Handle)==true) // File pointer is at the end
- break; // Exit reading and drawing
- }
- //确定使用哪个周期的数组,复制到临时数组
- if(显示周期=="超长期") ArrayCopy(临时数组,超长期,0,0,WHOLE_ARRAY); //使用复制数组的方式--效率极低
- else if(显示周期=="长期")ArrayCopy(临时数组,长期,0,0,WHOLE_ARRAY);
- else if(显示周期=="中期")ArrayCopy(临时数组,中期,0,0,WHOLE_ARRAY);
- else if(显示周期=="短期")ArrayCopy(临时数组,短期,0,0,WHOLE_ARRAY);
- else if(显示周期=="超短期")ArrayCopy(临时数组,超短期,0,0,WHOLE_ARRAY);
- else if(显示周期=="其他")ArrayCopy(临时数组,其他,0,0,WHOLE_ARRAY);
- //定单画图有关代码
- for(i=orders-1;i>=0;i--)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
- {
- ticket=OrderTicket();
- if(OrderType( )==OP_BUY && OrderSymbol()==Symbol() && IfStringInTheArray(DoubleToStr(ticket,0)))//画出当前货币的历史多单 //订单号转换成字符串格式判断
- {
- SignalBS =1;
- startTime= OrderOpenTime();endTime = OrderCloseTime ();
- startPrice= OrderOpenPrice(); endprice = OrderClosePrice ();
- SetBS(); //开始画
- }
- else if (OrderType( )==OP_SELL && OrderSymbol()==Symbol() && IfStringInTheArray(DoubleToStr(ticket,0)))//画出当前货币的历史空单
- {
- SignalBS =-1;
- startTime= OrderOpenTime();endTime = OrderCloseTime ();
- startPrice= OrderOpenPrice(); endprice = OrderClosePrice ();
- SetBS();
- }
- }
- }
- //----
- //关闭文件
- FileClose( Handle ); // Close file
- return(0);
- }
- //+------------------------------------------------------------------+
- void SetBS() //画
- {
- int BarShift=WindowBarsPerChart()/50;
- datetime TimeShift=WindowBarsPerChart()/50*Period()*60;
- if (SignalBS == 1)//做多
- {
- ObjectDelete("BUY SIGNAL: " + TimeToStr(startTime));
- ObjectDelete("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(endTime));
- ObjectDelete("BUY Close: " + TimeToStr(endTime));
- //删除价格标签
- //ObjectCreate("BUY SIGNAL: " + TimeToStr(startTime),OBJ_ARROW,0,startTime,startPrice);
- //ObjectSet("BUY SIGNAL: " + TimeToStr(startTime),OBJPROP_ARROWCODE,5);
- //ObjectSet("BUY SIGNAL: " + TimeToStr(startTime),OBJPROP_COLOR,SignalPriceBUY);
- //换成文本框
- //ObjectCreate("BUY SIGNAL: " + TimeToStr(startTime),OBJ_TEXT,0,startTime-TimeShift,startPrice);
- //ObjectSetText("BUY SIGNAL: " + TimeToStr(startTime),DoubleToStr(startPrice,4), 9, "Arial", SignalPriceBUY);
- //ObjectSet("BUY SIGNAL: " + TimeToStr(startTime),OBJPROP_COLOR,SignalPriceBUY);
- ObjectCreate("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJ_TREND,0,startTime,startPrice,endTime,endprice);
- ObjectSet("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_COLOR,SignalPriceBUY);
- ObjectSet("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_RAY,false);
- ObjectSet("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_STYLE,STYLE_SOLID);
- ObjectSet("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_COLOR,SignalPriceBUY);
- ObjectSet("BUY : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_WIDTH,3);//变粗
- //删除价格标签
- //ObjectCreate("BUY Close: " + TimeToStr(endTime),OBJ_ARROW,0,endTime,endprice);
- //ObjectSet("BUY Close: " + TimeToStr(endTime),OBJPROP_ARROWCODE,5);
- //ObjectSet("BUY Close: " + TimeToStr(endTime),OBJPROP_COLOR,SignalPriceBUY);
- //换成文本框
- //ObjectCreate("BUY Close: " + TimeToStr(endTime),OBJ_TEXT,0,endTime-TimeShift,endprice);
- //ObjectSetText("BUY Close: " + TimeToStr(endTime),DoubleToStr(endprice,4), 9, "Arial", SignalPriceBUY);
- //ObjectSet("BUY Close: " + TimeToStr(endTime),OBJPROP_COLOR,SignalPriceBUY);
- }
- if (SignalBS == -1)//做空
- {
- ObjectDelete("SELL SIGNAL: " + TimeToStr(startTime));
- ObjectDelete("SELL : " + TimeToStr(endTime));
- ObjectDelete("SELL Close: " + TimeToStr(endTime));
- //删除价格标签
- //ObjectCreate("SELL SIGNAL: " + TimeToStr(startTime),OBJ_ARROW,0,startTime,startPrice);
- //ObjectSet("SELL SIGNAL: " + TimeToStr(startTime),OBJPROP_ARROWCODE,5);
- //ObjectSet("SELL SIGNAL: " + TimeToStr(startTime),OBJPROP_COLOR,SignalPriceSELL);
- //换成文本框(暂时也删除文本框)
- //ObjectCreate("SELL SIGNAL: " + TimeToStr(startTime),OBJ_TEXT,0,startTime-TimeShift,startPrice);
- //ObjectSetText("SELL SIGNAL: " + TimeToStr(startTime),DoubleToStr(startPrice,4), 9, "Arial", SignalPriceSELL);
- //ObjectSet("SELL SIGNAL: " + TimeToStr(startTime),OBJPROP_COLOR,SignalPriceSELL);
- ObjectCreate("SELL : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJ_TREND,0,startTime,startPrice,endTime,endprice);
- ObjectSet("SELL : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_COLOR,SignalPriceSELL);
- ObjectSet("SELL : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_RAY,false);
- ObjectSet("SELL : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_STYLE,STYLE_SOLID);
- ObjectSet("SELL : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_COLOR,SignalPriceSELL);
- ObjectSet("SELL : "+ DoubleToStr(ticket,0)+": " + TimeToStr(startTime)+"--"+TimeToStr(endTime),OBJPROP_WIDTH,3);//变粗
- //删除价格标签
- //ObjectCreate("SELL Close: " + TimeToStr(endTime),OBJ_ARROW,0,endTime,endprice);
- //ObjectSet("SELL Close: " + TimeToStr(endTime),OBJPROP_ARROWCODE,5);
- //ObjectSet("SELL Close: " + TimeToStr(endTime),OBJPROP_COLOR,SignalPriceSELL);
- //换成文本框(暂时也删除文本框)
- //ObjectCreate("SELL Close: " + TimeToStr(endTime),OBJ_TEXT,0,endTime-TimeShift,endprice);
- //ObjectSetText("SELL Close: " + TimeToStr(endTime),DoubleToStr(endprice,4), 9, "Arial", SignalPriceSELL);
- //ObjectSet("SELL Close: " + TimeToStr(endTime),OBJPROP_COLOR,SignalPriceSELL);
- }
- }
- int IfStringInTheArray(string TicketString){ //判断数组内是否存在制定的定单号
- int ArraySizeNumber=ArraySize(临时数组);
- int i;
- for(i=0;i<=ArraySizeNumber;i++){ //每一个定单都要搜索一遍全部数组--效率极低
- if(TicketString==临时数组[i]){
- return (1);
- }
- }
- return (0);
- }
复制代码
|
|