#property strict //--- enum type_order{Buy_order,Sell_order}; //--- sinput string Bloc_0="======= EA Options ======="; input type_order order=Buy_order;//Type order input int sl=500;//Stop Loss input int tp=500;//Take Profit input double lot=0.01;//First lot input bool arithmetic =true;//Arithmetic martingale input double martin=0.01;//Increasing lot / multiplying factor input double max_lot=1.00;//Max lot input int magic=777;//Magic extern int slip=50;//Slipage input bool obj_delete=true;//Object delete all //--- int last_type_order=-1,dos; datetime tim; //--- //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- dos=2;if(MarketInfo(Symbol(),MODE_MINLOT)==0.1) dos=1; if(MarketInfo(Symbol(),MODE_MINLOT)==1)dos=0; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(count()==0&&tim!=Time[0]) { if(order==Buy_order) open_buy();else open_sell(); if(obj_delete)ObjectsDeleteAll(); } } //+------------------------------------------------------------------+ //| all_col | //+------------------------------------------------------------------+ int count() { int col_=0; last_type_order=-1; for(int POS=0;POSlots) lots=MarketInfo(Symbol(),MODE_MINLOT); //--- double stop=MarketInfo(Symbol(),MODE_STOPLEVEL); double ask=Ask; double tpz;double slz; //--- if(sl==0)slz=0;else slz=ask-sl*Point; if(tp==0)tpz=0;else tpz=ask+tp*Point; if(stop>sl||stop>tp) {Alert("For this symbols to low SL or TP, order not open, symbol: ",Symbol(),". Minimal stop level: ",stop);tim=Time[0];return;} if(AccountFreeMarginCheck(Symbol(),OP_SELL,lots)<=0) {Alert("Not enjoy money for open order with size: "+DoubleToString(lots,2)+" !");tim=Time[0];return;} RefreshRates(); tk=OrderSend(Symbol(),OP_BUY,lots,Ask,30,slz,tpz,NULL,magic,0,clrGreen); if(tk==-1) {Print("Order not open! Error: ",GetLastError()," pair: ",Symbol());} } //+-------------------------------------------------------------------+ //|OPEN SELL | //+-------------------------------------------------------------------+ void open_sell() { int tk=0; double lots=lotka(); lots=NormalizeDouble(lots,dos); if(MarketInfo(Symbol(),MODE_MINLOT)>lots) lots=MarketInfo(Symbol(),MODE_MINLOT); //--- double stop=MarketInfo(Symbol(),MODE_STOPLEVEL); double bid=Bid; double tpz;double slz; if(sl==0)slz=0;else slz=bid+sl*Point; if(tp==0)tpz=0;else tpz=bid-tp*Point; if(stop>sl||stop>tp) {Alert("For this symbols to low SL or TP, order not open, symbol: ",Symbol(),". Minimal stop level: ",stop);tim=Time[0];return;} if(AccountFreeMarginCheck(Symbol(),OP_SELL,lots)<=0) {Alert("Not enjoy money for open order with size: "+DoubleToString(lots,2)+" !");tim=Time[0];return;} RefreshRates(); tk=OrderSend(Symbol(),OP_SELL,lots,Bid,30,slz,tpz,NULL,magic,0,clrRed); if(tk==-1) {Print("Order not open! Error: ",GetLastError()," pair: ",Symbol());} } //+---------------------------------------------------------------------+ //| was lot | //+---------------------------------------------------------------------+ double lotka() { int history=OrdersHistoryTotal(); for(int i=history-1; i>=0; i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue; else if(OrderMagicNumber()==magic && OrderSymbol()==Symbol()) { if(arithmetic) { if(OrderProfit()<=0&&OrderLots()+martin<=max_lot) return NormalizeDouble(OrderLots()+martin,dos); else return lot; } else { if(OrderProfit()<=0&&OrderLots()*martin<=max_lot) return NormalizeDouble(OrderLots()*martin,dos); else return lot; } } } return lot; }