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

[amibroker] Re: Trailing Stop in AB



PureBytes Links

Trading Reference Links

You can do a generic (long) trailing stop from your Buy array like this:

Buy = False; // Make global variables
Sell = False;

function TrailingStop(data, trigger)
{
    stop = Null;
    inPos = False;
    for (i = 0; i < BarCount; i++)
    {
        if (!inPos)
        {
            if (Buy[i])
            {
                inPos = True;
                stop[i] = data[i];
            }
        }
        else
        {
            Buy[i] = False; // Remove excess buy signals
            stop[i] = Max(data[i], stop[i-1]);
            if (trigger[i] < stop[i])
            {
                Sell[i] = True;
                inPos = False;
            }
        }
    }
    return stop;
}

Buy = <your buy rules>;
Stop = TrailingStop(<stop line array>, <trigger array>);

The stop line array can be anything you want to use as a trailing
stop, eg. Close-3*ATR(21). The trigger array is the array you want to
cross below the stop line to trigger an exit, eg. Close.

The TrailingStop function will both fill the Sell array with the
appropriate sell signals and give you a stop line that can be plotted
to show the trailing stops after each buy signal:

Plot(Stop, "Stop", colorBlue, styleLine | styleThick);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorBlue, 0, Low, -30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorBlue, 0, Low, -30);

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "Greg" <crootster@xxx> wrote:
>
> Howard,
> I was told that the trailing stop in the system works off the high 
> and that you need a plug in to work off the LOW.
> 
> Cheers Greg
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Howard B" <howardbandy@> wrote:
> >
> > Hi Greg --
> > 
> > No plug in is needed.  Information about stops is in the 
> documentation.
> > 
> > When AmiBroker is open, pull down the Help menu, Click Help 
> Contents, type
> > in "Trailing Stop" or "ApplyStop".  It's all there.
> > 
> > Howard
> > 
> > 
> > On 7/20/07, Greg <crootster@> wrote:
> > >
> > >   I am trying to put a trailing stop to a system I am building 
> but had
> > > heard I need a plug in of some kind.Any help would be greatly
> > > appreciated.
> > >
> > > Cheers Greg
> > >
> > >  
> > >
> >
>




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/