needs help with stoploss modifications.. =)

 

Hi All,


Ive been trying to figure out what is wrong with my code below. Basically, I want to modify and order's stoploss once it hits a desired price. Please tell me what i'm doing wron.. i've read it over and over a lot of times but still can't get it to work. I'd really appreciate your help. =)

Thanks!!



void AdjustStop()
{
for (int trall=0; trall<OrdersTotal(); trall++) {
if ((OrderSelect(trall, SELECT_BY_POS, MODE_TRADES))) continue;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

{
if ((OrderOpenPrice() + TPLong < Bid) && (OrderType() == OP_BUY))OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+ SLLong, 0, 0, Blue);
if ((OrderOpenPrice() - TPShort > Ask ) && (OrderType() == OP_SELL))OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - SLShort, 0, 0, Blue);
}

}

}

 


if ((OrderSelect(trall, SELECT_BY_POS, MODE_TRADES))) continue;

I don't see a logic operator in this conditional-if


or,


would it be better to simply say: OrderSelect(trall, SELECT_BY_POS, MODE_TRADES);

 
heyarn wrote >>

Hi All,

Ive been trying to figure out what is wrong with my code below. Basically, I want to modify and order's stoploss once it hits a desired price. Please tell me what i'm doing wron.. i've read it over and over a lot of times but still can't get it to work. I'd really appreciate your help. =)

Thanks!!

void AdjustStop()
{
for (int trall=0; trall<OrdersTotal(); trall++) {
if ((OrderSelect(trall, SELECT_BY_POS, MODE_TRADES))) continue;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

{
if ((OrderOpenPrice() + TPLong < Bid) && (OrderType() == OP_BUY))OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+ SLLong, 0, 0, Blue);
if ((OrderOpenPrice() - TPShort > Ask ) && (OrderType() == OP_SELL))OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - SLShort, 0, 0, Blue);
}

}

}

If I'm not mistaken you do not need the "continue". I think that that will cause the program to skip to the next iteration so you will never get the next statement executed.

Easy to test just delete "continue" and see what happens.

HTH

Keith

 

Also, you should take a look at: MarketInfo(Symbol(),MODE_STOPLEVEL); if your trailing stop is a variable one.


I spent the better part of last week working with the OrderModify() function; it is a tricky one to say the least. If you ignore MODE_STOPLEVEL which defines the non-modify zone you will get Error 130. The non-modify zone applies to SL's and TP's. Also Error 2 which rejects the requested modification because the proposed modification wants to replace the existing SL with the same value. So you also have to check to make sure you are actually changing the value of the existing SL.

Reason: