Two things I can see. The primary one is the statement:

> V60 = MA(V, 60);

This is inside the custom backtest routine, which is not in the
context of any particular stock, so what is the "V" array? Which stock
is it for?

To use volume data like this inside a custom backtest routine, you
need to pass it from the main AFL code as a composite symbol and then
retrieve it with Foreign inside the custom backtest (at least that's
how I would do it). Take a look at the file "AmiBroker Custom
Backtester Inferface.pdf" in the files section here. It has an example
that does exactly that.

The other point, which is more just a clarification, is should the
500K be volume in number of shares or value of shares in dollars?

And as a simplification, you don't need to use static variables to
store the counters, just ordinary variables would do. It's all inside
the same backtest routine.

Regards,
GP


--- In [email protected], "egregory99" <[EMAIL PROTECTED]> wrote:
>
> 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 );
> }
>


Reply via email to