#property copyright "Mokara" #property link "https://www.mql5.com/en/users/mokara" #property description "" #property version "1.0" #include #include #include #include #include #include #include #include #include #include #define SPAN 6 #define DIALOG_WIDTH 300 #define DIALOG_HEIGHT 250 #define CELL_WIDTH 40 #define CELL_HEIGHT 40 CFiboHandler fibo_handler; //https://www.youtube.com/watch?v=rBCNDJXhR1o&list=PLeQQbTeiG3sD5QS8ExpmRoJGz1vvFz4nv&index=73 class MyAppDialog : public CAppDialog { private: CLabel label1; CRadioGroup m_radio_group; CMySpinEdit edit_trailing; CButton btn_set_trail; CMySpinEdit edit_tp_unit_value; CButton btn_set_tp; CArrayString Positions; CArrayString Orders; CTrade trade; public: void OnInit(){ Create(0, "Trade Copilot V3", 0, 20, 20, DIALOG_WIDTH, DIALOG_HEIGHT); int x1 = 0; int y1 = SPAN; int subwin = 0; //row 1 label1.Create(0, "label1", subwin, x1, y1, x1+CELL_WIDTH, y1+CELL_HEIGHT); label1.ColorBackground(clrGreen); label1.Color(clrGreen); label1.Text("Sell limit 10"); Add(label1); //row 2 y1 = y1+CELL_HEIGHT; x1 = 0; m_radio_group.Create(0, "m_radio_group", subwin, 0, y1, x1+CELL_WIDTH*3, y1+CELL_HEIGHT*1.5); m_radio_group.AddItem("所有单", 0); m_radio_group.AddItem("盈利单", 1); m_radio_group.AddItem("亏损单", 2); m_radio_group.Value(0); Add(m_radio_group); //row 3 y1 = y1+CELL_HEIGHT*1.5+SPAN; x1 = 0; edit_trailing.Create(0, "edit_trailing", subwin, 0, y1, x1+CELL_WIDTH*2, y1+CELL_HEIGHT); // edit_trailing.Width(); // edit_trailing.Height(); edit_trailing.MaxValue(100); edit_trailing.MinValue(0); edit_trailing.Value(50); Add(edit_trailing); x1 = x1+CELL_WIDTH*2 + SPAN; btn_set_trail.Create(0, "btn_set_trail", 0, x1, y1, 0, 0); btn_set_trail.Width(CELL_WIDTH*4); btn_set_trail.Height(CELL_HEIGHT); btn_set_trail.ColorBackground(clrOrange); btn_set_trail.Text("设置追踪"); Add(btn_set_trail); //row 4 y1 = y1+CELL_HEIGHT+SPAN; x1 = 0; edit_tp_unit_value.Create(0, "edit_tp_unit_value", subwin, 0, y1, x1+CELL_WIDTH*2, y1+CELL_HEIGHT); edit_tp_unit_value.MaxValue(600); edit_tp_unit_value.MinValue(0); edit_tp_unit_value.Value(50); edit_tp_unit_value.StepValue(25); Add(edit_tp_unit_value); x1 = x1+CELL_WIDTH*2 + SPAN; btn_set_tp.Create(0, "btn_set_tp", 0, x1, y1, 0, 0); btn_set_tp.Width(CELL_WIDTH*4); btn_set_tp.Height(CELL_HEIGHT); btn_set_tp.ColorBackground(clrLimeGreen); btn_set_tp.Text("设置TP"); Add(btn_set_tp); Run(); OnTick(); } void OnDeinit(const int reason){ Destroy(reason); } void OnTick(){ double unit_percent = 0.05; label1.Text(StringFormat("单位PIPS: %d", UnitPips(unit_percent))); } void ChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam); }; void MyAppDialog::ChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam){ CAppDialog::ChartEvent(id, lparam, dparam, sparam); fibo_handler.OnChartEvent(id, lparam, dparam, sparam); if(id==CHARTEVENT_OBJECT_CLICK){ //设置追踪 if(sparam==btn_set_trail.Name()){ double lots = 0.01;// edit1.Value(); // trade.Sell(lots); double target_group = m_radio_group.Value(); Print("btn_set_trail: ", edit_trailing.Value(), m_radio_group.Value()); // for(int i=PositionsTotal()-1; i>=0; i--){ // ulong ticket = PositionGetTicket(i); // if(PositionSelectByTicket(ticket)){ // double profit = PositionGetDouble(POSITION_PROFIT); // bool is_ok = true; // if(target_group==0){ // is_ok = true; // }else if(target_group==1){ // is_ok = profit>0; // }else{ // is_ok = profit<0; // } // if(is_ok){ // PositionModifyTP(ticket, unit_percent, tp_unit_value); // } // } // } //设置TP }else if(sparam==btn_set_tp.Name()){ double tp_unit_value = edit_tp_unit_value.Value()/100; double unit_percent = 0.05; // for(int i=PositionsTotal()-1; i>=0; i--){ ulong ticket = PositionGetTicket(i); // trade.PositionClose(ticket); PositionModifyTP(ticket, unit_percent, tp_unit_value); } Print("btn_set_tp: ", edit_tp_unit_value.Value(), m_radio_group.Value()); } // else if(sparam==btn3.Name()){ // } } } MyAppDialog app = MyAppDialog(); CTrade trade; int OnInit() { //--- ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true); app.OnInit(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { app.OnDeinit(reason); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { app.ChartEvent(id, lparam, dparam, sparam); } void OnTick() { //--- app.OnTick(); }