//+------------------------------------------------------------------+ //| Simple trade copier on the same account | //| Copyright 2017, V | //+------------------------------------------------------------------+ #property version "1.1" #property copyright "Copyright © 2015, V" #property description "Simple trade copier on the same account." #property strict //+------------------------------------------------------------------+ //| Enumerator of working mode | //+------------------------------------------------------------------+ input int slip=3; // Slippage (in pips) input double mult=1.0; // Multiplier (for copied trade) input int freq=1000; // Check frequency (milliseconds) input string prefix="VCPY_"; // Copied trade comment prefix input int maxAge=30; // Max age of the trade to be copied in sec //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class OrderContainer { public: int ticket; int copiedFrom; string symbol; int type; double price; double lot; double stoploss; double takeprofit; datetime opentime; string comment; OrderContainer(void); ~OrderContainer(void) { } OrderContainer(int pticket, string psymbol, int ptype, double pprice, double plot, double pstoploss, double ptakeprofit, datetime popentime, string pcomment) { ticket = pticket; symbol = psymbol; type=ptype; price=pprice; lot=plot; stoploss=pstoploss; takeprofit=takeprofit; opentime= popentime; comment = pcomment; if(StringSubstr(pcomment,0,StringLen(prefix))==prefix) { copiedFrom=StrToInteger(StringSubstr(pcomment,StringLen(prefix))); } } }; //+------------------------------------------------------------------+ //|Initialisation function | //+------------------------------------------------------------------+ void init() { ObjectsDeleteAll(); EventSetMillisecondTimer(freq); return; } //+------------------------------------------------------------------+ //|Deinitialisation function | //+------------------------------------------------------------------+ void deinit() { ObjectsDeleteAll(); EventKillTimer(); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTimer() { OrderContainer *orders[100]; int orderCount=OrdersTotal(); if(orderCount==0) return; //--- Saving information about all deals for(int i=0; i1)) break; orders[i]=new OrderContainer(OrderTicket(),OrderSymbol(),OrderType(),OrderOpenPrice(),OrderLots(),OrderStopLoss(),OrderTakeProfit(),OrderOpenTime(),OrderComment()); } OrderContainer *ordersToOpen[100]; int toOpenIndex=0; OrderContainer *ordersToClose[100]; int toCloseIndex=0; for(int i=0;islip) return; int orderSendReturnValue=OrderSend(symbol_,type_,lot_,market_price,slip,0,0,prefix+IntegerToString(ticket_)); if(orderSendReturnValue==-1) { Print("Error: ",GetLastError()," during opening the market order."); } else { Print("Market order ",IntegerToString(ticket_)," copied as ",prefix+IntegerToString(ticket_),"."); } return; } //+------------------------------------------------------------------+