PureBytes Links
Trading Reference Links
|
Hi Tomasz,
Just to clarify what we meant by Position Management functions, in the WealthLab world the way a system works is you run a system test via your main loop. During that loop, a collection (linked list, or whatever) object is populated as each trade occurs. You can then loop through the positions collection and apply criteria for exit, monitor profits, etc. Below are some examples of WealthScript code I wrote to implement exit on first profitable bar and exit after higher high in equity line.
{------------------------------------------------------------------------------}
{ TM_nBarsSinceProfitable }
{ - Exits the current position based on the number of bars that have }
{ passed since the position was last in a profit. }
{------------------------------------------------------------------------------}
function TM_nBarsSinceProfitable(Bar, Position, N: integer; Annotate: boolean): integer;
begin
var i, LastProfBar: integer;
if PositionActive(Position) then begin
LastProfBar := 0;
for i := PositionEntryBar(Position) to Bar do begin
if PositionOpenProfitPct(i, Position) <= 0.0 then LastProfBar := LastProfBar + 1;
if LastProfBar = N then begin
if PositionLong(Position) then
SellAtMarket(Bar+1, Position, IntToStr(N) + ' Bars Since Profitable XL');
if PositionShort(Position) then
CoverAtMarket(Bar+1, Position, IntToStr(N) + ' Bars Since Profitable XS');
end;
end;
if Annotate then
if LastProfBar > 0 then AnnotateBar(IntToStr(LastProfBar), Bar, false, #Red, 8);
end;
end;
{------------------------------------------------------------------------------}
{ PS_HigherEquityHighs }
{ - Exits the current position on the next bar with a market order if N }
{ higher highs in the positions equity line have occured since the }
{ position was established. This function uses the bars closing value }
{ to calculate the higher equity high. }
{------------------------------------------------------------------------------}
function PS_HigherEquityHighs(Bar, Position, N: integer; Annotate: boolean): integer;
begin
var HigherHighs, i: integer;
var ProfitHigh: float;
HigherHighs := 0;
if Bar >= (PositionEntryBar(Position)+1) and (PositionActive(Position)) then begin
for i := PositionEntryBar(Position) + 1 to Bar do begin
if PositionOpenProfit(i, Position) > PositionOpenProfit(i-1, Position) then begin
HigherHighs := HigherHighs + 1;
ProfitHigh := PositionOpenProfit(i, Position);
if Annotate = true then AnnotateBar(IntToStr(HigherHighs), i, true, #Green, 8);
end;
end;
if HigherHighs = N then begin
if PositionLong(Position) then
SellAtMarket(i+1, Position, 'PS ' + IntToStr(N) + ' Equity HH XL');
if PositionShort(Position) then
CoverAtMarket(i+1, Position, 'PS ' + IntToStr(N) + ' Equity HH XS');
end;
end;
end;
The advantage to this becomes evident when you work in a multiple position environment. Because each trade is tracked independently, it becomes very easy to understand what is going on. It also makes it easier to Split a position (ie: sell half and trail the rest), on a trade by trade basis. Unfortunately I think it may require changes to the backtest engine to support this type of functionality, which is why I fear it may be too much work to implement.
IMHO, it also makes the code much easier to follow, although it will probably be a less efficient than the current method. FWIW, I also miss the AnnotateBar feature, which allowed me to mark the exit/exit signal names, which was great for multiple entry type systems (ie: "NR4" ,"MACD", "Equity HH XS").
Thanks for listening, and I hope that helps clear up what we referring to.
Daniel
On Wed, 20 Oct 2004 22:19:08 +0200, Tomasz Janeczko wrote:
>
> Hello,
>
> "i think the feature i would miss the most is the Position
> Management. "
>
> I am not sure if you mean managing position size but
> if so, it is available here via PositionSize variable.
> http://www.amibroker.com/guide/h_backtest.html
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/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/
|