Thread: How to code?
View Single Post
  #865 (permalink)  
Old 05-04-2008, 06:41 AM
nittany1's Avatar
nittany1 nittany1 is offline
Senior Member
 
Join Date: Dec 2006
Location: Sarasota, FL
Posts: 184
nittany1 is on a distinguished road
I threw together an adjust trailing stop function for EAs, can someone check it out?

Code:
//+-----------------------------------------------------+
//|           adjust trailing stop                      |
//+-----------------------------------------------------+
void AdjustTrailingStop()
{
  int orders = OrdersTotal();
  for(int j=orders-1;j>=0;j--)
  {
    OrderSelect(j, SELECT_BY_POS);
    int type = OrderType();
    //-- Adjust trailing stop for BUYs
    if (type == OP_BUY && OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNumber))
    {
      if (Ask-TrailingStop*Point > OrderOpenPrice() && Ask-TrailingStop*Point > OrderStopLoss())
        {
          OrderModify(OrderTicket(),OrderOpenPrice(),Ask-TrailingStop*Point,OrderTakeProfit(),0);
        }  
    }
    //-- Adjust trailing stop for SELLs
    if (type == OP_SELL && OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNumber))
    {  
      if (Bid+TrailingStop*Point < OrderOpenPrice() && Bid+TrailingStop*Point < OrderStopLoss())
        {
          OrderModify(OrderTicket(),OrderOpenPrice(),Bid+TrailingStop*Point,OrderTakeProfit(),0);
        } 
    }
  }
}
__________________
You can find me on irc.ircforex.com most of the time... on #forex
Myspace Facebook My Indicators: Trade Assistant Trend Friend ToR CCI Helper
Holder of US Patent 6,774,788
Reply With Quote