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

Re: [amibroker] custom column to backtest results? passing value from exploration?



PureBytes Links

Trading Reference Links

Thanks Graham .
Yes, CBT seems to be lots of fun.


This is much better I think (no trade delays):

AddToComposite(RSI(14), "~RSIT-" + Name(),"C", 1|2|64 );

SetCustomBacktestProc( "" );

function FindValAtDateTime( array, dt, Value )
{
   found = -
1;
   
for( i = 0; i < BarCount AND found == -1; i++ )
   {
      
if( dt[ i ] == Value ) found = i;
   }

   
return IIf( found != -1, array[ found  ], Null );
}


if( Status("action") == actionPortfolio )
{
   bo =
GetBacktesterObject();

   bo.Backtest(
1);


   dt =
DateTime();


   
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
   {
      RSI_Trigger =
Foreign("~RSI-T-" + trade.symbol,"C" )<20;
      RSI_Val =
Foreign("~RSI-T-" + trade.symbol,"C" );

      ValAtEntry = FindValAtDateTime( RSI_Trigger, dt, trade.EntryDateTime );
      trade.addcustommetric(
"RSI_Trigger",    Valatentry);

      ValAtEntry = FindValAtDateTime( RSI_Val, dt, trade.EntryDateTime );
      trade.addcustommetric(
"RSI_Val",    Valatentry);


   }

bo.listTrades();
}




Graham wrote:
Sorry to day this, but this method will not work.
1. you are using and array value within a bar loop, which will not
give you correct results
2. the symbol that is au8tomatically referred to in the custom
backtest code is the current value of account equity. Any reference to
other symbols needs to use the foreign functions and the function
referred to later in this response.
3. you have not given the variables for the trigger type any array
identification, so only the last value calculated will be passed out
of the loop, you may also find you need to initialise the variables
before the loop to give them default values.
4. the variables to be added to custom metric will need to be further
identified so that the loop through the trades at the end will know
which result to use

I will not give complete answers with full coding as the time for this
would be longer than I have to type this. Half the fun is the
frustration as you learn all the coding techniques, the other half is
the hours used in the many attempts to get it right. In some cases
many many many many attempts.

You will need to pass the values of the indicators for each symbol, or
at least the values of which signal condition prompted the trade entry
This can be done via a few methods of which the easiest has been the
use of composite symbols. Use of this also requires a function to read
the foreign composite symbol and return the value at that bar. Tomasz
has provided a basic function for this which can be utilised called
FindEquityAtDateTime. This has been posted somewhere so search for it.
If you are using a new beta I believe staticvarset allows for arrays
instead of single value. This may be able to be used to pass the
relevant values of signal type to the CBT from the normal AFL code
part.
One item to remember is that the Signal part of the CBT is the bar of
actual trade. So if you have a delay in your code between signal and
trade you will need to ensure your values are offset by this delay
amount so reading them matches the actual bar of trade.

3 & 4 above I find the best method is to use varset to identify the
variable against trade. I simply use something along these lines
in the singal loop
Varset( "VTrigger_"+sig.Symbol+"_"+dt[bar], FunctionToGetValue(inputs) )

in the trade loop
Varget( "VTrigger_"+trade.Symbol+"_"+trade.EntryDatetime )

I probably have not included everything you will need to know as that
would require a much longer response and time to put together all the
required items, but if you pull together avery example of code you can
find amidst the various sources of Ab code you will find enough to get
you started on the right path.

  



__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





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

__,_._,___