Hello Thomas,
Thank you very much for your close interest. I will also try your solution.
Today, I have found my answer in the group mail archive. I am sorry for
taking your time before completely investigating the solution in the
previous e-mails. Here's what I have found (it works- with one letter
correction as enrybar-entrybar):
------------------------------------------------------------------------------
/*Custom Backtesting*/
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio){
bo=GetBacktesterObject();
bo.Backtest(1);
dt = DateTime();
bi = BarIndex();
for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
{
SetForeign( trade.Symbol ); // need to switch the symbol
entrybar = LastValue( ValueWhen( dt ==
trade.EntryDateTime, bi ) );
test= C[ enrybar ]; // we need scalar value
test1= HHV(C,20) ;
test1 = test1[ entrybar ]; // we need scalar value
trade.AddCustomMetric("test",test);
trade.AddCustomMetric("test1",test1);
}
bo.AddCustomMetric("Marker","Marker");
bo.ListTrades();
}
Best regards,
Tomasz Janeczko
amibroker.com
------------------------------------------------------------------------------
Here is the link:
http://finance.groups.yahoo.com/group/amibroker/message/119866
Thank you again to everybody for sharing their knowloedge in the group.
Best regards,
Ilhan Ketrez
On Mon, Nov 17, 2008 at 8:30 PM, Thomas Z. <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have fixed your code:
>
>
> Buy = Cross( C, MA( C, 10 ) );
> Sell = Cross( MA( C, 10 ), C );
>
> trend = EMA( C, 5 ) / EMA( C, 21 );
> AddToComposite( C, "~MyTrend_" + Name(), "X", atcFlagEnableInBacktest |
> atcFlagDefaults );
>
>
> function FindValueAtDateTime( input, dt, Value )
> {
> found = -1;
>
> for ( i = 0; i < BarCount AND found == -1; i++ )
> {
> if ( dt[ i ] == Value )
> found = i;
> }
>
> return IIf( found != -1, input[ found ], Null );
> }
>
> SetCustomBacktestProc( "" );
>
> if ( Status( "action" ) == actionPortfolio )
> {
> bo = GetBacktesterObject();
> bo.PreProcess();
> dt = DateTime();
> sc = 1;
>
> for ( i = 1; i < BarCount; i++ )
> {
> for ( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i )
> )
> {
> if ( sig.IsEntry() )
> {
> //VarSet("trendd"+sc,Foreign("~MyTrend", "C"));
> sc = sc + 1;
> }
> }
>
> bo.ProcessTradeSignals( i );
> }
>
> tc = 1;
>
> for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
> {
> TrendArray = Foreign( "~MyTrend_" + trade.Symbol, "C" );
> //tr = VarGet("trendd"+tc);
> Trend = FindValueAtDateTime( TrendArray, dt, trade.ExitDateTime );
> trade.AddCustomMetric( "Trend", Trend ); //tr should be here instead
> of a
> tc = tc + 1;
> }
>
> bo.PostProcess();
> }
>
>
> Thomas
> www.PatternExplorer.com <http://www.patternexplorer.com/>
>
>
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf
> Of Ilhan Ketrez
> Sent: Sunday, November 16, 2008 9:17 PM
> To: [email protected]
> Subject: Re: [amibroker] Adding custom metrics
>
> Hello,
>
> I still couldn't achieve... Below please find a work summary and my code. I
> will be glad to see your comments&help. Thanks in advance.
>
> 1- The operation is to examine the trades of a single ticker in depth.
> 2- Passing of one formula (trend) to composite is OK. I can see it appear
> in
> tickers.
> 3- I desired to check Buy signals with a loop. And insert the values of the
> composite to a static array buy VarSet. This should be added by date
> sequence by the signals loop.
> 4- Then, get the new static array variables in the trades loop by varget
> and
> add the custom metrics.
>
> The problem is: Getting the composite array values into CB doesn't seem
> possible.
> Here is the code:
>
> trend = EMA(C,5) / EMA(C,21);
> AddToComposite
> (C, "~MyTrend", "X", atcFlagEnableInBacktest| atcFlagDefaults );
> SetCustomBacktestProc
> ("");
> if
> ( Status("action") == actionPortfolio)
> {
> bo =
> GetBacktesterObject();
> bo.PreProcess();
> //
> sc =
> 1;
> for (i = 1; i < BarCount; i++)
> {
> for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
> {
> if( sig.IsEntry() )
> {
> //VarSet("trendd"+sc,Foreign("~MyTrend", "C"));
> a =
> Foreign("~MyTrend", "C"); //for testing purpose
> sc = sc +
> 1;
> }
> }
> bo.ProcessTradeSignals(i);
> }
> tc =
> 1;
> for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
> {
> //tr = VarGet("trendd"+tc);
> trade.AddCustomMetric(
> "Trend", a); //tr should be here instead of a
> tc = tc +
> 1;
> }
> bo.PostProcess();
> }
> System...
> 2008/11/16 İlhan Ketrez <[EMAIL PROTECTED]>
> Hello,
>
> Not complete yet but "AddToComposite" hint seems to be enough for me..
> Thank you very much.
> 2008/11/16 Thomas Z. <[EMAIL PROTECTED]>
>
> Hello,
>
> it is be possible.
>
> You have to store the CCI Value through AddToComposite for each symbol and
> have to load it in the CBI through the foreign function.
> Additionally you have to use a loop to iterate through all bars and all
> closed trades to add the CCI value from the bar where the trade has been
> closed.
>
>
> Thomas
> www.PatternExplorer.com <http://www.patternexplorer.com/>
>
>
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf
> Of Ilhan Ketrez
> Sent: Saturday, November 15, 2008 11:05 PM
> To: [email protected]
> Subject: Re: [amibroker] Adding custom metrics
>
> Still no replies.
>
> I wonder if this is possible in Amibroker.
>
> A yes/no response or a link to an example document can also be very
> helpful.
>
> Thank you.
>
>
>
> 2008/11/14 İlhan Ketrez <[EMAIL PROTECTED]>
> Thank you but it doesn't work that way, i.e. it doesn't give the entry CCI.
> To clarify, I want to see the entry CCI values in the yellow areas of the
> attached picture.
> Could you please elaborate your response by providing an example?
>
> Thank you very much.
> On Fri, Nov 14, 2008 at 10:04 PM, Ara Kaloustian <[EMAIL PROTECTED]> wrote:
> Entry for "CCI" should be just "CCI" - not "trade.CCI"
>
> ----- Original Message -----
> From: İlhan Ketrez
> To: [email protected]
> Sent: Friday, November 14, 2008 12:00 PM
> Subject: [amibroker] Adding custom metrics
>
> Dear friends,
>
> Regarding the addition of custom metrics to the backtest report, to
> simplify
> my question please find below a script from the AB documentation. Simply, I
> want to add, for example, CCI value, RSI value and various entry bar
> conditions instead of Initial risk or R multiple below.
>
> In other words, just like trade.score gives entry score, I want to add
> "trade.cci" as entry cci to the backtest report.
>
> Thank you in advance for your help.
>
> Best regards,
> Ilhan
>
> SetCustomBacktestProc("");
> MaxLossPercentStop = 10; // 10% max. loss stop
> /* Now custom-backtest procedure follows */
> if
> ( Status("action") == actionPortfolio )
> {
> bo =
> GetBacktesterObject();
> bo.Backtest(
> 1); // run default backtest procedure
> SumProfitPerRisk =
> 0;
> NumTrades =
> 0;
> // iterate through closed trades first
> for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
> {
> // risk is calculated as the maximum value we can loose per trade
> // in this example we are using max. loss stop
> // it means we can not lose more than (MaxLoss%) of invested amount
> // hence ris
> Risk = ( MaxLossPercentStop /
> 100 ) * trade.GetEntryValue();
> RMultiple = trade.GetProfit()/Risk;
> trade.AddCustomMetric(
> "Initial risk $", Risk );
> trade.AddCustomMetric(
> "R-Multiple", RMultiple );
> trade.AddCustomMetric(
> "Trend", trend );
> SumProfitPerRisk = SumProfitPerRisk + RMultiple;
> NumTrades++;
> }
> expectancy3 = SumProfitPerRisk / NumTrades;
> bo.AddCustomMetric(
> "Expectancy (per risk)", expectancy3 );
> bo.ListTrades();
> }
>
>
>
>
> ------------------------------------
>
> **** IMPORTANT ****
> This group is for the discussion between users only.
> This is *NOT* technical support channel.
>
> *********************
> TO GET TECHNICAL 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
>
> *********************************
> Yahoo! Groups Links
>
>
>
>
>
>
>
> ------------------------------------
>
> **** IMPORTANT ****
> This group is for the discussion between users only.
> This is *NOT* technical support channel.
>
> *********************
> TO GET TECHNICAL 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
>
> *********************************
> Yahoo! Groups Links
>
>
>
>