//+------------------------------------------------------------------+ //| Erosweb_FollowTrades1.00.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict input double trigger_profit_pips = 50; input double interval_pips = 10; input double followtrade_times = 3; input int ea_magic = 55668899; datetime start_time = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetTimer(60); //bool check = HC_PositionOpen(0,0.3,_Symbol); start_time = Time[0]; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- int total = OrdersTotal(); for(int i=0;i=i_openprice+trigger_profit_pips*10*i_point+slave_num*interval_pips*10*i_point) { bool check = HC_PositionOpen(0,i_volume,i_symbol,0,0,ea_magic,string(i_ticket)); } } if(i_type==1) { if(i_bid<=i_openprice-trigger_profit_pips*10*i_point-slave_num*interval_pips*10*i_point) { bool check = HC_PositionOpen(1,i_volume,i_symbol,0,0,ea_magic,string(i_ticket)); } } } } } //--- total = OrdersTotal(); for(int i=0;i0) { HC_PositionClose(i_ticket); } } } //if(TimeCurrent()>start_time+100*PeriodSeconds()) //{ // HC_PositionsCloseAll(2,2,0); //} } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 市价单开仓功能 | //+------------------------------------------------------------------+ bool HC_PositionOpen(int type,double volume,string symbol = "current",double stoploss = 0,double takeprofit = 0,ulong magic = 0,string comment = NULL) { if(symbol == "current") symbol = _Symbol; double ask = SymbolInfoDouble(symbol,SYMBOL_ASK); double bid = SymbolInfoDouble(symbol,SYMBOL_BID); //--- bool res = false; if(type == 0) res = OrderSend(symbol,OP_BUY ,volume,ask,100,stoploss,takeprofit,comment,int(magic),0,clrOrange); if(type == 1) res = OrderSend(symbol,OP_SELL,volume,bid,100,stoploss,takeprofit,comment,int(magic),0,clrAqua ); return res; } //+------------------------------------------------------------------+ //| 市价单平仓和部分平仓功能 根据订单号 | //+------------------------------------------------------------------+ bool HC_PositionClose(ulong ticket) { if(OrderSelect(int(ticket),SELECT_BY_TICKET)) { string symbol = OrderSymbol(); double ask = SymbolInfoDouble(symbol,SYMBOL_ASK); double bid = SymbolInfoDouble(symbol,SYMBOL_BID); if(OrderType()==OP_BUY ) return OrderClose(int(ticket),OrderLots(),bid,100,clrNONE); if(OrderType()==OP_SELL) return OrderClose(int(ticket),OrderLots(),ask,100,clrNONE); } return false; } //+------------------------------------------------------------------+ //| 市价单一次全平功能 | //+------------------------------------------------------------------+ void HC_PositionsCloseAll(int type=2,int profit_type=2,ulong magic=0,string symbol="current",string comment = NULL) { if(symbol == "current") symbol = _Symbol; int total = OrdersTotal(); // number of open positions //--- iterate over all open positions for(int i = total - 1; i >= 0; i--) { if(OrderSelect(i,SELECT_BY_POS)==false) continue; //--- parameters of the position ulong i_ticket = OrderTicket(); //--- int i_type = OrderType(); if(type == 0 && i_type != OP_BUY ) continue; if(type == 1 && i_type != OP_SELL) continue; //--- if(magic != 0 && magic != OrderMagicNumber()) continue; if(symbol != "all" && symbol != OrderSymbol()) continue; if(comment != NULL && comment != OrderComment()) continue; //--- if(profit_type == 0 && OrderProfit() < 0) continue; if(profit_type == 1 && OrderProfit() >= 0) continue; //--- HC_PositionClose(i_ticket); } return; } //+------------------------------------------------------------------+ //| 订单统计功能 - 总和 | //+------------------------------------------------------------------+ double HC_PositionSumCalc(string sum_type,int type = 2,int profit_type = 2,ulong magic = 0,string symbol = "current",string comment = NULL) { if(symbol == "current") symbol = _Symbol; int total = OrdersTotal(); // number of open positions double sum_value = 0; for(int i = 0; i < total; i++) { if(OrderSelect(i,SELECT_BY_POS)==false) continue; //--- parameters of the position ulong i_ticket = OrderTicket(); string i_symbol = OrderSymbol(); //--- int i_type = OrderType(); if(type == 0 && i_type != OP_BUY ) continue; if(type == 1 && i_type != OP_SELL) continue; //--- if(magic != 0 && magic != OrderMagicNumber()) continue; if(symbol != "all" && symbol != OrderSymbol()) continue; if(comment != NULL && comment != OrderComment()) continue; //--- if(profit_type == 0 && OrderProfit() < 0) continue; if(profit_type == 1 && OrderProfit() >= 0) continue; //--- if(sum_type == "number") sum_value += 1; //--- double i_volume = OrderLots(); if(sum_type == "volume") sum_value += i_volume; //--- double i_profit = OrderProfit(); double i_profit_full = i_profit + OrderSwap(); if(sum_type == "profit") sum_value += i_profit; if(sum_type == "profit_full") sum_value += i_profit_full; if(sum_type == "profit_point") sum_value += NormalizeDouble(i_profit / (i_volume * SymbolInfoDouble(i_symbol,SYMBOL_TRADE_TICK_VALUE)),0); if(sum_type == "profit_point_full") sum_value += NormalizeDouble(i_profit_full / (i_volume * SymbolInfoDouble(i_symbol,SYMBOL_TRADE_TICK_VALUE)),0); } //--- return sum_value; }