//--------------------------------------------------------------------- // A function for dynamic calculation of working lot. //--------------------------------------------------------------------- #property copyright "© RickD 2006-2007" #property link "www.e2e-fx.net" //--------------------------------------------------------------------- extern bool uplot = true; extern int lastprofit = 1; extern double lotmin = 0.1; extern double lotmax = 0.5; extern double lotstep = 0.1; double GetLots() { double lot = lotmin; if (!uplot) return (lot); int ticket = GetLastOrderHist(); if (ticket == -1) return (lot); if (!OrderSelect(ticket, SELECT_BY_TICKET, MODE_HISTORY)) return (lot); if (OrderProfit()*lastprofit < 0) return (lot); lot = MathMin(OrderLots() + lotstep, lotmax); return (lot); } int GetLastOrderHist(int type = -1) { int ticket = -1; datetime dt = 0; int cnt = HistoryTotal(); for (int i=0; i < cnt; i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue; //if (OrderSymbol() != Symbol()) continue; //if (OrderMagicNumber() != Magic) continue; if (type != -1 && OrderType() != type) continue; if (OrderCloseTime() > dt) { dt = OrderCloseTime(); ticket = OrderTicket(); } } return (ticket); }