//+------------------------------------------------------------------+ //| smSHow HistoryOrders.mq4 | //+------------------------------------------------------------------+ #property copyright "Copyright 03.03.2017, SwingMan" #property link "" #property strict #property indicator_chart_window bool calculationDone=false; //---- constants int iOpenArrow=1; int iExitArrow=3; //---- variables int orderType; //datetime thisTime,oldTime; //bool newBar; datetime orderOpenTime,orderCloseTime; double orderOpenPrice,orderClosePrice; //datetime orderThisTime; //double orderStopLoss; double lots; double orderTakeProfit; // //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { calculationDone=false; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int ticket=0; if(calculationDone==true) return(0); //--- ################################################################# int ordersHistTotal=OrdersHistoryTotal(); if(ordersHistTotal==0) return(0); for(int cnt=ordersHistTotal-1;cnt>=0;cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true) { if(OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL)) { ticket=OrderTicket(); Check_ExistingTicketArrows(ticket); } } } //--- ################################################################# //--- calculationDone=true; return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Check_ExistingTicketArrows(int iTicket) { // string sTicket=(string)iTicket; // int nObjects=ObjectsTotal(); // ////-- check ticket // for(int io=nObjects;io>=0;io--) // { // string objName=ObjectName(io); // // bool bIsPendingOrder=(StringFind(objName,"limit",0)>=0) || (StringFind(objName,"modified",0)>=0); // if(StringFind(objName,sTicket,0)>=0 && bIsPendingOrder==false) // { // Check_SopLossValues(iTicket); // return; // } // } //-- draw arrows for a new order //if(OrderSelect(iTicket,SELECT_BY_TICKET,MODE_TRADES)==true) // { Get_OrderData(iTicket); Draw_OpenArrow(iTicket); if(orderClosePrice>0) { Draw_StopLossArrow(iTicket); Draw_OpenStopLine(iTicket); } //} } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Get_OrderData(int ticket) { orderClosePrice=0; if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY)==true) { orderType=OrderType(); orderOpenTime =OrderOpenTime(); orderOpenPrice=OrderOpenPrice(); orderCloseTime =OrderCloseTime(); orderClosePrice=OrderClosePrice(); //orderThisTime=iTime(Symbol(),Period(),0); //orderStopLoss=OrderStopLoss(); lots=OrderLots(); orderTakeProfit=OrderTakeProfit()+OrderCommission(); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Draw_OpenArrow(int ticket) { int chartID=0; string sOrderType=""; color cColor=0; if(orderType==OP_BUY) { sOrderType=" buy "; cColor=clrDodgerBlue; //## BUY } else if(orderType==OP_SELL) { sOrderType=" sell "; //## SELL cColor=clrRed; } string sObjName="#"+(string)ticket+sOrderType+DoubleToString(lots,2)+" "+Symbol()+" at "+DoubleToString(orderOpenPrice,Digits); if(ObjectFind(chartID,sObjName)>=0) return; ObjectCreate(chartID,sObjName,OBJ_ARROW,0,orderOpenTime,orderOpenPrice); ObjectSetInteger(chartID,sObjName,OBJPROP_COLOR,cColor); ObjectSetInteger(chartID,sObjName,OBJPROP_ARROWCODE,iOpenArrow); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Draw_StopLossArrow(int ticket) { int chartID=0; string sOrderType=""; color cColor=clrGoldenrod; //## EXIT if(orderType==OP_BUY) { sOrderType=" buy "; } else if(orderType==OP_SELL) { sOrderType=" sell "; } string sObjName="#"+(string)ticket+sOrderType+DoubleToString(lots,2)+" "+Symbol()+" at "+DoubleToString(orderOpenPrice,Digits)+ " close at "+DoubleToString(orderClosePrice,Digits); if(ObjectFind(chartID,sObjName)>=0) return; ObjectCreate(chartID,sObjName,OBJ_ARROW,0,orderCloseTime,orderClosePrice); ObjectSetInteger(chartID,sObjName,OBJPROP_COLOR,cColor); ObjectSetInteger(chartID,sObjName,OBJPROP_ARROWCODE,iExitArrow); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Draw_OpenStopLine(int ticket) { int chartID=0; string sOrderType=""; color cColor=0; if(orderTakeProfit>=0) cColor=clrGreen; else cColor=clrRed; //if(orderType==OP_BUY) // { // if(orderStopLoss>=orderOpenPrice) // cColor=clrGreen; // else // cColor=clrRed; // } //else //if(orderType==OP_SELL) // { // if(orderStopLoss<=orderOpenPrice) // cColor=clrGreen; // else // cColor=clrRed; // } string sObjName="#"+(string)ticket+" "+DoubleToString(orderOpenPrice,Digits)+" -> "+DoubleToString(orderClosePrice,Digits); if(ObjectFind(chartID,sObjName)>=0) return; ObjectCreate(chartID,sObjName,OBJ_TREND,0,orderOpenTime,orderOpenPrice,orderCloseTime,orderClosePrice); ObjectSetInteger(chartID,sObjName,OBJPROP_COLOR,cColor); ObjectSetInteger(chartID,sObjName,OBJPROP_STYLE,STYLE_DOT); ObjectSet(sObjName,OBJPROP_RAY,false); } //+------------------------------------------------------------------+