//+------------------------------------------------------------------+ //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Joke" #property link "http://www.mql5.com" #property version "1.00" //--- input parameters input int Periods=35; //Period for MA indicator input int SL=150; //Stop Loss input int TP=250; //Take Profit input int MAGIC=999; //MAGIC number input string sym1="USDGBP"; //Symbol1 input string sym2="EURJPY"; //Symbol2 MqlTradeRequest trReq1; MqlTradeResult trRez1; MqlTradeRequest trReq2; MqlTradeResult trRez2; int handle1; int handle2; double SmoothedBuffer1[]; double SmoothedBuffer2[]; double sl; double tp; int curBAR; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //Set default vaules for all new order requests trReq1.action=TRADE_ACTION_DEAL; trReq1.magic=MAGIC; trReq1.symbol=sym1; // Trade symbol trReq1.volume=0.1; // Requested volume for a deal in lots trReq1.deviation=1; // Maximal possible deviation from the requested price trReq1.type_filling=ORDER_FILLING_AON; // Order execution type trReq1.type_time=ORDER_TIME_GTC; // Order execution time trReq1.comment="JokeForever"; //end //Set default vaules for all new order requests trReq2.action=TRADE_ACTION_DEAL; trReq2.magic=MAGIC; trReq2.symbol=sym2; // Trade symbol trReq2.volume=0.1; // Requested volume for a deal in lots trReq2.deviation=1; // Maximal possible deviation from the requested price trReq2.type_filling=ORDER_FILLING_AON; // Order execution type trReq2.type_time=ORDER_TIME_GTC; // Order execution time trReq2.comment="JokeForever"; //end //Create handle for 2 MA indicators handle1=iMA(sym1,PERIOD_CURRENT,Periods,0,MODE_EMA,PRICE_CLOSE); handle2=iMA(sym2,PERIOD_CURRENT,Periods,0,MODE_EMA,PRICE_CLOSE); //end //input parameters are ReadOnly tp=TP*0.0001; sl=SL*0.0001; //end return(0); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { MqlTick tick1,tick2; //variable for tick info if(!SymbolInfoTick(sym1,tick1)) { printf("Failed to get Symbol info for ",sym1); return; } if(!SymbolInfoTick(sym2,tick2)) { printf("Failed to get Symbol info for ",sym2); return; } //Create handle for 2 MA indicators handle1=iMA(sym1,PERIOD_CURRENT,Periods,0,MODE_EMA,PRICE_CLOSE); handle2=iMA(sym2,PERIOD_CURRENT,Periods,0,MODE_EMA,PRICE_CLOSE); //end //Copy latest MA indicator values into a buffer int copied=CopyBuffer(handle1,0,0,4,SmoothedBuffer1); if(copied>0) copied=CopyBuffer(handle2,0,0,4,SmoothedBuffer2); if(copied>0) { double curBID,curMA; curBID = tick2.ask/tick1.bid; curMA = SmoothedBuffer2[1]/SmoothedBuffer1[1]; // if(curBID <= curMA && curMA-sl= curMA+tp) { printf("tp"); CloseAllPosSell(); curBAR = Bars(Symbol(),Period()); return; } if(curBID <= curMA-sl) { printf("sl"); CloseAllPosSell(); curBAR = Bars(Symbol(),Period()); return; } } } //+------------------------------------------------------------------+ int GetOrders(string sym, int tpe) { int ords; int pos=PositionsTotal(); // ??????? ?????????? ???????? ??????? for(int ip=0;ip<=pos;ip++) { string sSymbol=PositionGetSymbol(ip); if(PositionSelect(sSymbol)==true) { if(PositionGetInteger(POSITION_TYPE)==tpe) { ords++; } } } return(ords); //--- } //+------------------------------------------------------------------------------------+ void CloseAllPosSell() { MqlTick tick1,tick2; //variable for tick info if(!SymbolInfoTick(sym1,tick1)) { Print("Failed to get Symbol info for ",sym1); return; } if(!SymbolInfoTick(sym2,tick2)) { Print("Failed to get Symbol info for ",sym2); return; } if(GetOrders( sym2, ORDER_TYPE_BUY)!=0) { trReq2.price=tick2.bid; // SymbolInfoDouble(NULL,SYMBOL_ASK); trReq2.sl=0; // Stop Loss level of the order trReq2.tp=0; // Take Profit level of the order trReq2.type=ORDER_TYPE_SELL; // Order type printf("close buy"); OrderSend(trReq2,trRez2); return; } if(GetOrders( sym1, ORDER_TYPE_SELL)!=0) { trReq1.price=tick1.ask; trReq1.sl=0; // Stop Loss level of the order trReq1.tp=0; // Take Profit level of the order trReq1.type=ORDER_TYPE_BUY; // Order type printf("close sell"); OrderSend(trReq1,trRez1); return; } } //+------------------------------------------------------------------------------------+