Code:
void StepStops()
{
double BuyStop, SellStop;
int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
if ( OrderSymbol()==Symbol() )
{
if ( mode==OP_BUY )
{
BuyStop = OrderStopLoss();
if ( Bid-OrderOpenPrice()>0 || OrderStopLoss()==0)
{
if ( Bid-OrderOpenPrice()>=Point*BreakEven && !BE) {BuyStop = OrderOpenPrice();BE = true;}
if (OrderStopLoss()==0) {BuyStop = OrderOpenPrice() - InitialStop * Point; k=1; BE = false;}
if ( Bid-OrderOpenPrice()>= k*StepSize*Point)
{
BuyStop = OrderStopLoss()+ StepSize*Point;
if (Bid - BuyStop >= MinDistance*Point)
{ BuyStop = BuyStop; k=k+1;}
else
BuyStop = OrderStopLoss();
}
//Print( " k=",k ," del=", k*StepSize*Point, " BuyStop=", BuyStop," digit=", digit);
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(BuyStop, digit),
OrderTakeProfit(),0,LightGreen);
return(0);
}
}
if ( mode==OP_SELL )
{
SellStop = OrderStopLoss();
if ( OrderOpenPrice()-Ask>0 || OrderStopLoss()==0)
{
if ( OrderOpenPrice()-Ask>=Point*BreakEven && !BE) {SellStop = OrderOpenPrice(); BE = true;}
if ( OrderStopLoss()==0 ) { SellStop = OrderOpenPrice() + InitialStop * Point; k=1; BE = false;}
if ( OrderOpenPrice()-Ask>=k*StepSize*Point)
{
SellStop = OrderStopLoss() - StepSize*Point;
if (SellStop - Ask >= MinDistance*Point)
{ SellStop = SellStop; k=k+1;}
else
SellStop = OrderStopLoss();
}
//Print( " k=",k," del=", k*StepSize*Point, " SellStop=",SellStop," digit=", digit);
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(SellStop, digit),
OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}
*siflotte*