Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Backtesting for Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:
trading system, amibroker

Better way to backtest by output an excel file


When we do the backtest, we always can only choice

“open” “high” “low” “close” “average” as our entry price.

In this way, we could precisely output our exact entry price

into an excel file. So that we could do more on the result

of backtesting.


Similar Indicators / Formulas

All in One
Submitted by Nahid about 14 years ago
Kase Peak Osc. V2 batu
Submitted by batu1453 over 10 years ago
Kase CD V2batu
Submitted by batu1453 over 10 years ago
Ichimoku
Submitted by prashantrdx over 10 years ago
Arvind' System
Submitted by akdabc over 14 years ago
Miftha remix for dse
Submitted by coolpace over 14 years ago

Indicator / Formula

Copy & Paste Friendly
Bars=1 + BarsSince( Day()!= Ref(Day(), -1));
NewDay = Day() != Ref(Day(), -1);

Plot(C,"",colorLime,128+styleNoLabel );

ExitTime = TimeNum()==134000;
RangeHigh = ValueWhen(NewDay, H);
RangeLow = ValueWhen(NewDay, L);
Buy = H > RangeHigh AND TimeNum()<134000;
Short = L < RangeLow AND TimeNum()<134000;
Sell=Short OR exittime;
Cover=Buy OR exittime;
Buy=ExRem(Buy,Sell); 
Sell=ExRem(Sell,Buy); 
Short=ExRem(Short,Cover); 
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy,shapeHollowUpTriangle,shapeNone),colorRed,0,L,IIf(Buy,-30,-25));
PlotShapes(IIf(Short,shapeDownTriangle,shapeNone),colorBlue,0,H,IIf(Short,-30,-25));
PlotShapes(IIf(exittime,shapeSmallSquare,shapeNone),colorBrightGreen,0,H,IIf(Sell,-30,-25));

BuyentryPrice=IIf(bars==1,O, RangeHigh );
ShortentryPrice=IIf(bars==1,O, RangeLow );

BT=fopen("c:backtest.csv","w");

y = Year(); 

m = Month(); 

d = Day();

for( i = 0; i < BarCount; i++ )

{

if( Buy[i] )

{

BTE=StrFormat("%02.0f/%02.0f/%02.0f,B,%.0f\n",Y[i],M[i],D[i],BuyentryPrice[i]);

fputs(BTE,BT);

}

if( Short[i] ) 

{

BTE=StrFormat("%02.0f/%02.0f/%02.0f,S,%.0f\n",Y[i],M[i],D[i],ShortentryPrice[i]);

fputs(BTE,BT);

}

if( exittime[i] ) 

{

BTE=StrFormat("%02.0f/%02.0f/%02.0f,S,%.0f\n",Y[i],M[i],D[i],C[i]);

fputs(BTE,BT);

}
}


fclose(BT);

2 comments

1. asad

tanksssssssssssss

2. tototjung

I don’t think this backtest represents real trading.
If I am not mistaken, Your AFL will trigger buy only if closing price above res, so You should use Closing price as BuyPrice. Forcing to use “BuyPrice=ValueWhen(Buy,e,1);” is cheating for two things :
1. You buy only if closing price confirm the break. This already remove a lot of cut loss transaction for false breakout.
2. The difference price range between your buy value and close oftenly huge and make a of difference in ending portofolio value.
Correct Me if I am wrongly read your AFL logic :)

regards,
toto

Leave Comment

Please login here to leave a comment.

Back