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

Re: [amibroker] How do I set about plotting the expectancy? [Re-post]



PureBytes Links

Trading Reference Links

Graham

Thanks for the reply and the pointers.
A few more functions there I need to befriend!
I'll spend some time with this and see where it leads me.

Regards

ChrisB

Graham wrote:

loop this through bar array and you can write the values to text file

SetCustomBacktestPr oc("");
if( Status("action") == actionPortfolio )
{
    bo = GetBacktesterObject ();
    bo.Backtest( 1);

    expectancy = SumProfit = 0;
    NumTrades = 0;
 

fw = fopen(...... ......... ...... , "w" )
for(i=0;i<barcount;i++ )
{
   expectancy = SumProfit = 0;
    NumTrades = 0;

    for( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
    {
        SumProfit = SumProfit + trade.GetProfit( );
        NumTrades++;
        expectancy = SumProfit/trade. TickSize/ trade.PointValue /NumTrades;

    }
    for( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
    {
        SumProfit = SumProfit + trade.GetProfit( );
        NumTrades++;
        expectancy = SumProfit/trade. TickSize/ trade.PointValue /NumTrades;
    }

if(fw) fputs(...... ......... ......... ......... , fw );

}
if(fw) fclose(fw);

    for( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
    {
        SumProfit = SumProfit + trade.GetProfit( );
        NumTrades++;
        expectancy = SumProfit/trade. TickSize/ trade.PointValue /NumTrades;
        trade.AddCustomMetr ic("Expectancy-Pips", expectancy );
    }

    for( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
    {
        SumProfit = SumProfit + trade.GetProfit( );
        NumTrades++;
        expectancy = SumProfit/trade. TickSize/ trade.PointValue /NumTrades;
        trade.AddCustomMetr ic("Expectancy-Pips", expectancy );
    }
    bo.AddCustomMetric( "Total Expectancy-Pips", expectancy );
    bo.ListTrades( );
}


--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriti ng.com

On 23/01/2008, ChrisB <kris45mar@xxxxxx net.au> wrote:
Graham/others

2 a.m. now.
Spent the night going through Herman's IntroToAtc.pdf and help files.

I am probably way off track here, but ....

Seems to me I still need to feed an array into the AddtoComposite( array,...) function.
It also seems to me that to do this I need to somehow extract this from the CBT code for expectancy:

************
SetCustomBacktestPr oc("");
if( Status("action") == actionPortfolio )
{
    bo = GetBacktesterObject ();
    bo.Backtest( 1);

    expectancy = SumProfit = 0;
    NumTrades = 0;

    for( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
    {
        SumProfit = SumProfit + trade.GetProfit( );
        NumTrades++;
        expectancy = SumProfit/trade. TickSize/ trade.PointValue /NumTrades;
        trade.AddCustomMetr ic("Expectancy-Pips", expectancy );
    }

    for( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
    {
        SumProfit = SumProfit + trade.GetProfit( );
        NumTrades++;
        expectancy = SumProfit/trade. TickSize/ trade.PointValue /NumTrades;
        trade.AddCustomMetr ic("Expectancy-Pips", expectancy );
    }
    bo.AddCustomMetric( "Total Expectancy-Pips", expectancy );
    bo.ListTrades( );
}

*********

I would have thought then that if I could extract the Expectancy from the CBT into an array I might just as easily be able to plot this.
Looking at the COM documents does not make it immediately apparent how I do this.(mea culpa as a non programmer).

Apart from the AddCustomMetric (command, if that's what it's called) which tells the CBT to send the expectancy to the Backtester Report , is there anything else I can do get this from CBT bit into regular AFL array variable so I can just plot it?

In the meantime I am happy to just export this from the backtester into an Excel spreadsheet for the moment.

Regards

ChrisB



ChrisB wrote:

Thanks Graham

Of course!
from the Backtester results I can see the column with the expectancy figures.
Then I just export this to csv and plot this in Excel which is what I will do for the moment.
I will look at the Addtocomposite function again to see if I can extract that data into a composite symbol.
I guess though if I am only getting 30 trades per year on a given strategy that will be an array that will need padding of data, and may not look too pretty.

Regards

ChrisB

Graham wrote:

You could try exporting the expectancy to a text file and plot from this, or create a composite symbol


--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriti ng.com

On 21/01/2008, ChrisB <kris45mar@xxxxxx net.au> wrote:
Promised attachment:


ChrisB wrote:

I will try and re-phrase the question:

Anyone have any pointers as to how to Plot the running expectancy after
I have run a Backtest?

In Excel when I walk forward manually, I plot my Expectancy like this:

Currently I place these trade on a Demo account to acquire the data for
entries and exits.
This is quite time consuming.
I want to plot similar or the same in a pane after running a Backtest.
When Positive and rising switch back to trading this strategy.
When Negative and or Falling, stop using this strategy.

Any pointers in the right direction would be appreciated, but I suspect
this may involve more programming than
I am capable of and may wish to farm this out.

Regards

ChrisB
ChrisB wrote:
>
> The help files give code for including Expectancy in the backtest and
> Optimization.
>
> I am not familiar with the working of the CBT. I can get the expectancy
> to appear in a column in the backtester
>
> How would I extract the expectancy figures into an array so that I can
> plot this?
>
> Regards
>








__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___