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

Re: How to write a trading system ...



PureBytes Links

Trading Reference Links

On Sun, 23 Dec 2001, Eduardo wrote:

> I would like to know how can I write a trading system that I enter a order
> to buy when close cross over the xaverage and exits when the close cross
> under the xaverage and the short order is exactly the inverse. I would make
> this in the same strategy in order to optimize the lenght to be used by both
> strategies.

I'm at work and do not have my TS6, but would this be close:

Inputs: longlen(9), shortlen(13);
Vars: InTrade(false), DoBuy(false), DoSell(false);

if InTrade = false then begin		{ if not yet trading, check if trade exists }
	if Close > XAverage(Close, longlen) then begin
		Buy At Market
		InTrade = true;
	end else if Close < XAverage(Close, len) then begin
		Sell at Market;
		InTrade = true;
	end;
end else begin						{ check if should get out }
	if Close < XAverage(Close, longlen) then begin
		ExitLong;
		InTrade = false;
	end else if Close > XAverage(Close, shortlen) then begin
		ExitShort;
		InTrade = false;
	end;
end;