//+------------------------------------------------------------------+
//|                                             @InfoTradeVisual.mq4 |
//|                                          modified by: saiful5009 |
//|                                   original copyright: Rukuki_Ake |
//+------------------------------------------------------------------+


#property copyright "Rukuki_Ake"
#property indicator_chart_window

extern int   OrderArrowType=1;
extern color BuyColor=Blue;
extern color SellColor=Red;
extern bool  DisplayPriceTag=false;
extern bool  DisplayHistoryPriceTag=false;
extern bool  DisplayExitArrow=true;
extern color ExitBuyColor=DodgerBlue;
extern color ExitSellColor=HotPink;
extern int   ExitArrowType=3;
extern bool  DisplayTradeLine=true;
extern color BuyLineColor=LightSkyBlue;
extern color SellLineColor=DeepPink;

     int iOrdersTotal = 0;
     int iOpenedOrders = 0;        // a quantity of open warrants on this tool
     int aOpenedOrderTypes[0];
  string aOpenedOrderSymbols[0];
datetime aOpenedOrderOpenTimes[0];
  double aOpenedOrderOpenPrices[0];
     int aOpenedOrderTickets[0];
  double aOpenedOrderProfits[0];
  double aOpenedOrderSwaps[0];  
  double aOpenedOrderLots[0];    
  
     int iOrdersHistoryTotal = 0;
     int iClosedOrders = 0;
     int aClosedOrderTypes[0];
  string aClosedOrderSymbols[0];
datetime aClosedOrderOpenTimes[0];
datetime aClosedOrderCloseTimes[0];
  double aClosedOrderOpenPrices[0];
  double aClosedOrderClosePrices[0];
     int aClosedOrderTickets[0];
  double aClosedOrderProfits[0];     
  double aClosedOrderSwaps[0];
  double aClosedOrderLots[0];  

  string sSymbol;


int init()  {  sSymbol = Symbol();  }
int deinit()  {  fDeleteOrderObjects ();  }



