//+------------------------------------------------------------------+ //| RusBafetma.mq5 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ enum sell_or_buy1 { up,//Снизу вверх (покупка) down, // Сверху вниз (продажа) all // Оба }; input int ma_big=14; input int ma_small=7; //input int ma_trend=100; //input bool trend=false; input int pips=3; input ENUM_TIMEFRAMES frame=PERIOD_M1; input sell_or_buy1 sell_or_buy=all; input double lot=0.01; double mbig[],msmall[],mtrend[]; int mabig_handle,masmall_handle,matrend_handle,mid; #include CTrade trade; int OnInit() { //--- EventSetTimer(1); mabig_handle=iMA(NULL,frame,ma_big,0,MODE_EMA,PRICE_CLOSE); masmall_handle=iMA(NULL,frame,ma_small,0,MODE_EMA,PRICE_CLOSE); // matrend_handle=iMA(NULL,frame,ma_trend,0,MODE_EMA,PRICE_CLOSE); if(masmall_handle<0) { Print("Объект iMA не создан: MA_handle= ",INVALID_HANDLE); Print("Ошибка исполнения = ",GetLastError()); //--- принудительное завершение программы return(-1); } if(mabig_handle<0) { Print("Объект iMA не создан: MA_handle= ",INVALID_HANDLE); Print("Ошибка исполнения = ",GetLastError()); //--- принудительное завершение программы return(-1); } /* if(matrend_handle<0) { Print("Объект iMA не создан: MA_handle= ",INVALID_HANDLE); Print("Ошибка исполнения = ",GetLastError()); //--- принудительное завершение программы return(-1); } */ //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTimer() { //--- if(CopyBuffer(mabig_handle,0,0,3,mbig)<=0) return; if(CopyBuffer(masmall_handle,0,0,3,msmall)<=0) return; // if(CopyBuffer(matrend_handle,0,0,3,mtrend)<=0) // return; // ArraySetAsSeries(mtrend,true); ArraySetAsSeries(mbig,true); ArraySetAsSeries(msmall,true); long buy_id,sell_id; ulong ticket; //string type; uint total=PositionsTotal(); int order_buy_c=0; int order_sell_c=0; //Alert(total); //--- пройдем в цикле по всем ордерам for(uint i=0;i0) { //--- получим свойства ордера // type =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE))); //--- подготовим и выведем информацию об ордере // Alert(PositionGetInteger(POSITION_TYPE)); if(PositionGetString(POSITION_SYMBOL)==_Symbol) { if(PositionGetInteger(POSITION_TYPE)==1) { order_sell_c++; sell_id=PositionGetInteger(POSITION_IDENTIFIER); } else { order_buy_c++; buy_id=PositionGetInteger(POSITION_IDENTIFIER); } } } } double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID); if(mbig[1]>=msmall[1] && (msmall[0]-mbig[0])>pips*_Point && order_buy_c<1){trade.PositionClose(sell_id);trade.Buy(lot);} //sell if(mbig[1]<=msmall[1] && (mbig[0]-msmall[0])>pips*_Point && order_sell_c<1){trade.PositionClose(buy_id); trade.Sell(lot);} } //+------------------------------------------------------------------+