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

[amibroker] Help fix code please



PureBytes Links

Trading Reference Links

I'm trying to count the number of trades taken with 60 day vol. over 
and under 500,000. It is not counting right. The volume for over 
500,000 always shows 0. Thanks for the help.


SetCustomBacktestProc("");

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

    bo.Backtest(); // run default backtest procedure 

   SumMAE = 0; 
   NumTrades = 0;
   SumMFE = 0; 
   NumTrades2 = 0;
StaticVarSet("Counter1", 0); 
StaticVarSet("Counter2", 0); 

   // iterate through closed trades first 
   for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
() ) 
   { 
      // here we sum up maximum adverse excursions
       SumMAE = SumMAE + trade.GetMAE();
       NumTrades++; 
       SumMFE = SumMFE + trade.GetMFE();
       NumTrades2++;

Counter1 = StaticVarGet("Counter1"); 
Counter2 = StaticVarGet("Counter2"); 
V60 = MA(V, 60); 
BI = BarIndex(); 
LVBI = LastValue(BI); 
if (V60[LVBI] > 500000) 
    Counter1 = Counter1 + 1; 
else 
    Counter2 = Counter2 + 1; 
StaticVarSet("Counter1", Counter1); 
StaticVarSet("Counter2", Counter2);
   } 

   // iterate through eventually still open positions 
   for( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos
() ) 
   { 
       SumMAE = SumMAE + trade.GetMAE();
       NumTrades++; 
       SumMFE = SumMFE + trade.GetMFE();
       NumTrades2++;

   } 
   averageMAE = SumMAE / NumTrades; 
   bo.AddCustomMetric( "Avg. adverse excursion", averageMAE ); 
   averageMFE = SumMFE / NumTrades2; 
   bo.AddCustomMetric( "Avg. favorable excursion", averageMFE );

bo.AddCustomMetric( "Volume > 500,000", Counter1 );
bo.AddCustomMetric( "Volume < 500,000", Counter2 );
} 



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