void fInitOrders(bool bAll=true)  {
    int iOrderType;
    int iCounter = 0;
    string sOrderSymbol;


    iOrdersTotal=OrdersTotal();
    if  (iOpenedOrders>0)  {
        ArrayResize(aOpenedOrderTypes,0);
        ArrayResize(aOpenedOrderSymbols,0);
        ArrayResize(aOpenedOrderOpenTimes,0);
        ArrayResize(aOpenedOrderOpenPrices,0);
        ArrayResize(aOpenedOrderTickets,0);
        ArrayResize(aOpenedOrderProfits,0);        
        ArrayResize(aOpenedOrderSwaps,0);                
        ArrayResize(aOpenedOrderLots,0);
        iOpenedOrders=0;
    }
    for(int i=0;i<iOrdersTotal;i++)
        if (OrderSelect(i,SELECT_BY_POS)==true)  {
            iOrderType=OrderType();
            sOrderSymbol=OrderSymbol();
            if (sOrderSymbol==sSymbol && (iOrderType == OP_BUY || iOrderType == OP_SELL))  {
                iOpenedOrders++;
                ArrayResize(aOpenedOrderTypes,iOpenedOrders);
                ArrayResize(aOpenedOrderSymbols,iOpenedOrders);
                ArrayResize(aOpenedOrderOpenTimes,iOpenedOrders);
                ArrayResize(aOpenedOrderOpenPrices,iOpenedOrders);
                ArrayResize(aOpenedOrderTickets,iOpenedOrders);            
                ArrayResize(aOpenedOrderProfits,iOpenedOrders);
                ArrayResize(aOpenedOrderSwaps,iOpenedOrders);                
                ArrayResize(aOpenedOrderLots,iOpenedOrders);                                
                aOpenedOrderTypes[iOpenedOrders-1]=iOrderType;
                aOpenedOrderSymbols[iOpenedOrders-1]=sOrderSymbol;
                aOpenedOrderOpenTimes[iOpenedOrders-1]=OrderOpenTime();
                aOpenedOrderOpenPrices[iOpenedOrders-1]=OrderOpenPrice();
                aOpenedOrderTickets[iOpenedOrders-1]=OrderTicket();                
                aOpenedOrderProfits[iOpenedOrders-1]=OrderProfit();
                aOpenedOrderSwaps[iOpenedOrders-1]=OrderSwap();                
                aOpenedOrderLots[iOpenedOrders-1]=OrderLots();                                
            }

        }



    /* Closed Order */
    if (bAll)  {
        iOrdersHistoryTotal=OrdersHistoryTotal();
        if  (iClosedOrders>0)  {
            ArrayResize(aClosedOrderTypes,0);
            ArrayResize(aClosedOrderSymbols,0);
            ArrayResize(aClosedOrderOpenTimes,0);
            ArrayResize(aClosedOrderCloseTimes,0);        
            ArrayResize(aClosedOrderOpenPrices,0);
            ArrayResize(aClosedOrderClosePrices,0);        
            ArrayResize(aClosedOrderTickets,0);
            ArrayResize(aClosedOrderProfits,0);        
            ArrayResize(aClosedOrderSwaps,0);
            ArrayResize(aClosedOrderLots,0);        
            iClosedOrders=0;
        }
        for(int j=0;j<iOrdersHistoryTotal;j++)
            if (OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)==true)  {
                iOrderType=OrderType();
                sOrderSymbol=OrderSymbol();
                if (sOrderSymbol==sSymbol && (iOrderType == OP_BUY || iOrderType == OP_SELL))  {
                    iClosedOrders++;
                    ArrayResize(aClosedOrderTypes,iClosedOrders);
                    ArrayResize(aClosedOrderSymbols,iClosedOrders);
                    ArrayResize(aClosedOrderOpenTimes,iClosedOrders);
                    ArrayResize(aClosedOrderCloseTimes,iClosedOrders);                
                    ArrayResize(aClosedOrderOpenPrices,iClosedOrders);
                    ArrayResize(aClosedOrderClosePrices,iClosedOrders);                
                    ArrayResize(aClosedOrderTickets,iClosedOrders);            
                    ArrayResize(aClosedOrderProfits,iClosedOrders);                            
                    ArrayResize(aClosedOrderSwaps,iClosedOrders);
                    ArrayResize(aClosedOrderLots,iClosedOrders);                
                    aClosedOrderTypes[iClosedOrders-1]=iOrderType;
                    aClosedOrderSymbols[iClosedOrders-1]=sOrderSymbol;
                    aClosedOrderOpenTimes[iClosedOrders-1]=OrderOpenTime();
                    aClosedOrderCloseTimes[iClosedOrders-1]=OrderCloseTime();                
                    aClosedOrderOpenPrices[iClosedOrders-1]=OrderOpenPrice();
                    aClosedOrderClosePrices[iClosedOrders-1]=OrderClosePrice();                
                    aClosedOrderTickets[iClosedOrders-1]=OrderTicket();                
                    aClosedOrderProfits[iClosedOrders-1]=OrderProfit();                                
                    aClosedOrderSwaps[iClosedOrders-1]=OrderSwap();
                    aClosedOrderLots[iClosedOrders-1]=OrderLots();
                
                }

            }
    }     
}



