//+——————————————————————+
//| FXPT_BuySellUnlimitedOrders.mq4|
//| Developed by fxprotrader |
//| http://www.fxpro-trader.com” |
//+——————————————————————+
#property copyright “Copyright © 2011, fxprotrader”
#property link “http://www.fxpro-trader.com”
//——– HISTORY—————-
// v0.1 Initial release(013012)
//——————————–
//coded for Price
//http://www.forexfactory.com/showthread.php?p=5335422#post5335422
#property show_inputs
extern string TopComment1=”Check Symbol and Order type”;
extern string TopComment2=”Must select Buy or Sell”;
extern bool buyorder = FALSE;
extern bool sellorder = FALSE;
extern int NumberOfOrders = 5;
extern double Lots = 0.10;
extern int StopLoss = 40;
extern int TakeProfit= 20
extern int MagicNumber = 999;
extern string MyComment=””;
string TradeComment=”FXPT_BuySell “;
int Slippage=2;
double Poin;
//+——————————————————————+
//| Custom initialization function |
//+——————————————————————+
int init(){
if (Point == 0.00001) Poin = 0.0001;
else {
if (Point == 0.001) Poin = 0.01;
else Poin = Point;
}
return(0);
}
//+——————————————————————+
//| script program start function |
//+——————————————————————+
int start(){
double BP,SP,TP,SL,HashLn;
int ticket;
int c,x,err;
int NumberOfTries=5;
//BUY
if(buyorder == TRUE){
for(x=0;x<NumberOfOrders;x++){
for(c=0;c<NumberOfTries;c++){
RefreshRates();
SL=Ask-(StopLoss*Poin);
TP=Ask+(TakeProfit*Poin);
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,TradeComment+DoubleToStr(StopLoss,0)+”/”+DoubleToStr(TakeProfit,0)+” “+Period(),MagicNumber,0,Blue);
err=GetLastError();
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){
OrderModify(ticket,OrderOpenPrice(),SL,TP,0,Blue);
}
}
if(err==0){break;}
else{
Print(“Errors opening BUY order err:”+err);
if(err==4 || err==137 ||err==146 || err==136){
Sleep(100);continue;//Busy errors
}
else{break;}//normal error
}
}//for error/NumberOfTries
}
return(ticket);
}
//sell
else if(sellorder == TRUE){
for(x=0;x<NumberOfOrders;x++){
for(c=0;c<NumberOfTries;c++){
RefreshRates();
SL=Bid+(StopLoss*Poin);
TP=Bid-(TakeProfit*Poin);
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,TradeComment+DoubleToStr(StopLoss,0)+”/”+DoubleToStr(TakeProfit,0)+” “+Period(),MagicNumber,0,Red);
err=GetLastError();
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){
OrderModify(ticket,OrderOpenPrice(),SL,TP,0,Red);
}
}
if(err==0){break;}
else{
Print(“Errors opening SELL order err:”+err);
if(err==4 || err==137 ||err==146 || err==136){
Sleep(100);continue;//Busy errors
}
else{break;}//normal error
}
}//for error/NumberOfTries
}
return(ticket);
}
// }
}