I need help,pls.(TrailingPositions)

To add comments, please log in or register
vieri32
118
vieri32  

I want to make a negative trailing stops.I pasted code which makes takeprofit 0 when it goes for exzample -10 pips.But it gives error...

void TrailingPositions() {
double pBid, pAsk, pp;
pp = MarketInfo(OrderSymbol(), MODE_POINT);
if (OrderType()==OP_BUY) {
pBid = MarketInfo(OrderSymbol(), MODE_BID);
//BreakEven routine
if (BreakEven>0) {
if ((OrderOpenPrice()-pBid)>BreakEven*pp) {
if ((OrderTakeProfit()-OrderOpenPrice())>0) {
ModifyTakeProfit(OrderOpenPrice());
}
}
}

if (TrailingStop>0) {
if ((pBid-OrderOpenPrice())>TrailingStop*pp) {
if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss(pBid-TrailingStop*pp);
return;
}
}
}
}
if (OrderType()==OP_SELL) {
pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
if (BreakEven>0) {
if ((pAsk-OrderOpenPrice())>BreakEven*pp) {
if ((OrderTakeProfit()-OrderOpenPrice())<0) {
ModifyTakeProfit(OrderOpenPrice()-0*pp);
}
}
}
if (TrailingStop>0) {
if (OrderOpenPrice()-pAsk>TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}
}
//+------------------------------------------------------------------+
//| Modify StopLoss |
//| Parameters: |
//| ldStopLoss - StopLoss Leve |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss) {
bool fm;
PlaySound("alert.wav");
fm=OrdModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}
void ModifyTakeProfit(double ldTakeProfit) {
bool fm;
PlaySound("alert.wav");
fm=OrdModify(OrderTicket(),OrderOpenPrice(),ldTakeProfit,OrderStopLoss(),0,CLR_NONE);
}
Simon Gniadkowski
17644
Simon Gniadkowski  

Please use this to post code . . . it makes it easier to read.


take a look here for trailing SL :http://crum.be/trailsl

whroeder1
17954
whroeder1  
fm=OrdModify(OrderTicket(),OrderOpenPrice(),ldTakeProfit,OrderStopLoss(),0,CLR_NONE);
  1. OrdModify is custom function or your code DOESN'T compile.
  2. Did you OrderSelect() the order, otherwise OrderTicket(), OrderOpenPrice(), etc are meaning less.
  3. Always test return codes.
    if (!OrderModify(...) Alert("OrderModify failed: ",GetLastError());

To add comments, please log in or register