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

RE: [amibroker] Re: Custom Trade Metrics



PureBytes Links

Trading Reference Links

Ok,
use this then, remember you will only the HV for closed trades with this code, if you want open trades, you will need to do another loop;

function FindStuffAtDateTime( fx, dt, Value )

{

    found = -1;

    for( i = 0; i < BarCount AND found == -1; i++ )

    {

        if( dt[ i ] == Value ) found = i;

    }

    return IIf( found != -1, fx[ found - 1 ], Null );

}

if( Status("action") == actionPortfolio )

{

    bo = GetBacktesterObject();

    bo.Backtest();

    // iterate through closed trades first

    for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )

    {

    sym = trade.Symbol();

    myC = Foreign(sym, "C");

        HVtrade = 100* StDev(log(myC/Ref(myC,-1)),100)*sqrt(252);

    myHv = FindStuffAtDateTime(HVtrade, DateTime(), trade.EntryDateTime );

        trade.AddCustomMetric("HV", myHv );

    }

    bo.ListTrades();

}

Paul Ho

TrustNet

P O Box 212

Ashburton Victoria 3147

- paul.ho@xxxxxxxxxxxxxxx

(  0400059655
 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of C Alvarez
Sent: Monday, 20 June 2005 5:39 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Custom Trade Metrics

I still get blank values in the HV column. I think the problem is
that I am passing an array to AddCustomMetric when it expects a
value. I need to determine the index into HVtrade, so I can do
HVtrade[index].

Any ideas on how to get from the trade date to the index into
HVtrade?

Thank you,
Cesar

--- In amibroker@xxxxxxxxxxxxxxx, "Paul Ho" <paultsho@xxxx> wrote:
> I suggest you try the following
> SetCustomBacktestProc("");
> /* Now custom-backtest procedure follows */
> if( Status("action") == actionPortfolio )
> {
>     bo = GetBacktesterObject();
>     bo.Backtest(1); // run default backtest procedure
>    for(trade=bo.GetFirstTrade(); trade; trade=bo.GetNextTrade())
>    {
>       sym = trade.Symbol();
>       myC = Foreign(sym, "C" );
>       HVtrade = 100* StDev(log(myC/Ref(myC,-1)),100)*sqrt(252);
>       trade.AddCustomMetric("HV", HVtrade );
>    }
>     bo.ListTrades();
> }
>

> Paul Ho
>

>
>   _____ 
>
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
On Behalf
> Of C Alvarez
> Sent: Sunday, 19 June 2005 2:07 AM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: Custom Trade Metrics
>
>
> The HV column has all blanks in it.
>
> Thanks for the help. Here is the formula.
>
> Cey
>
> ////////////////////////////////////////////////////
>
> SetCustomBacktestProc("");
> /* Now custom-backtest procedure follows */
> if( Status("action") == actionPortfolio )
> {
>     bo = GetBacktesterObject();
>     bo.Backtest(1); // run default backtest procedure
>    for(trade=bo.GetFirstTrade(); trade; trade=bo.GetNextTrade())
>    {
>       sym = trade.Symbol();
>       SetForeign(sym );
>       HVtrade = 100* StDev(log(C/Ref(C,-1)),100)*sqrt(252);
>       RestorePriceArrays();
>       trade.AddCustomMetric("HV", HVtrade );
>    }
>     bo.ListTrades();
> }
> // trading system here
> Buy = MA(C,50) > MA(C,200) AND C >MA(C,200);
> Sell = C < MA(C,200);
>
> Buy = ExRem(Buy,Sell);
> Sell = ExRem(Sell, Buy);
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Paul Ho" <paultsho@xxxx> wrote:
> > Can you post your formula and results?
> > 
> > Paul Ho
> >
> > 
> >
> >   _____ 
> >
> > From: amibroker@xxxxxxxxxxxxxxx
[mailto:amibroker@xxxxxxxxxxxxxxx]
> On Behalf
> > Of C Alvarez
> > Sent: Saturday, 18 June 2005 1:17 PM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: [amibroker] Re: Custom Trade Metrics
> >
> >
> > I added the SetForeign call and the HV formula still does not
> work.
> > Is this something that I need to calculate manually?
> > Any more help?
> >
> > Thanks,
> > Cey
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Paul Ho" <paultsho@xxxx>
wrote:
> > > the problem is with this line "HVtrade = 100*
> > > StDev(log(C/Ref(C,-1)),100)*sqrt(250);
> > > you need to get the trade symbol and then use foreign to get
the
> > price array
> > > before doing your calculaltion
> > > 
> > > Paul Ho
> > >
> > > 
> > >
> > >
> > >   _____ 
> > >
> > > From: amibroker@xxxxxxxxxxxxxxx
> [mailto:amibroker@xxxxxxxxxxxxxxx]
> > On Behalf
> > > Of C Alvarez
> > > Sent: Saturday, 18 June 2005 4:21 AM
> > > To: amibroker@xxxxxxxxxxxxxxx
> > > Subject: [amibroker] Custom Trade Metrics
> > >
> > >
> > > I am trying to add the custom metric of what the Historical
> > > Volatility was when the trade was entered.
> > >
> > > I tried the following code, but all I get are blanks. Do we
not
> > have
> > > access to the price arrays? Or what am I doing wrong?
> > >
> > > Thank you,
> > > Cey
> > >
> > > Here is the code:
> > > SetCustomBacktestProc("");
> > > if( Status("action") == actionPortfolio )
> > > {
> > >    bo = GetBacktesterObject();
> > >    bo.Backtest(1);
> > >    for(trade=bo.GetFirstTrade(); trade; trade=bo.GetNextTrade
())
> > >    {
> > >            HVtrade = 100* StDev(log(C/Ref(C,-1)),100)*sqrt
(250);
> > >          trade.AddCustomMetric("HV", HVtrade);
> > >    }
> > >     bo.ListTrades();
> > > }
> > >
> > >
> > >
> > >
> > >
> > > 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 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/
> > >  
> > >
> > > *      To unsubscribe from this group, send an email to:
> > > amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > > <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?
> subject=Unsubscribe>
> > >  
> > >
> > > *      Your use of Yahoo! Groups is subject to the Yahoo!
Terms
> of
> > Service
> > > <http://docs.yahoo.com/info/terms/> .
> >
> >
> >
> >
> > 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 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/
> >  
> >
> > *      To unsubscribe from this group, send an email to:
> > amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?
subject=Unsubscribe>
> >  
> >
> > *      Your use of Yahoo! Groups is subject to the Yahoo! Terms
of
> Service
> > <http://docs.yahoo.com/info/terms/> .
>
>
>
>
> 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 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/
>  
>
> *      To unsubscribe from this group, send an email to:
> amibroker-unsubscribe@xxxxxxxxxxxxxxx
> <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
>  
>
> *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service
> <http://docs.yahoo.com/info/terms/> .




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 other support material please check also:
http://www.amibroker.com/support.html





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 other support material please check also:
http://www.amibroker.com/support.html





Yahoo! Groups Links