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

[amibroker] Re: Help fix code please



PureBytes Links

Trading Reference Links

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 amibroker@xxxxxxxxxxxxxxx, "egregory99" <everett2010@xxx> 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 );
> }
>




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/