PureBytes Links
Trading Reference Links
|
Hello
The answer involves an analysis of this part of the code - keep it in
mind for what follows
*pct=IIf((MA(C,2)-buyat)/buyat > MinGainPct,trailPct,9999);*
MinGainPct is expressed as .04 because of the* (MA(C,2)-buyat)/buyat*
element of this line of code. Let's say that the close for the past two
days has been $10.00. We have bought at $10.50. The calculation for
'pct' would then be
MA(C,2)-buyat/buyat
($10-$10.5)/$10.5 = app.-0.0476
At this moment,
*(MA(C,2)-buyat)/buyat IS NOT GREATER THAN MinGainPct
*(Remember, MinGainPct has been set at 0.04; -0.476 is clearly not
greater than 0.04)
*
*so the 'pct' variable will feed the trailing stop with 9999; in other
words, the trailing stop will kick in when 9999% of the profit has been
given back - this is just a way to say 'The trailing stop is NOT activated'.
Now let's say the closing price goes up and one day we close at $12.20;
the day before this, the close was $11.80. The MA(C,2) in this case will
be $12.00. If we insert this new number into the formula, we get
MA(C,2)-buyat/buyat
($12-$10.5)/$10.5 = app.0.143
At this moment,
*(MA(C,2)-buyat)/buyat IS GREATER THAN MinGainPct (which is 0.04)
*Now the 'pct' variable will feed the trailing stop with the 'trailpct'
value because the conditions for activation of the trailing stop have
been met - that is,
(MA(C,2)-buyat)/buyat [which now equals 0.143] has been calculated to be
greater than the MinGainPct (0.04).
Of course you can change the value of MinGainPct to suit your needs.
Trailstop does signify the amount you allow the trade to retrace (once
it gets past the MinGainPct threshold) before exiting.
Hope this helps
Andrew Z wrote:
> Hey all,
>
> > Hello
> > Walt was kind enough to provide me with the following code - I hope he
> > doesn't mind if I share it around. This is something you can try, and
> > maybe you can adapt it if it isn't providing exactly what you need.
> > Basically, it takes care of the trailing stop which kicks in after
> > *MinGainPct* amount of profit has been reached. The trailing stop will
> > close the position after *trailPct* of the profit beyond the *MinGainPct
> > *profit has been given back I think you have to set up the hard stop
> > 'behind the entry' separately, but that shouldn't be a problem.
> >
> > buyat=BuyPrice;
> > MinGainPct=.04;
> > trailPct=15;
> > pct=IIf((MA(C,2)-buyat)/buyat > MinGainPct,trailPct,9999);
> > ApplyStop(stopTypeTrailing,stopModeRisk,pct,1,True);
>
> Being a newbie, i'm a little confused by this. Why are MinGainPct and
> trailPct not expressed in the same manner? Does .04 signify 4%? If so,
> why not express it as a whole number like trailPct?
>
> Also, does trailPct signify the % amount you allow to retrace before
> exiting?
>
> Thanks,
>
> Andrew.
>
>
> Check AmiBroker web page at:
> http://www.amibroker.com/
>
> Check group FAQ at:
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
>
> ------------------------------------------------------------------------
> *Yahoo! Groups Links*
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/amibroker/
>
> * To unsubscribe from this group, send an email to:
> amibroker-unsubscribe@xxxxxxxxxxxxxxx
> <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
--
The majority meet with failure because of their lack of persistence in creating new plans to take the place of those which fail.
------------------------ Yahoo! Groups Sponsor --------------------~-->
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> 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/
|