//+------------------------------------------------------------------+ //| Profit Calculator.mq5 | //| Copyright © 2018, Amr Ali | //| https://www.mql5.com/en/users/amrali | //+------------------------------------------------------------------+ #define VERSION "2.85" #property copyright "Copyright © 2018, Amr Ali" #property link "https://www.mql5.com/en/users/amrali" #property version VERSION #property description "Calculate the profit or risk money for a trade." //+------------------------------------------------------------------+ #include #include #include #include #include #include #include #include #include #include "SpinEditDouble.mqh" #include "Functions.mqh" //+------------------------------------------------------------------+ //| defines | //+------------------------------------------------------------------+ //--- indents and gaps #define INDENT_LEFT (11) // indent from left (with allowance for border width) #define INDENT_TOP (11) // indent from top (with allowance for border width) #define CONTROLS_GAP_X (20) // gap by X coordinate #define CONTROLS_GAP_Y (10) // gap by Y coordinate //--- for buttons #define BUTTON_WIDTH (240) // size by X coordinate #define BUTTON_HEIGHT (27) // size by Y coordinate //--- for the indication area #define EDIT_WIDTH (110) // size by X coordinate #define EDIT_HEIGHT (27) // size by Y coordinate #define LABEL_HEIGHT (10) // size by Y coordinate //+------------------------------------------------------------------+ //| Class CControlsDialog | //| Usage: main dialog of the Controls application | //+------------------------------------------------------------------+ class CControlsDialog : public CAppDialog { private: CLabel m_lbl_symbol; CLabel m_lbl_ordertype; CLabel m_lbl_volume; CLabel m_lbl_currency; CLabel m_lbl_days; CLabel m_lbl_open_price; CLabel m_lbl_close_price; CLabel m_lbl_profit_pts; CLabel m_lbl_profit; CLabel m_lbl_swap; CComboBox m_symbol; // the dropdown list object CComboBox m_ordertype; // the dropdown list object CSpinEditDouble m_volume; // the display field object CSpinEditDouble m_days; // the display field object CSpinEditDouble m_open_price; // the display field object CSpinEditDouble m_close_price; // the display field object CCheckBox m_use_points; CEdit m_currency; // the display field object CEdit m_profit; // the display field object CEdit m_swap; // the display field object CButton m_calculate; // the button object CAccountInfo m_account; CSymbolInfo m_sym; int m_font_size; // object font size public: CControlsDialog(void); ~CControlsDialog(void); //--- create virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); //--- chart event handler virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); protected: //--- create dependent controls bool CreateControlSymbol(void); bool CreateControlVolume(void); bool CreateControlCurrency(void); bool CreateControlHoldingDays(void); bool CreateControlOpenPrice(void); bool CreateControlClosePrice(void); bool CreateControlOrderType(void); bool CreateControlUsePoints(void); bool CreateControlCalculate(void); bool CreateControlProfit(void); bool CreateControlSwap(void); //--- handlers of the dependent controls events virtual void OnClickButtonClose(void); void OnChangeComboSymbol(void); void OnChangeOrderType(void); void OnChangeChkUsePoints(void); void OnClickButtonCalculate(void); }; //+------------------------------------------------------------------+ //| Event Handling | //+------------------------------------------------------------------+ EVENT_MAP_BEGIN(CControlsDialog) ON_EVENT(ON_CHANGE,m_symbol,OnChangeComboSymbol) ON_EVENT(ON_CHANGE,m_ordertype,OnChangeOrderType) ON_EVENT(ON_CHANGE,m_use_points,OnChangeChkUsePoints) ON_EVENT(ON_CLICK,m_calculate,OnClickButtonCalculate) EVENT_MAP_END(CAppDialog) //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CControlsDialog::CControlsDialog(void) { m_sym.Name(Symbol()); } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CControlsDialog::~CControlsDialog(void) { } //+------------------------------------------------------------------+ //| Create | //+------------------------------------------------------------------+ bool CControlsDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) { if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2)) return(false); //--- scale controls font size to screen dpi double screen_dpi=(double)TerminalInfoInteger(TERMINAL_SCREEN_DPI); m_font_size=(int)MathRound(CONTROLS_FONT_SIZE * 96.0 / screen_dpi); //--- create dependent controls if(!CreateControlSymbol()) return(false); if(!CreateControlVolume()) return(false); if(!CreateControlCurrency()) return(false); if(!CreateControlHoldingDays()) return(false); if(!CreateControlOpenPrice()) return(false); if(!CreateControlClosePrice()) return(false); if(!CreateControlOrderType()) return(false); if(!CreateControlUsePoints()) return(false); if(!CreateControlCalculate()) return(false); if(!CreateControlProfit()) return(false); if(!CreateControlSwap()) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create the "m_symbol" combo box | //+------------------------------------------------------------------+ bool CControlsDialog::CreateControlSymbol(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP; int x2=x1+EDIT_WIDTH; int y2=y1+EDIT_HEIGHT; //--- create if(!m_lbl_symbol.Create(m_chart_id,m_name+"m_lbl_symbol",m_subwin,x1,y1,x2,y2)) return(false); if(!m_lbl_symbol.Text("Symbol:")) return(false); if(!m_lbl_symbol.FontSize(m_font_size)) return(false); if(!Add(m_lbl_symbol)) return(false); //--- coordinates y1=y1+(LABEL_HEIGHT+CONTROLS_GAP_Y); y2=y1+EDIT_HEIGHT; //--- create if(!m_symbol.Create(m_chart_id,m_name+"m_symbol",m_subwin,x1,y1,x2,y2)) return(false); if(!Add(m_symbol)) return(false); //--- fill out with market watch symbols int total=SymbolsTotal(true); CArrayString array; array.Sort(); for(int i=0; i