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

Re: [amibroker] Re: backtester mfe/mae calculation



PureBytes Links

Trading Reference Links

Hello,

Yes you can generate MAE/MFE in points and with any number of decimal digits.
Appropriate code looks as follows.

/* First we need to enable custom backtest procedure and 
** tell AmiBroker to use current formula 
*/ 

SetCustomBacktestProc(""); 

/* Now custom-backtest procedure follows */ 
if( Status("action") == actionPortfolio ) 
{ 
    bo = GetBacktesterObject(); 

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

   SumProfitPerRisk = 0; 
   NumTrades = 0; 

   // iterate through closed trades first 
   for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) 
   { 
       trade.AddCustomMetric("MAE $", StrFormat( "%.4f", 100 * trade.GetMAE() / trade.EntryPrice )  ); 
       trade.AddCustomMetric("MFE $", StrFormat( "%.4f", 100 * trade.GetMFE() / trade.EntryPrice ) ); 
   } 
    bo.ListTrades(); 
} 

// your trading system here 

Buy=....
Sell=....


Also note that MFE calculation for long trade is is:
(highest high price since entry) - (entry price)
and MAE is:
(lowest low price since entry) - (entry price)

And the calculation includes High-Low range of all bars since entry bar till exit bar.

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "murthysuresh" <money@xxxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, September 07, 2007 5:02 AM
Subject: [amibroker] Re: backtester mfe/mae calculation


> Tomasz
> Your note gave me the right perspective. I use IB on a 1 minute 
> timeframe datasournce when i use the backtester.  since i also use 
> the default backtester, it uses the 1 minute bar close for entry and 
> exits. There is usually good price movement within the 1 minute bar.
> 
> In comparision, the bracket trader data was realtime as the trade was 
> made in IB realtime and it provided MFE and MAE based on a finer data 
> resolution- close to realtime(alleast few seconds).
> 
> So when i compare the entry and exit prices, they dont match between 
> these 2 apps because of the resolution of the datasource I AM USING 
> are different in each case.
> 
> One thing that i observed is that the % resolution was to 2 decimal 
> places. This would not be significant in Stocks. But in Forex, the 
> pip value is trading in 4 decimal places. The significance can be 
> related as below
> Scenario #1:
> GBPUSD BUY 2.0258 SELL 2.0253 MFE 0.0007 
> MFE IN % =100* .0007/2.0253 = 0.034562781 %
> Backtester would round it to .03
> 
> Scenario #2: <notice there is a 1 pip difference between the MFE 
> values>
> GBPUSD BUY 2.0258 SELL 2.0253 MFE 0.0008 
> MFE IN % =100* .0008/2.0253 = 0.039500321 %
> Backtester would round it to .04
> 
> 1 pip difference can make a difference in my analysis because of the 
> rounding factor
> 
> The question is, "IS it possible to use 4 number decimal in the % 
> results provided by backtester?"
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> 
> wrote:
>>
>> Hello,
>> 
>> OK, I am sorry for harsh tone of my reply BUT...
>> how could I possibly help you without knowing basic details.
>> Let me point out some missing pieces from your e-mail:
>> 
>> >> Trade Long 
>> >> Date 06/09/2007 4:55 
>> 
>> You provided the date and time BUT... is it AM or PM?
>> Is it EST time zone or different one ? 
>> How can I duplicate your setup without knowing the time zone?
>> (I looked at charts and did not the prices you have pointed out
>> in the IB backfilled chart, so I *need* time/date AM/PM and time 
> zone you are in
>> - remember that IB is using LOCAL computer date time so 4:55 on 
> your computer
>> is not 4:55 on mine.
>> 
>> >> Ex. Price 1.36665 
>> >> % chg 0.04% 
>> >> Profit 4.03 
>> >> % Profit 0.04% 
>> >> Contracts 7320.11 
>> >> Position value 10000
>> >> Cum. Profit 4.03
>> >> # bars 4
>> >> Profit/bar 1.01
>> >> MAE -0.02%
>> >> MFE 0.04%
>> >> Scale In/Out 0/0
>> 
>> Why do you think these are wrong figures. In my opinion they are 
> correct.
>> As I don't know what time you were using and I can not verify it on 
> the chart
>> I need to *assume* now that the highest high since entry was equal 
> to exit price 
>> which is:  1.36665. Note that it is just assumption since I could 
> not verify it on true data.
>> 
>> If the above assumption is correct the MFE is correct:
>> 
>> Entry price: 1.36610
>> Max. Favourable Excursion: 1.36665 - 1.36610 = 0.00055
>> Now MFE in percent is = 0.00055 / EntryPrice =  0.04026 %
>> And that's what AB shows.
>> 
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>> ----- Original Message ----- 
>> From: "Tomasz Janeczko" <groups@xxx>
>> To: <amibroker@xxxxxxxxxxxxxxx>
>> Sent: Thursday, September 06, 2007 11:22 PM
>> Subject: Re: [amibroker] backtester mfe/mae calculation
>> 
>> 
>> >I am getting sick and tired of such e-mails.
>> > Why don't you assume the reverse, i.e. that bracket trader 
> calculation is wrong????
>> > 
>> > Plus you are comparing apples to oranges (percent to point), give 
> no info on periodicity you use,
>> > using of course WRONG settings in the backtester (see enormous 
> contracts number:
>> > 7320 EURUSD lots !!!!)
>> > 
>> > There is an article in the KB that you should read first about 
> setting up for forex.
>> > 
>> > Best regards,
>> > Tomasz Janeczko
>> > amibroker.com
>> > ----- Original Message ----- 
>> > From: "murthysuresh" <money@xxx>
>> > To: <amibroker@xxxxxxxxxxxxxxx>
>> > Sent: Thursday, September 06, 2007 10:53 PM
>> > Subject: [amibroker] backtester mfe/mae calculation
>> > 
>> > 
>> >> The backtester provides the mfe and mae in % only. When i 
> calculate 
>> >> it by hand and using the bracketTrader, it provides in value 
> which on 
>> >> further analysis does not transulate into matching % that 
> amibroker 
>> >> provides. 
>> >> here is the example.
>> >> 
>> >> for eg.
>> >> Ticker EUR.USD-IDEALPRO-CASH 
>> >> Trade Long 
>> >> Date 06/09/2007 4:55 
>> >> Price 1.3661 
>> >> Ex. date 06/09/2007 5:10 
>> >> Ex. Price 1.36665 
>> >> % chg 0.04% 
>> >> Profit 4.03 
>> >> % Profit 0.04% 
>> >> Contracts 7320.11 
>> >> Position value 10000
>> >> Cum. Profit 4.03
>> >> # bars 4
>> >> Profit/bar 1.01
>> >> MAE -0.02%
>> >> MFE 0.04%
>> >> Scale In/Out 0/0
>> >> 
>> >> 
>> >> Bracket trader and visually looking at buy/sell signals on the 
>> >> backtester chart provides the MFE and MAE to be 
>> >> MAE -0.0002
>> >> MFE 0.0008
>> >> 
>> >> 
>> >> I have 4.96 version amibroker. Is this a Bug? How can i extract 
> the 
>> >> MFE/MAE values instead of % from the backtester to confirm it.
>> >> regards
>> >> 
>> >> Seede.
>> >> 
>> >> 
>> >> 
>> >> 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
>> >> 
>> >> 
>> >> 
>> >> 
>> >>
>> > 
>> > 
>> > 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
>> > 
>> > 
>> > 
>> > 
>> >
>>
> 
> 
> 
> 
> 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
> 
> 
> 
> 
>


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/