how to code the arrow in the EA

To add comments, please log in or register
Amnart Bunjaridh Sanit
726
Amnart Bunjaridh Sanit  

anyone can advise how to code the arrow as attached photo

Anthony Garot
1942
Anthony Garot  
Amnart Bunjaridh Sanit:

anyone can advise how to code the arrow as attached photo

The example code here to create the arrow.

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_arrow

Use Wingdings code 240 for the right arrow.

https://www.mql5.com/en/docs/constants/objectconstants/wingdings

If you want a dashed line, you can use OBJ_TREND with the OBJPROP_RAY set to false

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_trend

Keith Watford
Moderator
14469
Keith Watford  
Anthony Garot:

Use Wingdings code 240 for the right arrow.

Actually the arrow codes are 1 for opening a trade and 3 for closing

Amnart Bunjaridh Sanit
726
Amnart Bunjaridh Sanit  
Anthony Garot:

The example code here to create the arrow.

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_arrow

Use Wingdings code 240 for the right arrow.

https://www.mql5.com/en/docs/constants/objectconstants/wingdings

If you want a dashed line, you can use OBJ_TREND with the OBJPROP_RAY set to false

https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_trend

thanks bro

nicholi shen
2159
nicholi shen  

I made a class a while ago to plot trades... Maybe you can make use of it. :)


Example EA that plots history trades:

#property strict
#include <ChartObjects\ChartObjectsArrows.mqh>
#include <ChartObjects\ChartObjectsLines.mqh>
#include <Arrays\ArrayObj.mqh>

class PlotTrade : public CObject
{
   int                           m_ticket;
   CChartObjectArrow             m_in;
   CChartObjectArrow             m_out;
   CChartObjectTrend             m_line;
   static ulong                  s_count;
public:
   PlotTrade():m_ticket(-1){}
   bool create(int ticket){
      m_ticket = ticket;
      if(!OrderSelect(ticket, SELECT_BY_TICKET) || OrderType() > 1)
         return false;
      string name = "__plot_" + string(++s_count) + "_";
      int digits = (int)SymbolInfoInteger(OrderSymbol(), SYMBOL_DIGITS);
      string tooltip = StringFormat("#%d %s\n%s: %s\n%s: %s\nProfit: %s",
         ticket, OrderType() == OP_BUY ? "BUY" : "SELL",
         TimeToString(OrderOpenTime()), DoubleToString(OrderOpenPrice(), digits),
         TimeToString(OrderCloseTime()), DoubleToString(OrderClosePrice(), digits),
         DoubleToString(OrderProfit() + OrderSwap() + OrderCommission(), 2)
      );
      color line_col = OrderType() == OP_BUY ? clrDodgerBlue : clrRed;
      if(!m_in.Create(0, name + "in", 0, OrderOpenTime(), OrderOpenPrice(), 1)
         || !m_out.Create(0, name + "out", 0, OrderCloseTime(), OrderClosePrice(), 3)
         || !m_line.Create(0, name + "line", 0, 
               OrderOpenTime(), OrderOpenPrice(), 
               OrderCloseTime(), OrderClosePrice()
            )
         || !m_line.RayRight(false)
         || !m_in.Color(line_col)
         || !m_line.Color(line_col)
         || !m_line.Style(STYLE_DOT)     
         || !m_in.Tooltip(tooltip)
         || !m_out.Tooltip(tooltip)
         || !m_line.Tooltip(tooltip) 
      )
         return false;
      return true;
   }
   int ticket() const {
      return m_ticket;
   }
   virtual int Compare(const CObject *node, const int mode=0) const override {
      const PlotTrade *other = node;
      if(this.ticket() > other.ticket()) return 1;
      if(this.ticket() < other.ticket()) return -1;
      return 0;
   }
};
ulong PlotTrade::s_count = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

CArrayObj list;
int OnInit(){
   EventSetMillisecondTimer(1);
   return INIT_SUCCEEDED;
}

void OnTimer(){
   EventKillTimer();
   list.Sort();
   for(int i=OrdersHistoryTotal()-1; i>=0; --i){
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderSymbol() == _Symbol){
         PlotTrade *plot_trade = new PlotTrade();
         if(plot_trade.create(OrderTicket()) && list.Search(plot_trade) < 0)
            list.InsertSort(plot_trade);
         else
            delete plot_trade;
      }
   }
}

void OnTick(){}
To add comments, please log in or register