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

Re: [amibroker] Help - Portfolio Backtester Issues



PureBytes Links

Trading Reference Links

hi,
 
concerning question 1.1,    I do not see that happening, or maybe I misunderstood your question. I used your code and added a simple system (see below). It will write all trades to the file, not just the last ones. According to the "manual" you will get all trades.
 
rgds, Ed
 
 
SetCustomBacktestProc("");

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

   fh =
fopen( "C:\\TestFile.trt", "w"
);

    bo =
GetBacktesterObject
();
    bo.BackTest();
// High-Level backtest

    dt =
DateTime
();

    Initial_Stop =
"0"
;

    
// if Initial Stop data is not available then 0 placeholder should be used.


   
for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) { // iterate through closed trades


      
if
( trade.IsLong ) {
      
         Long_Short =
"L"
;

        }
else
{

            Long_Short =
"S"
;

        }

        String =  trade.Symbol +
" " + Long_Short + " " + NumToStr(trade.EntryDateTime,formatDateTime) + " " + NumToStr( trade.ExitDateTime, formatDateTime
)
        +
" " + Initial_Stop + " " + trade.EntryPrice + " "
+ trade.ExitPrice;

      
if
( fh ) {
      
         
fputs( string + "\n"
, fh );
        
        }
          
     }

   
fclose
( fh );

}



// Your trading system here...

SetOption("MaxOpenPositions", 50
);
PositionSize = -15
;
SetTradeDelays(1,1,1,1
);
PositionScore = 50 - Ref(StochK(15),-1
);

Buy = C > EMA(C,20); Buy = Ref(Buy,-1); BuyPrice = O
;
Short = C < EMA(C,20); Short = Ref(Short,-1); ShortPrice = O
;
Sell = 0
;
Cover = 0
;

ApplyStop( stopTypeNBar,stopModeBars,4,ExitAtStop = 1,Volatile = False, ReentryDelay = 1
);

SellPrice = C
;
CoverPrice = C
;

// stop signals are implemented and redundant signals are removed

Equity(1
);

SetChartOptions(0, chartShowDates
);
GraphXSpace = 5
;
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 = 0
);
PlotShapes(IIf(Cover,shapeHollowUpArrow,0),colorGold, layer = 0, yposition = CoverPrice, offset = 0
);


 
 
 
 
 
 
 
 
 
 
 
 
 
 
----- Original Message -----
From: dpweir
Sent: Friday, September 16, 2005 1:14 PM
Subject: [amibroker] Help - Portfolio Backtester Issues

Hello

 

I have been working on code to produce output from the backtester which meets a third party tool format, Tradesim’s Universal text Trade Database. Unable to produce this format so far, is the only reason why I have not ditched Metastock all together (I understand there is an exe available to do this but it does not look at an initialstop variable and requires a few too many button clicks for lazy me), so I am anxious to get this working.

 

Also I think this may be a another good example of using the PBI (hint hint Thomas)

 

I have posted the code below. The issues I have, are listed below and any input on how to resolve or work around these would be very much appreciated. Thomas any input appreciated =)

 

  1. Trade List

 

1.1    If I run the individual backtest, I only get the last symbols results.  Can the script be altered so all symbols are listed with their results ?

 

1.2    Portfolio backtest.  If we are unable to get the individual backtester working, what configuration would be required to get all possible trades using the portfolio backtester ?

 

  1. Date

 

I have changed my regional settings so the date is now in the format of yyyy/mm/dd, however there appears to be no option in my regional settings to have the date in the format of yyyymmdd , which is the format requirement.

 

  1. Initial stop value. 

 

I was going to leave this for a separate post,  but I feel like we are on a roll.  Is there also anyway to get the value of atr(period) at the first bar (or bar before) the entry signal ? This value is used for position sizing within Tradesim.

 

Many, many thanks.

 

Now the code,

 

/* Tradesim - Universal text Trade Database Version 1.0

Original sample code from PBI Collected Documentation, 'How to create a Trade List By ShortFox'

 

Requirements:  To generate YYYYMMDD output, declare it in your regional settings */

 

Buy = 0; Sell = 0; Short = 1; Cover = 0;

 

SetCustomBacktestProc("");

 

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

{

    fh = fopen( "C:\\TestFile.trt", "w" );

 

    bo = GetBacktesterObject();

    bo.BackTest(); // High-Level backtest

    dt = DateTime();

 

    Initial_Stop = "0";

    // if Initial Stop data is not available then 0 placeholder should be used.

 

    for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )

    { // iterate through closed trades

        if ( trade.IsLong )

        {

            Long_Short = "L";

        }

        else

        {

            Long_Short = "S";

        }

        String =  trade.Symbol + " " + Long_Short + " " + NumToStr(trade.EntryDateTime,formatDateTime) + " " + NumToStr( trade.ExitDateTime, formatDateTime )

        + " " + Initial_Stop + " " + trade.EntryPrice + " " + trade.ExitPrice;

       if ( fh )

          fputs( string + "\n", fh );

    }

 

    fclose( fh );

}

 

// Your trading system here...

Buy = C > EMA(C,20);

Sell = C < EMA(C,20);

 

 

 





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





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS