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

[amibroker] Re: Plot ATR trailing stop which only increases



PureBytes Links

Trading Reference Links

Andrew,

One issue with a line that only ever increases is where do you start
it from? Do you only want it to start once at the beginning of the
data, or at every Buy signal, or at some other points?

One generic solution is an auto-resetting stop, which only ever
increases until it is broken, at which point it resets back to the
value associated with that bar. A function to do that might be like this:

function MakeAutoStop(data, trigger)
{
    stop = data[0];
    for (i = 1; i < BarCount; i++)
    {
        stop[i] = data[i];
        if (stop[i] < stop[i-1])
            stop[i] = stop[i-1];
        if (trigger[i] < stop[i])
            stop[i] = data[i];
    }
    return stop;
}

In this case "data" is the raw stop data that you want to make into a
trailing stop, and "trigger" is the array that should break through it
to trigger an exit (typically Close). Note that this won't always give
the same results as starting from a specific entry date, but solves
the problem of how to specify the entry dates.

If you want something that will start from each Buy signal, with the
stop being the only method of exit, then it's more complicated since
some buy signals will be ignored if no exit has been triggered to the
previous one at that point. One possibility there, assuming Buy is
global, is:

function MakeStop(data, trigger)
{
    stop = Null;
    holding = False;
    for (i = 0; i < BarCount; i++)
    {
        if (holding)
        {
            Buy[i] = False; // Remove redundant Buy signals
            if (data[i] > stop[i-1])
                stop[i] = data[i];
            else
                stop[i] = stop[i-1];
            if (trigger[i] < stop[i])
                holding = False;
        }
        else
        {
            if (Buy[i])
            {
                holding = True;
                stop[i] = data[i];
            }
        }
    }
    return stop;
}

Hope this helps.

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "amickan1958" <amickan@xxx> wrote:
>
> Hi,
> 
> I've been trying to crack this one but can't seem to. What I need is a 
> plot of my trailing stop. The stop is based on a multiplier of todays 
> ATR(30) value. This stop only ever increase.
> 
> Can anyone help me out with some code please?
> 
> Thanks
> 
> Andrew
>




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

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