Oedyne Gwibroed
New Member
- Credits
- 0
bool Trail(int Stop)
{
double newStopLoss=0.0;
textstring="";
int StopLevel = (int)MarketInfo(Symbol(),MODE_STOPLEVEL);
if(Stop<StopLevel)Stop=StopLevel;
for (int i = OrdersTotal() - 1; i >= 0; i--){
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber ) continue;
if(OrderType()==OP_BUY) {
newStopLoss=Bid-(Stop*Point);
if(Bid-OrderOpenPrice()>Point*Stop) {
if((OrderStopLoss()<Bid-Point*Stop) || (OrderStopLoss()==0)) {
if(OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0,clrNONE)==false)
{
return(false);
}else
{
return(true);
}
}
}
}
if(OrderType()==OP_SELL) {
newStopLoss=Ask+(Stop*Point);
if((OrderOpenPrice()-Ask)>(Point*Stop)){
if(OrderStopLoss()>Ask+(Point*Stop) || (OrderStopLoss()==0)){
if(OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0,clrNONE)==false)
{
return(false);
}else
{
return(true);
}
}
}
}
}
return(true);
}
{
double newStopLoss=0.0;
textstring="";
int StopLevel = (int)MarketInfo(Symbol(),MODE_STOPLEVEL);
if(Stop<StopLevel)Stop=StopLevel;
for (int i = OrdersTotal() - 1; i >= 0; i--){
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber ) continue;
if(OrderType()==OP_BUY) {
newStopLoss=Bid-(Stop*Point);
if(Bid-OrderOpenPrice()>Point*Stop) {
if((OrderStopLoss()<Bid-Point*Stop) || (OrderStopLoss()==0)) {
if(OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0,clrNONE)==false)
{
return(false);
}else
{
return(true);
}
}
}
}
if(OrderType()==OP_SELL) {
newStopLoss=Ask+(Stop*Point);
if((OrderOpenPrice()-Ask)>(Point*Stop)){
if(OrderStopLoss()>Ask+(Point*Stop) || (OrderStopLoss()==0)){
if(OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0,clrNONE)==false)
{
return(false);
}else
{
return(true);
}
}
}
}
}
return(true);
}