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

[amibroker] EnterTrade and ExitTrade question



PureBytes Links

Trading Reference Links


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;








------------------------ 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
--------------------------------------------------------------------~-> 

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/