PureBytes Links
Trading Reference Links
|
Hi,
I tried the code provided below for long positions in a portifolio
mode and it did not trigger exists as much as I expected. This is
assuming that the variable 'BuyPrice' is the actual buy price.
But, I am not sure if 'BuyPrice' represents the actual buy price used
by the backtester. I could not find info that clearly defines what
'BuyPrice' exactly is.
pct=IIf((MA(C,2)-BuyPrice)/BuyPrice > 0.5,5,9999);
ApplyStop(stopTypeTrailing,stopModeRisk,pct,1,True);
--- In amibroker@xxxxxxxxxxxxxxx, nikku <nikku@xxxx> wrote:
>
> Hi Clement
>
> I wish I could take credit for this, but as I mentioned, I can't - it
> was given to me by Walt who frequents this board.
>
> Yes, this stop is easily adaptable for short positions. Here is the
> code. See the pct line for the changes.
>
> shortat=shortPrice;
> MinGainPct=.04;
> trailPct=15;
> pct=IIf((shortat-MA(C,2))/shortat > MinGainPct,trailPct,9999);
> ApplyStop(stopTypeTrailing,stopModeRisk,pct,1,True);
>
> Re: your question about the stop changing throughout the trading day, I
> am not sure how it would respond if applied to intraday data as I use
> only EOD data myself. However, I don't /think/ it would matter - the
> code should behave in the same manner. Someone else who is more
familiar
> with the 'shortprice' world may be able to help you if you run into
> problems. Good luck with it.
>
>
> Clement Chin wrote:
>
> > Hi, Nikku,
> >
> > Can this same stop be applied to Short Sell position? Do I need to
change
> > anything?
> >
> > Since the stop is using current Close in calculation, I assume it will
> > change through out the trading day. Am I right?
> >
> > Thanks in advance. This is a good piece of work.
> >
> > C.C.
> >
> >
> >
> > -----Original Message-----
> > From: nikku [mailto:nikku@x...]
> > Sent: Wednesday, February 02, 2005 1:45 AM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: Re: [amibroker] Trailing sttops
> >
> >
> > 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.
> >
> >
> >
> >
> >
> > 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
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Check AmiBroker web page at:
> > http://www.amibroker.com/
> >
> > Check group FAQ at:
> > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> >
> >
> > *Yahoo! Groups Sponsor*
> > ADVERTISEMENT
> >
> >
> > *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/
|