转载: 保存为指标,直接加载就行了。 //+------------------------------------------------------------------+ //| showtradeh**.mq4 | //| st小散 liangdawen | //+------------------------------------------------------------------+ #property copyright "liangdawen" #property link "ldawen@126.com" #property indicator_chart_window string indnames = ""; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { return(0); } int deinit() { deltradesh**(); objectdelete("show trade h**tory "); objectdelete("copyright"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { /* labelcreate("ldw1",10,10,"abckmklsjfls"); arrowcreate("ldwdsf",d'2010.10.01 22:10',1.3675,"safs",red,3); arrowcreate("ld1wdsf",d'2010.10.01 20:10',1.3625,"sasfs",blue,1); arrowcreate("ld1sf",d'2010.10.01 10:10',1.3615,"sasfs",blue,4); trendlinecreate("kslsflksfsl",d'2010.10.01 22:10',1.3675,d'2010.10.01 20:10',1.3625); */ static datetime bartime = 0; if(bartime != time[0]) { bartime = time[0]; labelcreate("show trade h**tory ",10,10,"show trade h**tory"); labelcreate("copyright",25,25,"(liangdawen)"); showtrades(); } return(0); } //+------------------------------------------------------------------+ void labelcreate(string name,int x,int y,string text="-",int size=10,string font="arial",color colour=red,int window = 0) { if (objectfind(indnames+name) == -1) { objectcreate(indnames+name,obj_label,window,0,0); objectset(indnames+name,objprop_corner,1); objectset(indnames+name,objprop_xd**tance,x); objectset(indnames+name,objprop_yd**tance,y); } objectsettext(indnames+name,text,size,font,colour); } void arrowcreate(string name,datetime dt,double price,string text = "-",color colour=red,int arrowtype = 1,int window = 0) { if (objectfind(indnames+name) == -1) { objectcreate(indnames+name,obj_arrow,window,dt,price); objectset(indnames+name,objprop_arrowcode,arrowtype); objectset(indnames+name,objprop_color,colour); } } void trendlinecreate(string name,datetime dt1,double price1,datetime dt2,double price2,color colour=red,int window = 0) { if (objectfind(indnames+name) == -1) { objectcreate(indnames+name,obj_trend,window,dt1,price1,dt2,price2); objectset(indnames+name,objprop_color,colour); objectset(indnames+name,objprop_ray,false); objectset(indnames+name,objprop_style,style_dot); } } void showtrades() { int cnt; color openarrowcolor; color closearrowcolor; color stoplosscolor; color linecolor; string stype = " "; string text; int oc = ordersh**torytotal(); for(cnt=0;cnt<oc;cnt++) { if(orderselect(cnt,select_by_pos,mode_h**tory) ==false) continue; if(ordersymbol() != symbol()) continue; if( ordertype()==op_sell ) { openarrowcolor = red; closearrowcolor = violet; stoplosscolor = red; linecolor = red; } if( ordertype()==op_buy ) { openarrowcolor = blue; closearrowcolor = goldenrod; stoplosscolor = blue; linecolor = blue; } if(ordertype() == op_sell) stype = "sell"; if(ordertype() == op_buy) stype = "buy"; string ticket = doubletostr(orderticket(),0); double lots = normalizedouble(orderlots(),2); double op= normalizedouble(orderopenprice(),digits); double cp = normalizedouble(ordercloseprice(),digits); text = stringconcatenate("# ",orderticket()," ",stype," ",lots," ",ordersymbol()," at ",op," ",cp); arrowcreate("o "+text,orderopentime(),orderopenprice()," ",openarrowcolor,1); // --open arrow arrowcreate("c "+text,orderclosetime(),ordercloseprice()," ",closearrowcolor,3); // --close arrow arrowcreate("s "+text,orderopentime(),orderstoploss()," ",openarrowcolor,4); // --stop arrow trendlinecreate("l " + text ,orderopentime(),orderopenprice(),orderclosetime(),ordercloseprice(),linecolor); // trendline } // end for } //end showtrades void deltradesh**() { int cnt; string stype = " "; string text; int obj_id ; string obj_name; int oc = ordersh**torytotal(); for(cnt=0;cnt<oc;cnt++) { if(orderselect(cnt,select_by_pos,mode_h**tory) ==false) continue; if(ordersymbol() != symbol()) continue; if(ordertype() == op_sell) stype = "sell"; if(ordertype() == op_buy) stype = "buy"; string ticket = doubletostr(orderticket(),0); double lots = normalizedouble(orderlots(),2); double op= normalizedouble(orderopenprice(),digits); double cp = normalizedouble(ordercloseprice(),digits); text = stringconcatenate("# ",orderticket()," ",stype," ",lots," ",ordersymbol()," at ",op," ",cp); obj_name = "o "+text; obj_id = objectfind(obj_name); if(obj_id!=-1) objectdelete(obj_name); // --open arrow obj_name = "c "+text; obj_id = objectfind(obj_name); if(obj_id!=-1) objectdelete(obj_name); // --close arrow obj_name = "s "+text; obj_id = objectfind(obj_name); if(obj_id!=-1) objectdelete(obj_name); // --stop arrow obj_name = "l "+text; obj_id = objectfind(obj_name); if(obj_id!=-1) objectdelete(obj_name); // --trendline } // end for } //end showtrades 20210311