Normal
[USER=55912]@Roller_1[/USER] funny enough I came across this today and i'm sure that you could modify the CBT code to achieve what you want ? or at least give you some ideasThe below example displays the yearly returns at the end of your back test reporthttps://alvarezquanttrading.com/amibroker-sample-code/[ATTACH=full]103914[/ATTACH][CODE]// Provided by Cesar Alvarez www.AlvarezQuantTrading.com// this code is for daily bar tests////////////////////////////////////////////////////////////// Repalce with your codeSetOption("MaxOpenPositions",10);SetPositionSize(10,spsPercentOfEquity);Buy = RSI(2) < 5;Sell = RSI(2) > 80;Short = Cover = 0;// End of replace///////////////////////////////////////////////////////////// Or you can add the following to the end of your current code// will not output anything if there are less than 200 bars in your testSetCustomBacktestProc("");if(Status("action") == actionPortfolio){ dnStart = Status("rangefromdate"); dnEnd = Status("rangetodate"); yrStart = int(dnStart/10000); yrEnd = int(dnEnd/10000); bo = GetBacktesterObject(); bo.backtest(); ver = Version(); if(BarCount > 200) { dt = DateNum(); if(ver <= 5.4) eq = Foreign("~~~EQUITY", "C"); else eq = bo.EquityArray(); // This could also be done by compressing to Monthly bars eqM = 0; // end of year equity - saving 2001 data in bar 101, 2002 in bar 102, ... for (i = 1; i < BarCount-1; i++) { // are we at the end of a year if (int(dt[i+1]/10000) > int(dt[i]/10000) ) eqM[int(dt[i]/10000)] = eq[i]; } // save the last equity eqM[yrStart-1] = GetOption("InitialEquity"); eqM[yrEnd] = eq[BarCount-1]; // output the results for (i=yrStart; i<= yrEnd; i++) { bo.AddcustomMetric("" + (i + 1900) + " Ret % ", 100*(eqM[i]/eqM[i-1] - 1)); } }}[/CODE]
[USER=55912]@Roller_1[/USER] funny enough I came across this today and i'm sure that you could modify the CBT code to achieve what you want ? or at least give you some ideas
The below example displays the yearly returns at the end of your back test report
https://alvarezquanttrading.com/amibroker-sample-code/
[ATTACH=full]103914[/ATTACH]
[CODE]// Provided by Cesar Alvarez www.AlvarezQuantTrading.com
// this code is for daily bar tests////////////////////////////////////////////////////////////
// Repalce with your code
SetOption("MaxOpenPositions",10);
SetPositionSize(10,spsPercentOfEquity);Buy = RSI(2) < 5;
Sell = RSI(2) > 80;Short = Cover = 0;
// End of replace
///////////////////////////////////////////////////////////// Or you can add the following to the end of your current code
// will not output anything if there are less than 200 bars in your test
SetCustomBacktestProc("");
if(Status("action") == actionPortfolio)
{
dnStart = Status("rangefromdate");
dnEnd = Status("rangetodate");
yrStart = int(dnStart/10000);
yrEnd = int(dnEnd/10000); bo = GetBacktesterObject();
bo.backtest(); ver = Version(); if(BarCount > 200)
dt = DateNum();
if(ver <= 5.4)
eq = Foreign("~~~EQUITY", "C");
else
eq = bo.EquityArray(); // This could also be done by compressing to Monthly bars
eqM = 0; // end of year equity - saving 2001 data in bar 101, 2002 in bar 102, ...
for (i = 1; i < BarCount-1; i++)
// are we at the end of a year
if (int(dt[i+1]/10000) > int(dt[i]/10000) )
eqM[int(dt[i]/10000)] = eq[i];
} // save the last equity
eqM[yrStart-1] = GetOption("InitialEquity");
eqM[yrEnd] = eq[BarCount-1]; // output the results
for (i=yrStart; i<= yrEnd; i++)
bo.AddcustomMetric("" + (i + 1900) + " Ret % ", 100*(eqM[i]/eqM[i-1] - 1));
}
}[/CODE]
Hello and welcome to Aussie Stock Forums!
To gain full access you must register. Registration is free and takes only a few seconds to complete.
Already a member? Log in here.