[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Trailing Stop Example



PureBytes Links

Trading Reference Links

The following implements a trailing stop loss at yesterdays LOW minus
SLlevel (Adapt to your own needs):
-----------------------------------------------------

Buy = Cond;
Sell = 0; // Initialize Sell Array before looping

/* ORDER EXIT */
positionopen = False;
for( i = 1; i < BarCount; i++ )       // Trailing Stop logic
{
      if ( positionopen )  Buy[ i ] = False;  // ExRem sim... only 1
Buy signal per trade
      if ( Buy[i] )
      {
         SellPrice[ i ] = 0;         // No S/L on 1st Day
         positionopen = True;
      }
     else
        SellPrice[ i ] = Max( Low[ i - 1 ] - SLlevel, SellPrice[ i - 1
] );

     if ( Open[i] < SellPrice[i] )        SellPrice[i] = Open[i];

    if ( i == BarCount OR L[ i ] <= SellPrice[ i ] )
    {
        Sell[ i ] = True;
        positionopen = False;
    }
}


Regards,

Phsst


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs Online - Over 14,500 titles.
No Late Fees & Free Shipping.
Try Netflix for FREE!
http://us.click.yahoo.com/Tq9otC/XP.FAA/3jkFAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/