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

Re: [amibroker] Re: Applystop trailing stop calculation



PureBytes Links

Trading Reference Links

I disagree. It is documented quite well in fact.

Basic BACKTESTING TUTORIAL (MUST READ FOR EVERYONE who wants to run any backtest):

http://www.amibroker.com/guide/h_backtest.html

Excerpt:

Trailing stops

This kind of stop is used to protect profits as it tracks your trade so each time a position value reaches a new high, the trailing stop is placed at a higher level. When the profit drops below the trailing stop level the position is closed. This mechanism is illustrated in the picture below (10% trailing stop is shown):

< 
The trailing stop, as well as two other kind of stops could be enabled from user interface (Automatic analysis' Settings window) or from the formula level - using ApplyStop function:

To reproduce the example above you would need to add the following code to your automatic analysis formula:

ApplyStop( 2, 1, 10, 1 ); // 10% trailing stop, percent mode, exit at stop ON

or you can write it using predefined constants that are more descriptive

ApplyStop( stopTypeTrail, stopModePercent, 10, True );

Trailing stops could be also defined in points (dollars) and percent of profit (risk). In the latter case the amount parameter defines the percentage of profits that could be lost without activating the stop. So 20% percent of profit (risk) stop will exit your trade that has maximum profit of $100 when the profit decreases below $80.

Dynamic stops

The ApplyStop() function allows now to change the stop level from trade to trade. This enables you to implement for example volatility-based stops very easily.

For example to apply maximum loss stop that will adapt the maximum acceptable loss based on 10 day average true range you would need to write:

ApplyStop( 0, 2, 2 * ATR( 10 ), 1 );

or you can write it using predefined constants that are more descriptive

ApplyStop( stopTypeLoss, stopModePoint, 2 * ATR( 10 ), True );

The function above will place the stop 2 times 10 day ATR below entry price.

As ATR changes from trade to trade - this will result in dynamic, volatility based stop level. Please note that 3rd parameter of ApplyStop function (the amount) is sampled at the trade entry and held troughout the trade. So in the example above it uses ATR(10) value from the date of the entry. Further changes of ATR do not affect the stop level.

See complete APPLYSTOP function documentation for more details.


Best regards,
Tomasz Janeczko
amibroker.com
  ----- Original Message ----- 
  From: Mark H 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Friday, November 03, 2006 6:25 PM
  Subject: Re: [amibroker] Re: Applystop trailing stop calculation


  It is not very well documented and I have never used trailing stop myself so can't give you a definite answer.

  If I were you, I would probably find out by myself. Just run a backtest and compare the trade price of trailing stops with calculations based on the following:
  Yesterday's high or close, today's open or high.

  AB is evolving so fast, and some details are not very well documented. I have found myself use _TRACE() a lot to figure out how AB does a lot of calculations, expecially within CBT which I use extensively.



    ----- Original Message ----- 
    From: jlami11 
    To: amibroker@xxxxxxxxxxxxxxx 
    Sent: Friday, November 03, 2006 9:40 AM
    Subject: [amibroker] Re: Applystop trailing stop calculation


    Hi,

    sorry maybe i explained poorly. What i mean is how is the trailing
    stop value calculated. 

    e.g.For long trade using 3*ATR as trailing stop. Is the ATR value
    subtracted from yesterdays Close price or from todays Open price etc etc.?
    or is it done in some other way entirely?

    regards.

    --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxx> wrote:
    >
    > Applystops work on the High and Low prices crossing the stop value
    > 
    > 
    > -- 
    > Cheers
    > Graham
    > AB-Write >< Professional AFL Writing Service
    > Yes, I write AFL code to your requirements
    > http://www.aflwriting.com
    > 
    > 
    > 
    > On 03/11/06, jlami11 <jlami11@xxx> wrote:
    > >
    > > Thanks Graham and steve for responses to other message.
    > >
    > > I have another quesiton about the trailing stop that is used in
    > > Applystop: Is the amount of whatever trailing stop you are using
    > > applied to previous days closing price? or does it work in another
    way?
    > >
    > > Thanks any help appreciated.
    > >



   


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006