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

Re: [amibroker] Portfolio Backtesting with Buy at Open and Sell at Close



PureBytes Links

Trading Reference Links

> I am in the process of ( doing / performing )
> research on a Trading Theory. Initial results prove promising.
>
> I am not asking for complete trading systems.... but would
> like anyone in the group who would like to contribute...their :
> Entry's
> Exits
> Stops ( applystops in afl )
>
> Thank you in Advance
> Anthony

Surprised nobody's chimed in here yet, unless they're doing so in private.
I'm not sure what your actual project is, but keep us posted, especially if
profitable things happen (:-).

Here's an exit I've been playing with. The basic idea is sort of similar to
SAR, but more Fred Flintstone. Basically, it demands that price go in your
favor by the requested percentage every bar since entry, otherwise it exits.
InitialLongExit and InitialShortExit set how much slop to start with,
typically some percentage or ATR multiple off entry price.

Hope this is useful, to you or to someone. Comments, corrections, or other
ideas are of course welcome.

Dave


Here's the actual code; example calling code and notes follow:

------------------
function fExitExponential(Price, InitialLongExit, InitialShortExit, LongPct,
ShortPct, BuyDelay, ShortDelay) {
	LastDir = 0;
	LongFactor = 1 + (LongPct / 100);
	ShortFactor = 1 - (ShortPct / 100);
	ex = Null;
	BuyDelayed = Ref(Buy, -BuyDelay);
	ShortDelayed = Ref(Short, -ShortDelay);
	for(i = 0; i <= BarCount - 1; i++) {
		if(BuyDelayed[i] AND (LastDir != 1)) {
			LastDir = 1;
			ex[i] = InitialLongExit[i];
		} else if(ShortDelayed[i] AND (LastDir != -1)) {
			LastDir = -1;
			ex[i] = InitialShortExit[i];
		} else if(LastDir == 1) {
			ex[i] = ex[i - 1] * LongFactor;
			if(Price[i] < ex[i]) {
				LastDir = 0;
			}
		} else if(LastDir == -1) {
			ex[i] = ex[i - 1] * ShortFactor;
			if(Price[i] > ex[i]) {
				LastDir = 0;
			}
		}
	}
	return ex;
}
------------------

Here's an example of how it'd typically be set up and called:

InitialSlop = ATR(10) * 2;
Price = O; // for trading at Open
PctChange = 1.5;
BuyDelay = Status("BuyDelay");
SellDelay = Status("SellDelay");
Exit = fExitExponential(Price, Price - InitialSlop, Price + InitialSlop,
PctChange, PctChange, BuyDelay, ShortDelay);
Sell = Cross(Exit, Price);
Cover = Cross(Price, Exit);

NOTES:

- Since this works off Buy and Sell signals, you need to generate them
first, then call it.

- The exit signal is null when you're out of the market. As it stands, if
there's a entry signal on the same day as an exit, it won't be null where it
should be, but the exits are still correct.


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/