//+------------------------------------------------------------------+ //| SymbolSynthesizerDialog.mqh | //| Copyright 2011, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #include #include #include #include #include #include #include #include #include #include #include //+------------------------------------------------------------------+ //| 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 INDENT_RIGHT (11) // indent from right (with allowance for border width) #define INDENT_BOTTOM (11) // indent from bottom (with allowance for border width) #define CONTROLS_GAP_X (15) // gap by X coordinate #define CONTROLS_GAP_Y (5) // gap by Y coordinate //--- for labels #define LABEL_WIDTH (100) // size by X coordinate //--- for buttons #define BUTTON_WIDTH (125) // size by X coordinate #define BUTTON_HEIGHT (20) // size by Y coordinate //--- for the indication area #define EDIT_HEIGHT (20) // size by Y coordinate //--- for group controls #define GROUP_WIDTH (150) // size by X coordinate #define LIST_HEIGHT (204) // size by Y coordinate #define RADIO_HEIGHT (56) // size by Y coordinate #define CHECK_HEIGHT (93) // size by Y coordinate //--- int SymNum; double vBID,vASK,vol,slippage; //+------------------------------------------------------------------+ //| Class CSymbolSynthesizerDialog | //| Usage: main dialog of the SymbolSynthesizer application | //+------------------------------------------------------------------+ class CSymbolSynthesizerDialog : public CAppDialog { private: CLabel m_label1; // the label1 object CLabel m_label2; // the label2 object CLabel m_label3; // the label3 object CComboBox m_combo_box; // the dropdown list object CEdit m_edit1; // the display field1 object CEdit m_edit2; // the display field2 object CEdit m_edit3; // the display field3 object CSpinEditDouble m_spin_edit1; // the up-down1 object CSpinEdit m_spin_edit2; // the up-down2 object CButton m_button1; // the button sell object CButton m_button2; // the button buy object CTrade m_trade; // trading object public: CSymbolSynthesizerDialog(void); ~CSymbolSynthesizerDialog(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); //--- void TickChange(void); //--- double Call_Trade(string symb,int pos,string com); protected: //--- create dependent controls bool CreateLabel1(void); bool CreateComboBox(void); bool CreateEdit1(void); bool CreateEdit2(void); bool CreateEdit3(void); bool CreateLabel2(void); bool CreateSpinEdit1(void); bool CreateLabel3(void); bool CreateSpinEdit2(void); bool CreateButton1(void); bool CreateButton2(void); //--- handlers of the dependent controls events void OnChangeComboBox(void); void OnChangeSpinEdit1(void); void OnChangeSpinEdit2(void); void OnClickButton1(void); void OnClickButton2(void); }; //+------------------------------------------------------------------+ //| Event Handling | //+------------------------------------------------------------------+ EVENT_MAP_BEGIN(CSymbolSynthesizerDialog) ON_EVENT(ON_CHANGE,m_combo_box,OnChangeComboBox) ON_EVENT(ON_CHANGE,m_spin_edit1,OnChangeSpinEdit1) ON_EVENT(ON_CHANGE,m_spin_edit2,OnChangeSpinEdit2) ON_EVENT(ON_CLICK,m_button1,OnClickButton1) ON_EVENT(ON_CLICK,m_button2,OnClickButton2) EVENT_MAP_END(CAppDialog) //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CSymbolSynthesizerDialog::CSymbolSynthesizerDialog(void) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CSymbolSynthesizerDialog::~CSymbolSynthesizerDialog(void) { } //+------------------------------------------------------------------+ //| Create | //+------------------------------------------------------------------+ bool CSymbolSynthesizerDialog::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); //--- create dependent controls if(!CreateLabel1()) return(false); if(!CreateEdit1()) return(false); if(!CreateEdit2()) return(false); if(!CreateEdit3()) return(false); if(!CreateLabel2()) return(false); if(!CreateSpinEdit1()) return(false); if(!CreateLabel3()) return(false); if(!CreateSpinEdit2()) return(false); if(!CreateButton1()) return(false); if(!CreateButton2()) return(false); if(!CreateComboBox()) return(false); //--- succeed OnChangeComboBox(); return(true); } //+------------------------------------------------------------------+ //| Create the "Label1" element | //+------------------------------------------------------------------+ bool CSymbolSynthesizerDialog::CreateLabel1(void) { //--- coordinates int x1=INDENT_LEFT; int y1=INDENT_TOP; int x2=x1+GROUP_WIDTH; int y2=y1+EDIT_HEIGHT; //--- create if(!m_label1.Create(m_chart_id,m_name+"Label1",m_subwin,x1,y1,x2,y2)) return(false); if(!m_label1.Text("Symbol:")) return(false); if(!Add(m_label1)) return(false); //--- succeed return(true); } //+------------------------------------------------------------------+ //| Create the "ComboBox" element | //+------------------------------------------------------------------+ bool CSymbolSynthesizerDialog::CreateComboBox(void) { //--- coordinates int x1=INDENT_LEFT+(LABEL_WIDTH+CONTROLS_GAP_X); int y1=INDENT_TOP; int x2=x1+GROUP_WIDTH; int y2=y1+EDIT_HEIGHT; //--- create if(!m_combo_box.Create(m_chart_id,m_name+"ComboBox",m_subwin,x1,y1,x2,y2)) return(false); if(!Add(m_combo_box)) return(false); //--- fill out with strings for(int i=0;i-1 && hedge2>-1) { if(Sym[SymNum][3]=="L") Print("Hedge SELL position: ",Sym[SymNum][0]," ",hedge1*hedge2); else Print("Hedge SELL position: ",Sym[SymNum][0]," ",hedge2/hedge1); } else Print("Hedge SELL failed: ",Sym[SymNum][0]); } //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ void CSymbolSynthesizerDialog::OnClickButton2(void) { double hedge1,hedge2; vol=m_spin_edit1.Value(); if(Sym[SymNum][3]=="L") hedge1=Call_Trade(Sym[SymNum][1],0,"HedgeBUY "+Sym[SymNum][0]+"1"); else hedge1=Call_Trade(Sym[SymNum][1],1,"HedgeBUY "+Sym[SymNum][0]+"1"); if(hedge1==-1) { Print("Hedge BUY failed: ",Sym[SymNum][0]); return; } vol=vol*hedge1; hedge2=Call_Trade(Sym[SymNum][2],0,"HedgeBUY "+Sym[SymNum][0]+"2"); if(hedge1>-1 && hedge2>-1) { if(Sym[SymNum][3]=="L") Print("Hedge BUY position: ",Sym[SymNum][0]," ",hedge1*hedge2); else Print("Hedge BUY position: ",Sym[SymNum][0]," ",hedge2/hedge1); } else Print("Hedge BUY failed: ",Sym[SymNum][0]); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ double CSymbolSynthesizerDialog::Call_Trade(string symb,int pos,string com) { bool res; m_trade.SetDeviationInPoints((ulong)slippage); double Lots=NormalizeDouble(vol,2); if(Lots