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

[amibroker] Re: Coding Problem



PureBytes Links

Trading Reference Links

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@xxx> 
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/