//+------------------------------------------------------------------+ //| Ojala.mq4 | //| Mohammed | //| http://www.forex-tsd.com | //+------------------------------------------------------------------+ #property copyright "Mohammed" #property link "http://www.forex-tsd.com" //18:15 18:14 17:15 18:12 extern double TakeProfit=13; extern double TrailingStop=8; extern double StopLoss=25; extern bool UseStopLoss = true; extern double Lots = 0.01; extern int EmaPeriod = 12; // Thanks going to Coders' Guru! bool isNewSumbol(string current_symbol) { //loop through all the opened order and compare the symbols int total = OrdersTotal(); for(int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); string selected_symbol = OrderSymbol(); if (current_symbol == selected_symbol) return (False); } return (True); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int cnt, ticket, total; if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } total = OrdersTotal(); if(total < 1 || isNewSumbol(Symbol())) { if(iCustom(NULL,0,"EMAOsMA",0,1)<0 && iCustom(NULL,0,"EMAOsMA",EmaPeriod,0,0)>0) { if(UseStopLoss) ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Ojala",12345,0,Green); else ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"Ojala",12345,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(iCustom(NULL,0,"EMAOsMA",0,1)>0 && iCustom(NULL,0,"EMAOsMA",EmaPeriod,0,0)<0) { if(UseStopLoss) ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Ojala",12345,0,Red); else ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"Ojala",12345,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } for(cnt=0;cnt0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } //+------------------------------------------------------------------+