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 [email protected], "Greg" <[EMAIL PROTECTED]> 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 [email protected], "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
> > >
> > >
> > >
> >
>