//+------------------------------------------------------------------+ //| pp2.mq4 | //| Copyright © 2010, | //| | //+------------------------------------------------------------------+ #property copyright " www.Forexyangu.com" #property link "http://www.ForexYangu.com" //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------ extern int StopLoss =40; // SL for an opened order extern int TakeProfit =70; // ?? for an opened order extern double Lots =0.1; // Strictly set amount of lots extern int TrailingStop = 30; //Trailing stop /* Expert designed to open and close trades at first Parabolic SAR dots. Performance depends on your custom parameters Contact me at tonnyochieng@gmail.com */ //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //trading criteria bool result; double price; int cmd,error; //close if ((iSAR(NULL, 0, 0.02, 0.2, 0)iClose(NULL,0,1))) //Signal Buy { if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)) { cmd=OrderType(); //---- open order is sell if(cmd==OP_SELL) { while(true) { if(cmd==OP_BUY) price=Bid; else price=Ask; result=OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE); if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); } else error=0; if(error==135) RefreshRates(); else break; } } } else Print( "Error when order select ", GetLastError()); // Closing Sell //open buy if(OrdersTotal()==0) { int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point);//Opening Buy } } if ((iSAR(NULL, 0, 0.02, 0.2, 0)>iClose(NULL,0,0))&&(iSAR(NULL, 0, 0.02, 0.2, 1)