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

[amibroker] Re: How to add a column of MA30 of cum profit into the tradelist of the backtest



PureBytes Links

Trading Reference Links

Hi,

After some reading, now I am able to put up some codes as attached. I 
want to add two custom per-trade metrics. One is "custom cum profit", 
this metrics already appear in the built-in backtester, I add this as 
custom metrics in order to confirm that I am in the right direction. 
The second custom metrics is what I really need to add, that is "MA30 
of cum profit".

I succeeded in adding the first custom metrics "custom cum profit", 
but failed in getting the second done. The backtester shows zero 
for "MA30 of  cum profit"" the first 30 trades and blank from the 
31th trade.  Did I miss something here, why I cannot use the function 
MA() here correctly ?

thanks for any help

huanyan

==========================================================

SetCustomBacktestProc(""); 


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

    bo.Backtest(1); // run default backtest at notradelist mode

   Cumprofit = 0; 
   NumTrades = 0; 
   MA30_profit=0;

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

       Cumprofit = Cumprofit+ trade.Getprofit(); 

       trade.AddCustomMetric("custom cum profit",Cumprofit  ); // 
value of this metrics should be same as the built-in "cum.profit"
       


       NumTrades++; 

       if(numtrades>=30)
       {MA30_profit=MA(Cumprofit,30);}

       trade.AddCustomMetric("MA30 of cum profit",MA30_profit  ); 
   } 

       bo.ListTrades(); 

} 


//===========a simple trading system ================

fast = Optimize("fast", 12, 5, 20, 1 ); 
slow = Optimize("slow", 26, 10, 25, 1 ); 
Buy=Cross(MACD(fast,slow),Signal(fast,slow)); 
Sell=Cross(Signal(fast,slow),MACD(fast,slow)); 

Short=Sell;
Cover=Buy;






--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Start with the document titled "AmiBroker Custom Backtester 
> Interface.pdf" found in the Files section of this group published 
by 
> gp_sydney:
> 
> http://f1.grp.yahoofs.com/v1/sPtkSfaX2ek2RCVbqqJOCJA2R_-
> armYEr2K2MmIWnAHp_8p2ZKxwE4WR0554peVNTIdd--
> CzFINIbYE5z51vkgAozgCxi0yI/AmiBroker%20Custom%20Backtester%
> 20Interface.pdf
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "huanyanlu" <joesan99@> wrote:
> >
> > Hi, 
> > I have a simple question about custom backtesting.
> > I want to add a column of 30-trades average of the cum of profit 
> into 
> > the tradelist of the backtest result. How to implement this in 
AFL ?
> > 
> > Thanks for any help
> > 
> > huanlan
> >
>



------------------------------------

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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/