void fDrawOrders(bool bAll=true)  {
    double Spread=MarketInfo(Symbol(),MODE_SPREAD);
    for(int i=0;i<iOpenedOrders;i++)  {                          
        
        if (aOpenedOrderTypes[i] == OP_BUY)  
         {
            ObjectCreate("Buy(Open)#"+aOpenedOrderTickets[i],OBJ_ARROW,0,aOpenedOrderOpenTimes[i],aOpenedOrderOpenPrices[i]);
            ObjectSet("Buy(Open)#"+aOpenedOrderTickets[i],OBJPROP_ARROWCODE,OrderArrowType);
            ObjectSet("Buy(Open)#"+aOpenedOrderTickets[i],OBJPROP_COLOR,BuyColor);
            ObjectSetText("Buy(Open)#"+aOpenedOrderTickets[i],
                           StringConcatenate("\nBuy ",aOpenedOrderOpenPrices[i]," ", TimeToStr(aOpenedOrderOpenTimes[i],TIME_SECONDS),"\nProfit: $",
                           (MarketInfo(aOpenedOrderSymbols[i],MODE_BID)-aOpenedOrderOpenPrices[i])/
                           MarketInfo(aOpenedOrderSymbols[i],MODE_POINT)*
                           MarketInfo(aOpenedOrderSymbols[i],MODE_TICKVALUE)*aOpenedOrderLots[i]+
                           aOpenedOrderSwaps[i],"\n"));
           
            if(DisplayPriceTag)
             {
               ObjectCreate("TagBuy(Open)#"+aOpenedOrderTickets[i],OBJ_ARROW,0,aOpenedOrderOpenTimes[i],aOpenedOrderOpenPrices[i]);
               ObjectSet("TagBuy(Open)#"+aOpenedOrderTickets[i],OBJPROP_ARROWCODE,5);
               ObjectSet("TagBuy(Open)#"+aOpenedOrderTickets[i],OBJPROP_COLOR,BuyColor);              
             }

         }  
        
      else  
         {
            ObjectCreate("Sell(Open)#"+aOpenedOrderTickets[i],OBJ_ARROW,0,aOpenedOrderOpenTimes[i],aOpenedOrderOpenPrices[i]);
            ObjectSet("Sell(Open)#"+aOpenedOrderTickets[i],OBJPROP_ARROWCODE,OrderArrowType);
            ObjectSet("Sell(Open)#"+aOpenedOrderTickets[i],OBJPROP_COLOR,SellColor);
            ObjectSetText("Sell(Open)#"+aOpenedOrderTickets[i],
                           StringConcatenate("\nSell ",aOpenedOrderOpenPrices[i]," ", TimeToStr(aOpenedOrderOpenTimes[i],TIME_SECONDS),"\nProfit: $",
                           (aOpenedOrderOpenPrices[i]-MarketInfo(aOpenedOrderSymbols[i],MODE_ASK))/
                           MarketInfo(aOpenedOrderSymbols[i],MODE_POINT)*
                           MarketInfo(aOpenedOrderSymbols[i],MODE_TICKVALUE)*aOpenedOrderLots[i]+
                           aOpenedOrderSwaps[i],"\n"));              
            if(DisplayPriceTag)
             {
               ObjectCreate("TagSell(Open)#"+aOpenedOrderTickets[i],OBJ_ARROW,0,aOpenedOrderOpenTimes[i],aOpenedOrderOpenPrices[i]);
               ObjectSet("TagSell(Open)#"+aOpenedOrderTickets[i],OBJPROP_ARROWCODE,5);
               ObjectSet("TagSell(Open)#"+aOpenedOrderTickets[i],OBJPROP_COLOR,SellColor);              
             }
          }    

    }
    
    if (bAll)  {
        for(int j=0;j<iClosedOrders;j++)  {                             
                
            if (aClosedOrderTypes[j] == OP_BUY)  
             {              
               ObjectCreate("Buy(Closed)#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderOpenTimes[j],aClosedOrderOpenPrices[j]);
               ObjectSet("Buy(Closed)#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,OrderArrowType);
               ObjectSet("Buy(Closed)#"+aClosedOrderTickets[j],OBJPROP_COLOR,BuyColor);                 
               ObjectSetText("Buy(Closed)#"+aClosedOrderTickets[j],
                               StringConcatenate("\nBuy: ",DoubleToStr(aClosedOrderOpenPrices[j],Digits),"(", TimeToStr(aClosedOrderOpenTimes[j],TIME_SECONDS),")",
                               "\nExt: ", DoubleToStr(aClosedOrderClosePrices[j],Digits),"(", TimeToStr(aClosedOrderCloseTimes[j],TIME_SECONDS),")",
                               "\nProfit: $",(aClosedOrderClosePrices[j]-aClosedOrderOpenPrices[j])/MarketInfo(aClosedOrderSymbols[j],MODE_POINT)*MarketInfo(aClosedOrderSymbols[j],MODE_TICKVALUE)*aClosedOrderLots[j]+aClosedOrderSwaps[j],"\n"));                 

               if(DisplayTradeLine)
                {
                  ObjectCreate("BuyLine#"+aClosedOrderTickets[j],OBJ_TREND,0,aClosedOrderOpenTimes[j], aClosedOrderOpenPrices[j],aClosedOrderCloseTimes[j], aClosedOrderClosePrices[j]);
                  ObjectSet("BuyLine#"+aClosedOrderTickets[j],OBJPROP_STYLE,STYLE_DOT);
                  ObjectSet("BuyLine#"+aClosedOrderTickets[j],OBJPROP_WIDTH,1);
                  ObjectSet("BuyLine#"+aClosedOrderTickets[j],OBJPROP_COLOR,BuyLineColor); 
                  ObjectSet("BuyLine#"+aClosedOrderTickets[j],OBJPROP_RAY,false); 
                } 
               if(DisplayHistoryPriceTag)
                {
                  ObjectCreate("TagBuy(Closed)#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderOpenTimes[j],aClosedOrderOpenPrices[j]);
                  ObjectSet("TagBuy(Closed)#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,5);
                  ObjectSet("TagBuy(Closed)#"+aClosedOrderTickets[j],OBJPROP_COLOR,BuyColor);              
                }
              }  
              
            else  
              {
               ObjectCreate("Sell(Closed)#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderOpenTimes[j],aClosedOrderOpenPrices[j]);
               ObjectSet("Sell(Closed)#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,OrderArrowType);
               ObjectSet("Sell(Closed)#"+aClosedOrderTickets[j],OBJPROP_COLOR,SellColor);
               ObjectSetText("Sell(Closed)#"+aClosedOrderTickets[j],
                               StringConcatenate("\nSell: ",DoubleToStr(aClosedOrderOpenPrices[j],Digits),"(", TimeToStr(aClosedOrderOpenTimes[j],TIME_SECONDS),")",
                               "\nExt: ", DoubleToStr(aClosedOrderClosePrices[j],Digits),"(", TimeToStr(aClosedOrderCloseTimes[j],TIME_SECONDS),")",
                               "\nProfit: $",(aClosedOrderOpenPrices[j]-aClosedOrderClosePrices[j])/MarketInfo(aClosedOrderSymbols[j],MODE_POINT)*MarketInfo(aClosedOrderSymbols[j],MODE_TICKVALUE)*aClosedOrderLots[j]+aClosedOrderSwaps[j],"\n"));                 

               if(DisplayTradeLine)
                {
                  ObjectCreate("SellLine#"+aClosedOrderTickets[j],OBJ_TREND,0,aClosedOrderOpenTimes[j], aClosedOrderOpenPrices[j],aClosedOrderCloseTimes[j], aClosedOrderClosePrices[j]);
                  ObjectSet("SellLine#"+aClosedOrderTickets[j],OBJPROP_STYLE,STYLE_DOT);
                  ObjectSet("SellLine#"+aClosedOrderTickets[j],OBJPROP_WIDTH,1);
                  ObjectSet("SellLine#"+aClosedOrderTickets[j],OBJPROP_COLOR,SellLineColor); 
                  ObjectSet("SellLine#"+aClosedOrderTickets[j],OBJPROP_RAY,false); 
                }  
               if(DisplayHistoryPriceTag)
                {
                  ObjectCreate("TagSell(Closed)#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderOpenTimes[j],aClosedOrderOpenPrices[j]);
                  ObjectSet("TagSell(Closed)#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,5);
                  ObjectSet("TagSell(Closed)#"+aClosedOrderTickets[j],OBJPROP_COLOR,SellColor);              
                }
               }    
        

    if(DisplayExitArrow)
          {
            if (aClosedOrderTypes[j] == OP_BUY)  
             {
               ObjectCreate("ExitBuy#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderCloseTimes[j],aClosedOrderClosePrices[j]);
               ObjectSet("ExitBuy#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,ExitArrowType);
               ObjectSet("ExitBuy#"+aClosedOrderTickets[j],OBJPROP_BACK,false);                   
               ObjectSet("ExitBuy#"+aClosedOrderTickets[j],OBJPROP_COLOR,ExitBuyColor);  
               ObjectSet("ExitBuy#"+aClosedOrderTickets[j],OBJPROP_WIDTH,2); 
               ObjectSetText("ExitBuy#"+aClosedOrderTickets[j],                
                               StringConcatenate("\nBuy: ",DoubleToStr(aClosedOrderOpenPrices[j],Digits),"(", TimeToStr(aClosedOrderOpenTimes[j],TIME_SECONDS),")",
                               "\nExt: ", DoubleToStr(aClosedOrderClosePrices[j],Digits),"(", TimeToStr(aClosedOrderCloseTimes[j],TIME_SECONDS),")",
                               "\nProfit: $",(aClosedOrderClosePrices[j]-aClosedOrderOpenPrices[j])/MarketInfo(aClosedOrderSymbols[j],MODE_POINT)*MarketInfo(aClosedOrderSymbols[j],MODE_TICKVALUE)*aClosedOrderLots[j]+aClosedOrderSwaps[j],"\n"));                 
                        
               if(DisplayHistoryPriceTag)
                {
                  ObjectCreate("TagExitBuy(Closed)#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderCloseTimes[j],aClosedOrderClosePrices[j]);
                  ObjectSet("TagExitBuy(Closed)#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,5);
                  ObjectSet("TagExitBuy(Closed)#"+aClosedOrderTickets[j],OBJPROP_COLOR,ExitBuyColor);              
                }                         
              }  
              
        else if (aClosedOrderTypes[j] == OP_SELL) 
              {
               ObjectCreate("ExitSell#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderCloseTimes[j],aClosedOrderClosePrices[j]);
               ObjectSet("ExitSell#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,ExitArrowType);
               ObjectSet("ExitSell#"+aClosedOrderTickets[j],OBJPROP_BACK,false);    
               ObjectSet("ExitSell#"+aClosedOrderTickets[j],OBJPROP_COLOR,ExitSellColor);
               ObjectSet("ExitSell#"+aClosedOrderTickets[j],OBJPROP_WIDTH,2);
               ObjectSetText("ExitSell#"+aClosedOrderTickets[j],
                               StringConcatenate("\nSell: ",DoubleToStr(aClosedOrderOpenPrices[j],Digits),"(", TimeToStr(aClosedOrderOpenTimes[j],TIME_SECONDS),")",
                               "\nExt: ", DoubleToStr(aClosedOrderClosePrices[j],Digits),"(", TimeToStr(aClosedOrderCloseTimes[j],TIME_SECONDS),")",
                               "\nProfit: $",(aClosedOrderOpenPrices[j]-aClosedOrderClosePrices[j])/MarketInfo(aClosedOrderSymbols[j],MODE_POINT)*MarketInfo(aClosedOrderSymbols[j],MODE_TICKVALUE)*aClosedOrderLots[j]+aClosedOrderSwaps[j],"\n"));                 

               if(DisplayHistoryPriceTag)
                {
                  ObjectCreate("TagExitSell(Closed)#"+aClosedOrderTickets[j],OBJ_ARROW,0,aClosedOrderCloseTimes[j],aClosedOrderClosePrices[j]);
                  ObjectSet("TagExitSell(Closed)#"+aClosedOrderTickets[j],OBJPROP_ARROWCODE,5);
                  ObjectSet("TagExitSell(Closed)#"+aClosedOrderTickets[j],OBJPROP_COLOR,ExitSellColor);              
                } 

             }        
          }
        }
    }
}


void fDeleteOrderObjects (bool bAll = true)  {
    for(int i=0;i<iOpenedOrders;i++)  {
            ObjectDelete("Buy(Open)#"+aOpenedOrderTickets[i]);
            ObjectDelete("Sell(Open)#"+aOpenedOrderTickets[i]);
            ObjectDelete("TagBuy(Open)#"+aOpenedOrderTickets[i]);
            ObjectDelete("TagSell(Open)#"+aOpenedOrderTickets[i]);            
    }
    
    
    if (bAll)  {
        for(int j=0;j<iClosedOrders;j++)  {
            ObjectDelete("BuyLine#"+aClosedOrderTickets[j]);
            ObjectDelete("SellLine#"+aClosedOrderTickets[j]);
            ObjectDelete("Buy(Closed)#"+aClosedOrderTickets[j]);
            ObjectDelete("Sell(Closed)#"+aClosedOrderTickets[j]);
            ObjectDelete("ExitBuy#"+aClosedOrderTickets[j]); 
            ObjectDelete("ExitSell#"+aClosedOrderTickets[j]); 
            ObjectDelete("TagBuy(Closed)#"+aClosedOrderTickets[j]);
            ObjectDelete("TagSell(Closed)#"+aClosedOrderTickets[j]);  
            ObjectDelete("TagExitBuy(Closed)#"+aClosedOrderTickets[j]);
            ObjectDelete("TagExitSell(Closed)#"+aClosedOrderTickets[j]);                   
        }
    }    
   
}



int start()  {
        
    if(iOrdersTotal != OrdersTotal() || iOrdersHistoryTotal != OrdersHistoryTotal())  {
        fDeleteOrderObjects(true);
        fInitOrders(true);
        fDrawOrders(true);
    }  else  {
        fDeleteOrderObjects(false);
        fInitOrders(false);
        fDrawOrders(false);
    }
    
    
    return(0);
}
//+------------------------------------------------------------------+