Discussion of article "Creating an assistant in manual trading"

 

New article Creating an assistant in manual trading has been published:

The number of trading robots used on the currency markets has significantly increased recently. They employ various concepts and strategies, however, none of them has yet succeeded to create a win-win sample of artificial intelligence. Therefore, many traders remain committed to manual trading. But even for such specialists, robotic assistants or, so called, trading panels, are created. This article is yet another example of creating a trading panel from scratch.

Let's take a new sheet and draw our future trading panel by placing all necessary elements on it.

When developing a design for the trading panel, it should be taken into consideration how practical is the implementation. First, the trade panel should contain sufficient information, be easily readable and not overloaded with extra elements. We should always remember that it is not just a nice image on the screen, but an essential tool for a trader.

Here is my variation.

Design

Author: Dmitriy Gizlyk

 

Similar panels have been posted on this site for a long time. There is no use compared to the standard one.

As for ideas.

1) Button of the reverse pending order behind the stop-loss.

2) One-button position reversal button.

3) Position Trall button

4) Button of Martingale reverse order

5) Take Profit button 3 to 1 or customisable.

Minimum standard set.

 
Ilya Vasenin:

Similar panels have been posted on this site for a long time. There is no use compared to the standard one.

As for ideas.

1) Button of reverse pending order behind the stop-loss.

2) One-button position reversal button.

3) Position Trall button

4) Button of Martingale reverse order

5) Take Profit button 3 to 1 or customisable.

Minimum standard set.

Yes, there are a lot of trading panels in the Marketplace. Lots of different jobs in Freelance to create trading panels as well. You, as anyone else, can use this ready-made panel for free. But this is an article, not a Marketplace product. And the purpose of the article is not to give a ready-made product to use, but to show everyone and teach those who want to learn how everyone can create their own individual trading panel, according to their own requirements.
 
The Balance and Equity of the account are displayed at the bottom of the panel, which duplicates the "Tools" tab of the terminal. I propose instead to show in this place how many deals were made for the current day, what is their result, and in the future to make it so that when the specified number of deals or the specified loss for the day is reached, the terminal will switch off.
 
Dmitriy Gizlyk:
And the purpose of this article is not to give a ready-made product for use, but to show and teach everyone how everyone can create their own individual trading panel, according to their own requirements.

Dmitry, today I started to make a panel on µl 4 according to your tutorial. Almost everything works, but when I click on the panel or any button it opens only buy. What could be the reason?

//+------------------------------------------------------------------+
//|TradePanel.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. | |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <Controls\Dialog.mqh>
#include <Controls\Label.mqh>
#include <Controls\Button.mqh>

//--- Inputs
extern double Lot        = 0.1;      // lot
extern int StopLoss      = 500;      // moose
extern int TakeProfit    = 500;      // yazi
extern int Slip          = 30;       // requotes
extern int Magic         = 0;        // magik
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
enum label_align
  {
   left=-1,
   right=1,
   center=0
  };
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
class CTradePanel : public CAppDialog
  {
private:

   CLabel            Lots_label;                      // Display label " Lots"
   CEdit             Lots;                            // Display volume of next order
   CButton           SELL,BUY;                        // Sell and Buy Buttons
   CButton           CloseAll;                        // Close buttons

   //--- Create Label object
   bool              CreateLabel(const long chart,const int subwindow,CLabel &object,const string text,const uint x,const uint y,label_align align);
   //--- Create Button
   bool              CreateButton(const long chart,const int subwindow,CButton &object,const string text,const uint x,const uint y,const uint x_size,const uint y_size);
   //--- Create Edit object
   bool              CreateEdit(const long chart,const int subwindow,CEdit &object,const string text,const uint x,const uint y,const uint x_size,const uint y_size);

   //--- On Event functions
   void              LotsEndEdit(void);               // Edit Lot size

   //--- variables of current values
   double            cur_lot;                         // Lot of next order

   void              BuyClick();                      // Click BUY button
   void              SellClick();                     // Click SELL button
   void              CloseClick();                    // Click CLOSE button 

public:
                     CTradePanel(void){};
                    ~CTradePanel(void){};
   virtual bool      Create(const long chart,const string name,const int subwin=0,const int x1=20,const int y1=20,const int x2=320,const int y2=420);
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
   virtual void      Destroy(const int reason);
  };

