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

Re: [amibroker] Re: Nested Loops - Custom Backtester



PureBytes Links

Trading Reference Links

david,
 
below a complete test system including this code. A snapshort of the output in the AA window looks like this:
 
 Sig: AMZN   Sig2: AMZN
 Sig: AMZN   Sig2: ESLR
 Sig: AMZN   Sig2: GNTX
 Sig: AMZN   Sig2: GPRO
 Sig: AMZN   Sig2: GROW
 Sig: IFIN   Sig2: IFIN
 Sig: IFIN   Sig2: OSIP
 Sig: IFIN   Sig2: VARI
 Sig: AMCC   Sig2: AMCC
 Sig: AMCC   Sig2: SEPR
 Sig: CELG   Sig2: CELG
 Sig: CORS   Sig2: CORS
 Sig: CYMI   Sig2: CYMI
 Sig: CYMI   Sig2: DAKT
 Sig: CYMI   Sig2: INTU
 Sig: CYMI   Sig2: JNPR
 Sig: CYMI   Sig2: SSRI
 Sig: AGIX   Sig2: AGIX
 Sig: AGIX   Sig2: AMAG
 Sig: AGIX   Sig2: CHRS
 Sig: AGIX   Sig2: COLM
 Sig: AGIX   Sig2: DRIV
 Sig: AGIX   Sig2: FLEX
 Sig: AGIX   Sig2: FORM
 Sig: AGIX   Sig2: LECO
 Sig: IDXX   Sig2: IDXX
 Sig: IDXX   Sig2: JBLU
 Sig: IDXX   Sig2: XMSR
 
etc.
 
 
regards, ed
 
 
 
 
SetOption("UseCustomBacktestProc", True );

if( Status("action") == actionPortfolio
) {

   bo =
GetBacktesterObject
();
   bo.backtest();
   
   
for(bar=0; bar<BarCount
; bar++) {
   
      
for
( sig = bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar)) {
      
         
for
( sig2 = bo.GetFirstSignal(bar); sig2; sig2=bo.GetNextSignal(bar)) {
         
            bo.RawTextOutput(
"\t" + "Sig: " + sig.Symbol + "   Sig2: "
+ sig2.Symbol  );
            
         }
         
      }
      
   }

}



SetOption("InitialEquity", 100000
);
SetOption("MaxOpenPositions", 4
);

PositionSize = -25
;
SetTradeDelays(0,0,0,0
);

Buy = Cross(RSI(14),30); Buy = Ref(Buy,-1); BuyPrice = O
;
Sell = Cross(70,RSI(14)); Sell = Ref(Sell,-1); SellPrice = O
;

Short = Sell; ShortPrice = O
;
Cover = Buy; CoverPrice = O
;

Buy = ExRem( Buy, Sell
);
Sell = ExRem( Sell, Buy
);
Short = ExRem( Short, Cover
);
Cover = ExRem( Cover, Short
);


SetChartOptions(0, chartShowDates
);
Plot(C,"C",1,64
);

PlotShapes(IIf(Buy,shapeUpArrow,0),colorWhite, layer = 0, yposition = BuyPrice, offset = 0
);
PlotShapes(IIf(Sell,shapeDownArrow,0),colorYellow, layer = 0, yposition = SellPrice, offset = 0
);
PlotShapes(IIf(Short,shapeHollowDownArrow,0),colorLightBlue, layer = 0, yposition = ShortPrice, offset = -15
);
PlotShapes(IIf(Cover,shapeHollowUpArrow,0),colorGold, layer = 0, yposition = CoverPrice, offset = -15 )
 
 
 
----- Original Message -----
Sent: Monday, July 02, 2007 8:41 PM
Subject: [amibroker] Re: Nested Loops - Custom Backtester

Ed,

Unfortunately, I cannot re-create your results here. I used a very
simple backtest, and copied your code verbatim, but the outer loop
still executes only for the first signal.

Thanks, though, for the suggestion,

David

--- In amibroker@xxxxxxxxxps.com, "Edward Pottasch" <empottasch@...>
wrote:
>
> hi,
>
> it seems to be possible. I ran this code on top of some backtest.
The results in the AA window show that both loops are used. If you
want to change a trade then you will have to change this setup. Here
I first run the backtest and then go through the signal object.
>
> Ed
>
>
>
>
> SetOption("UseCustomBacktestProc", True );
>
> if( Status("action") == actionPortfolio ) {
>
> bo = GetBacktesterObject();
> //bo.PreProcess(); // Initialize backtester
> bo.backtest();
>
> for(bar=0; bar<BarCount; bar++) {
>
>
> for ( sig = bo.GetFirstSignal(bar); sig;
sig=bo.GetNextSignal(bar)) {
>
>
> for ( sig2 = bo.GetFirstSignal(bar); sig2;
sig2=bo.GetNextSignal(bar)) {
>
> bo.RawTextOutput( "\t" + "Sig: " + sig.Symbol
+ " Sig2: " + sig2.Symbol );
>
>
> }
>
> }
>
> }
> //bo.PostProcess(); // Finalize backtester
>
> }
>
>
>
>
> ----- Original Message -----
> From: david.weilmuenster
> To: amibroker@xxxxxxxxxps.com
> Sent: Monday, July 02, 2007 5:18 PM
> Subject: [amibroker] Nested Loops - Custom Backtester
>
>
> Hi,
>
> In the Custom Backtester, I need to run a nested loop to examine
all
> signals in comparison to a given signal, and have tried the
following
> code to implement a nested loop:
>
> for ( sig = bo.getfirstsignal(bar); sig; sig = bo.getnextsignal
(bar))
>
> {
>
> for ( sig_2 = bo.getfirstsignal(bar); sig_2; sig_2 =
> bo.getnextsignal(bar))
>
> {
>
> ... logic to compare signals
>
> }
>
> }
>
> -------------------------------------------
>
> But, the code executes only for the first signal in the outer
loop.
> I.e., it runs the inner loop perfectly, but only for the first
signal
> in the outer loop.
>
> Any clues as to what I'm doing wrong? Maybe this isn't possible?
> Other approaches I should try?
>
> Thanks,
> David Weilmuenster
>

__._,_.___

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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___