PureBytes Links
Trading Reference Links
|
Here is an idea to try (untested).
The key idea is switching the 2nd variable in ApplyStop
between values of 0 (ie, OFF) and 1 (percentage type stop).
If you want to use points rather than percentage then
additional code would be required in the form of IIF()
statements. For example, if you want the trailing stop to
be a percentage of profits rather than a percentage of
total value then you would need to add: StopNBarON =
IIF(StopNBarON,3,0);
BarsInTrade = barssince(buy);
InTradeProfit = ROC(BarsInTrade);
StopLossON = BarsInTrade < 10;//first 10 bars
TrailingStopON = InTradeProfit > 20;//
StopNBarON = !StopLossON AND !TrailingStopON;
ApplyStop(stoptypeloss,StopLossON,25);//exit
ApplyStop(stoptypetrailing,StopTrailingOn,15);//
ApplyStop(stoptypeNBar,StopNBarON,10);//
The above should work but it is untested so you might have
to make a few changes.
b
--- kw_odonian <kw_odonian@xxxxxxxxx> wrote:
> For backtesting, what would the code look like in a more
> complex exit
> strategy, say with the following rules:
>
> 1) Have a max. stop loss for initial N bars from entry
> bar.
>
> 2) If the trade is profitable after N bars and the profit
> lies between
> x and y percent, take profits
>
> 3) If the trade is profitable after N bars but the profit
> is higher
> than y percent, switch to trailing stop
>
> 4) Beyond N bars, if the open profit exceeds a certain
> level, tighten
> trailing stop - and this is also the point where I'd love
> to have a
> pyramiding capability.
>
> Any help would be appreciated!
>
> kw
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
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/
|