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

Re: [amibroker] EnterTrade and ExitTrade question



PureBytes Links

Trading Reference Links

Hello,

There are few things you are doing wrong.
First of all, to check if you are in the trade (i.e. have openend position)
you can not use single boolean flag, because
custom backtest operates on portfolio and can have multiple positions open.
Instead you should use 

FindOpenPos method of backtester object:
http://www.amibroker.com/guide/a_custombacktest.html

There are other mistakes too (like using array instead of number in Exit / Entry trade call)

You are getting error message because you are referring to uninitialized
object (you can calling ExitTrade when bINTrade is false and are attempting to
call openpos.Symbol).

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "tkoinaustin" <tkoinaustin@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Sunday, March 06, 2005 2:59 PM
Subject: [amibroker] EnterTrade and ExitTrade question


> 
> 
> I am having trouble using the new backtester. My code (shown below) 
> will error out on the "if( bInTrade == False) bo.ExitTrade
> (bar,openpos.Symbol,Ref(O,1));" and "if( bInTrade == False)
> bo.EnterTrade(bar, trd.Symbol, True, C, -10);" lines. The error I
> get is either error 18 "COM object variable is not initialized or
> has invalid type" or error 19 "COM method/function 'ExitTrade' call
> failed".
> 
> I suspect I am not initializing something properly, but I would
> appreciate a pair of eyes to look at this and see if something jumps
> out. I am using 4.70 RC 1. Thanks for any feedback.
> 
> Tom
> 
> ---------------------------------------------------------
> SetOption("UseCustomBacktestProc", True );
> 
> if( Status("action") == actionPortfolio )
> {
> // retrieve the interface to portfolio backtester
> bo = GetBacktesterObject();
> bo.PreProcess();
> for( bar = 0; bar < BarCount; bar++ )
> {
> // If not in trade, then get top positions in
> for( openpos = bo.GetFirstOpenPos(); openpos; openpos =
> bo.GetNextOpenPos() )
> {
> bInTrade = False;
> for( cnt = 0,sig = bo.GetFirstSignal( bar ); Cnt++; cnt <
> numStocks , sig = bo.GetNextSignal( bar ))
> {
> if( sig.Symbol == openpos.Symbol) bInTrade = True;
> }
> if( bInTrade == False) bo.ExitTrade(bar,openpos.Symbol,Ref
> (O,1));
> }
> 
> for( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal
> ( bar ))
> {
> bInTrade = False;
> // If in trade and not top 5 signals, exit trade
> {
> for( trd = bo.GetFirstTrade(),Cnt = 0; Cnt++; trd =
> bo.GetNextTrade(), Cnt < numStocks )
> {
> if( trd.Symbol == sig.Symbol ) bInTrade = True;
> }
> if( bInTrade == False) bo.EnterTrade(bar, trd.Symbol, True,
> C, -10);
> }
> }
> 
> bo.ProcessTradeSignals( bar );
> }
> bo.PostProcess();
> }
> 
> numStocks = 5;
> SetOption("MaxOpenPositions", numStocks );
> PositionSize = -numstocks;
> PositionScore= 100-RSI();
> Buy = 1;
> Sell = Short = Cover = 0;
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 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
> 
> 
> 
> 
> 
> 
> 
>


------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.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/