PureBytes Links
Trading Reference Links
|
Hello GP,
Thanks for the reply.
I wasn't really expecting a response but I'm so glad that you did as
you have explained it very well.
Many Thanks....
On a slightly different topic, as you've already been most helpful,
would you have any ideas/opinions with regard to my other recent post
entitled SAR Indicator (post # 117994)
Once again Thanks,
Chorlton
--- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@xxx>
wrote:
>
> Chorlton,
>
> The loop code does the same thing as the first three lines, but
allows
> you to remove extra buy signals as you go so that they don't affect
> the sell array (since sell signals are based on the date of buy
signals).
>
> The HighestSince line just says set hsb to the highest value of the
> AccDist array since the most recent buy signal (which is where you
can
> get a problem if there's a new buy signal while you're still
holding).
> Sell is then the AccDist value dropping more than 10% below that
> highest value. Note that hsb is an array in this case.
>
> The loop is broken into two main cases: when it's not holding
already,
> and when it is. When it's not holding, it's looking for buy signals.
> When it is holding, it removes any more buy signals and just looks
for
> sell signals. When not holding and a buy signal is encountered, it
> changes the state to holding (ie. doHold = True) and sets the
highest
> AccDist value (hsb) to the current bar's AccDist value. When
holding,
> it first checks for the current bar's AccDist value being higher
than
> the highest already recorded, and changes the highest to the new
> higher value if so, then checks to see if the current bar's AccDist
> value is more than 10% below the currently-recorded highest value.
If
> so, then that's a sell signal, in which case it sets the Sell array
to
> True at that bar, and changes the state to not holding (doHold =
> False). Note that hsb is a single value in this case, not an array.
>
> Hope this helps.
>
> Regards,
> GP
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "chorlton_c_hardy"
> <chorlton-c-hardy@> wrote:
> >
> >
> > Hello GP,
> >
> > Thanks for your detailed reply.
> >
> > Looking at the code posted, I think I will need to refer back to
the
> > manual just to ensure that I understand what every line of code
is
> > actually doing, as my programming is pretty basic!!! :-/
> >
> > However, I do appreciate your time in posting the answer.
> >
> > Many Thanks & All the best,
> >
> > Chorlton
> >
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@>
> > wrote:
> > >
> > > That's not really a trailing stop, since the AccDist line can
fall
> > as
> > > long as it doesn't exceed your limit.
> > >
> > > You could try something like:
> > >
> > > ad = AccDist();
> > > hsb = HighestSince(Buy, ad);
> > > Sell = ad < hsb*0.9;
> > >
> > > Note though that this will be upset by new buy signals before a
sell
> > > if the AccDist value has dropped somewhat from its highest
value
> > since
> > > the last buy. When you hit a new buy, hsb will then be the
highest
> > > since that buy, which may be lower than the highest value since
the
> > > original buy. This could allow AccDist to drop more than 10%
from
> > the
> > > highest value since the original buy without triggering a sell.
If
> > you
> > > want to avoid that, you'd probably need to generate the Sell
array
> > > iteratively using a loop, removing redundant Buy signals as you
go:
> > >
> > > ad = AccDist();
> > > Sell = False;
> > > hsb = 0;
> > > doHold = False;
> > > for (i = 0; i < BarCount; i++)
> > > {
> > > if (!doHold)
> > > {
> > > if (Buy[i])
> > > {
> > > doHold = True;
> > > hsb = ad[i];
> > > }
> > > }
> > > else
> > > {
> > > Buy[i] = False;
> > > if (ad[i] > hsb)
> > > hsb = ad[i];
> > > if (ad[i] < hsb * 0.9)
> > > {
> > > doHold = False;
> > > Sell[i] = True;
> > > }
> > > }
> > > }
> > >
> > > Regards,
> > > GP
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "chorlton_c_hardy"
> > > <chorlton-c-hardy@> wrote:
> > > >
> > > > Hello All,
> > > >
> > > > I'm tryin to code a trailing stop loss but am having a number
of
> > > > problems with writing the code.
> > > >
> > > > What I'm trying to achieve is:
> > > >
> > > > 1. Once a Buy signal appears from my system, the value of the
> > current
> > > > AccDist() Line should be recorded.
> > > >
> > > > 2. As long as the AccDist() moves upwards the trade should
remain
> > > > open.
> > > >
> > > > 3. However, once the AccDist() line falls by a certain
percentage
> > > > (say 10% for this example) from its Highest value since the
trade
> > was
> > > > opened, the trade should be stopped out.
> > > >
> > > > I have some code for a simple trailing stop based on the Low
of
> > the
> > > > price (see below) but I'm not sure how to modify it to
accomplish
> > the
> > > > above.
> > > >
> > > > Any ideas would be most welcome...
> > > >
> > > >
> > > > Initial = LLV(Low,5);
> > > >
> > > > stop[0] = Close[0];
> > > > for( i = 1 ; i < BarCount; i++)
> > > > {
> > > > if( Close[i] > stop[i-1])
> > > > {
> > > > stop[i] = Max( initial[i], stop[i-1] );
> > > > }
> > > > else { stop[i] = initial[i]; }
> > > > }
> > > >
> > > > Plot( stop, " Stop Loss", ParamColor("Color", colorCycle ),
> > ParamStyle
> > > > ("Style", styleDots | styleNoLine, maskDefault | styleDots |
> > > > styleNoLine ) );
> > > >
> > > >
> > > > Many Thanks in advance,
> > > >
> > > > Chorlton
> > > >
> > >
> >
>
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/
|