CTradePanel TradePanel;
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {
//---
// Create Trade Panel
   TradePanel.Create(ChartID(),"Panelka",0,20,20,150,200);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialisation function|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   TradePanel.Destroy(reason);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
bool CTradePanel::CreateLabel(const long chart,const int subwindow,CLabel &object,const string text,const uint x,const uint y,label_align align)
  {
// All objects must have separate name
   string name=m_name+"Label"+(string)ObjectsTotal(chart,-1,OBJ_LABEL);
//--- Call Create function
   if(!object.Create(chart,name,subwindow,x,y,0,0))
     {
      return false;
     }
//--- Adjust text
   if(!object.Text(text))
     {
      return false;
     }
//--- Align text to Dialog box's grid
   ObjectSetInteger(chart,object.Name(),OBJPROP_ANCHOR,(align==left ? ANCHOR_LEFT_UPPER :(align==right ? ANCHOR_RIGHT_UPPER : ANCHOR_UPPER)));
//--- Add object to controls
   if(!Add(object))
     {
      return false;
     }
   return true;
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
bool CTradePanel::CreateButton(const long chart,const int subwindow,CButton &object,const string text,const uint x,const uint y,const uint x_size,const uint y_size)
  {
// All objects must have separate name
   string name=m_name+"Button"+(string)ObjectsTotal(chart,-1,OBJ_BUTTON);
//--- Call Create function
   if(!object.Create(chart,name,subwindow,x,y,x+x_size,y+y_size))
     {
      return false;
     }
//--- Adjust text
   if(!object.Text(text))
     {
      return false;
     }
//--- set button flag to unlock
   object.Locking(false);
//--- set button flag to unpressed
   if(!object.Pressed(false))
     {
      return false;
     }
//--- Add object to controls
   if(!Add(object))
     {
      return false;
     }
   return true;
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
bool CTradePanel::CreateEdit(const long chart,const int subwindow,CEdit &object,const string text,const uint x,const uint y,const uint x_size,const uint y_size)
  {
// All objects must have separate name
   string name=m_name+"Edit"+(string)ObjectsTotal(chart,-1,OBJ_EDIT);
//--- Call Create function
   if(!object.Create(chart,name,subwindow,x,y,x+x_size,y+y_size))
     {
      return false;
     }
//--- Adjust text
   if(!object.Text(text))
     {
      return false;
     }
//--- Align text in Edit box
   if(!object.TextAlign(ALIGN_CENTER))
     {
      return false;
     }
//--- set Read only flag to false
   if(!object.ReadOnly(false))
     {
      return false;
     }
//--- Add object to controls
   if(!Add(object))
     {
      return false;
     }
   return true;
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
bool CTradePanel::Create(const long chart,const string name,const int subwin=0,const int x1=20,const int y1=20,const int x2=320,const int y2=420)
  {
// At first call create function of parents class
   CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2);

// Calculate coordinates and size of BID object

// Create object
   CreateLabel(chart,subwin,Lots_label,"LOT",55,5,0);
   CreateEdit(chart,subwin,Lots,"0.1",33,35,60,20);
   CreateButton(chart,subwin,BUY,"BUY",33,65,60,20);
   CreateButton(chart,subwin,SELL,"SELL",33,95,60,20);
   CreateButton(chart,subwin,CloseAll,"CLOSE",33,125,60,20);

   return(true);
  }
//+------------------------------------------------------------------+
//| Event Handling|
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CTradePanel)
ON_EVENT(ON_END_EDIT,Lots,LotsEndEdit)
ON_EVENT(ON_CLICK,BUY,BuyClick)
ON_EVENT(ON_CLICK,SELL,SellClick)
ON_EVENT(ON_CLICK,CloseAll,CloseClick)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Click BUY button|
//+------------------------------------------------------------------+
void CTradePanel::BuyClick(void)
  {
   PutOrder(0,Ask);
  }
//+------------------------------------------------------------------+
//| Click BUY button|
//+------------------------------------------------------------------+
void CTradePanel::SellClick(void)
  {
   PutOrder(1,Bid);
  }
//+------------------------------------------------------------------+
//| Click BUY button|
//+------------------------------------------------------------------+
void CTradePanel::CloseClick(void)
  {
   CloseAll();
  }
//+------------------------------------------------------------------+
//| Read lots value after edit|
//+------------------------------------------------------------------+
void CTradePanel::LotsEndEdit(void)
  {
//--- Read and normalize lot value
   cur_lot=NormalizeDouble(StringToDouble(Lots.Text()),2);
  }
//+------------------------------------------------------------------+
//| Application deinitialisation function |
//+------------------------------------------------------------------+
void CTradePanel::Destroy(const int reason)
  {
   CAppDialog::Destroy(reason);
   return;
  }
//+------------------------------------------------------------------+
//| Setting an order|
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
  {
   int r=0;
   color clr=Green;
   double sl=0,tp=0;

   if(type==1 || type==3 || type==5)
     {
      clr=Red;
      if(StopLoss>0)   sl=NormalizeDouble(price+StopLoss*Point,Digits);
      if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      if(StopLoss>0)   sl=NormalizeDouble(price-StopLoss*Point,Digits);
      if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
     }

   r=OrderSend(NULL,type,Lot,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//| Closing a position by order type|
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
  {
   bool cl;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0 && (ot==0 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
              }
            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   TradePanel.OnEvent(id,lparam,dparam,sparam);
  }
//+------------------------------------------------------------------+
 
Andrew Kornishkin:

Dmitry, today I started to make a panel on µl 4 according to your tutorial. Almost everything works, but when clicking on the panel or on any button it opens only buy. What could be the reason?

Good night, Andrew.
You have done everything correctly in the class description. Your only mistake is that in the OnInit function after creating the trading panel class you have not started its execution with the Run function.

int OnInit()
  {
//---
// Create Trade Panel
   TradePanel.Create(ChartID(),"Panelka",0,20,20,150,200);
   TradePanel.Run();
//---
   return(INIT_SUCCEEDED);
  }

Regards,

Dmitry.

 
Dmitriy Gizlyk:

Good night, Andrey.
You have done everything correctly in the class description. Your only mistake is that in the OnInit function after creating the trade panel class you have not started its execution with the Run function.

Regards,

Dmitry.

Thank you, Dmitry!
It worked!
 
I downloaded your trading panel to metatrader, but it doesn't work. That's too bad.
 
19681:
I downloaded your trading panel to metatrader, but it doesn't work. It's a pity.
How does it manifest itself?
For the panel to work, as well as any other trading programme, it is necessary to activate auto trading in the terminal.
 
Dmitriy Gizlyk:
What does it manifest itself in?
For the panel to work, like any other trading programme, it is necessary to activate auto-trading in the terminal.
Autotrading is of course enabled. And it manifests itself in the fact that the buttons do not work (when you click on sell or buy you get "error of open BUY ORDER").
 
19681:
Autotrading is of course enabled. And it manifests itself in the fact that the buttons do not work (when you click on sell or buy it shows "error of open BUY ORDER").
Check whether trading on the symbol is allowed at all? Due to recent events (Brexit) some brokers have temporarily restricted trading operations