Modification of the ticket once generated to add SL and TP :
In the extern parameters :
Code:
extern bool modifyafter=false;
If you modify one of my code, after each hidesl==false and hidetp==false, add :
Before the return(0); at the end of the start() function, add :
Code:
if(modifyafter){createstoploss(stoploss);createtakeprofit(takeprofit);}
At the end of the code, add :
Code:
void createstoploss(int stoploss){
RefreshRates();
double ask=MarketInfo(Symbol(),MODE_ASK);
double bid=MarketInfo(Symbol(),MODE_BID);
int total=OrdersTotal();
if(total>0){
for(int i=0;i<total;i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
if(OrderType()==OP_BUY){
if(OrderStopLoss()==0){
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(bid-stoploss*pt,dg),OrderTakeProfit(),0,Blue);
return(0);
}
}
else{
if(OrderStopLoss()==0){
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask+stoploss*pt,dg),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
void createtakeprofit(int takeprofit){
RefreshRates();
double ask=MarketInfo(Symbol(),MODE_ASK);
double bid=MarketInfo(Symbol(),MODE_BID);
int total=OrdersTotal();
if(total>0){
for(int i=0;i<total;i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
if(OrderType()==OP_BUY){
if(OrderTakeProfit()==0){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(bid+takeprofit*pt,dg),0,Blue);
return(0);
}
}
else{
if(OrderTakeProfit()==0){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(ask-takeprofit*pt,dg),0,Red);
return(0);
}
}
}
}
}
}