Hello trash
Thank you for the reply, and code! Much kudos to you, and much obliged myself /bow
I seem to get an error with the code you posted though. When I click Backtest, an error message appears, to which I click the Try to Continue button. Then I need to click on the red square stop button. Then the error message: "The results file can not be open for writing." appears. The code works fine, in that the daily p/l is listed at the bottom of the Report. However, no additional columns are added to the Backtest Analysis (just the default values as normal). Also, the Report Explorer doesnt seem to work. If you have any ideas, I would again be most appreciative. I did some google searching and it seems like those errors are said to occur when Excel or Word is open, but I had neither of these open when running the backtest.
Yes, I'm very sorry for the large font! I posted the original message on a device with a very small screen, and it was more for my own benefit than anyone else's. I checked on my desktop and it is indeed rather large! O_O I would edit it back to normal size, but there doesnt seem to be an edit function on previous posts. Sorry about that.
Anyway, thanks again for the help. It is sincerely appreciated.
Ato
Go to AB support. Maybe you destroyed some Windows registry dependencies.
However, no additional columns are added to the Backtest Analysis (just the default values as normal).
dt = DateTime();
EOD = Day() != Ref( Day(), 1 );
bir = Status( "barinrange" );
SetCustomBacktestProc("");
// Now custom-backtest procedure follows
if( Status( "action" ) == actionPortfolio ) {
bo = GetBacktesterObject(); // Retrieve the interface to portfolio backtester
bo.Backtest();
eq = bo.EquityArray();
ret = ( eq/Ref( eq, -1 ) -1 ) * 100;
bo.AddCustomMetric( "Daily %P/L:" );
for( i = 0; i < BarCount; i++ ) {
if( EOD[i] && ret[i] != 0 && bir[i] )
bo.AddCustomMetric( DateTimeToStr( dt[i] ), ret[i] );
}
}
// daily return output to exploration (after backtest)
// one of billions of solutions by trash
// https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=120&p=874231&viewfull=1#post874231
// first hit backtest then hit explore then copy&paste result list to Excel
// Apply 'Explore' in same TF you have backtested in.
EOD = Day() != Ref( Day(), 1 );
bir = Status( "barinrange" );
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio ) {
bo = GetBacktesterObject();
bo.Backtest();
StaticVarSet( "PortfolioEquity", bo.EquityArray );
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// some dummy system
SetPositionSize( 25, spsPercentOfEquity );
period = 20; // number of averaging periods
m = MA( Close, period ); // simple moving average
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average
Short = Sell;
Cover = Buy;
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if( Status( "action" ) == actionExplore ) {
TimeFrameSet( inDaily );
cl = StaticVarGet( "PortfolioEquity" );
refcl = Ref( cl, -1 );
ret = ( cl / refcl - 1 ) * 100;
TimeFrameRestore();
ret = TimeFrameExpand( ret, inDaily, expandFirst );
Filter = EOD AND ret != 0 AND bir;
AddColumn( ret, ""Daily %Returns"", 1.2 );
}
// daily return output to report and to exploration (after backtest)
// one of billions of solutions by trash
// https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=120&p=874231&viewfull=1#post874231
// first hit backtest then hit explore then copy&paste result list to Excel
dt = DateTime();
EOD = Day() != Ref( Day(), 1 );
bir = Status( "barinrange" );
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio ) {
bo = GetBacktesterObject();
bo.Backtest();
eq = bo.EquityArray;
StaticVarSet( "PortfolioEquity", eq );
TimeFrameSet( inDaily );
cl = StaticVarGet( "PortfolioEquity" );
refcl = Ref( cl, -1 );
ret = ( cl / refcl - 1 ) * 100;
TimeFrameRestore();
ret = TimeFrameExpand( ret, inDaily, expandFirst );
bo.AddCustomMetric( "Daily %P/L:" );
for( i = 0; i < BarCount; i++ ) {
if( EOD[i] && ret[i] != 0 && bir[i] )
bo.AddCustomMetric( DateTimeToStr( dt[i] ), ret[i] );
}
StaticVarSet( "PortfolioEqDaily%Return", ret );
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// some dummy system
SetPositionSize( 25, spsPercentOfEquity );
period = 20; // number of averaging periods
m = MA( Close, period ); // simple moving average
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average
Short = Sell;
Cover = Buy;
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if( Status( "action" ) == actionExplore ) {
ret = StaticVarGet( "PortfolioEqDaily%Return" );
Filter = EOD AND ret != 0 AND bir;
AddColumn( ret, "Daily %Returns", 1.2 );
}
Hi,
I am just a newbie to Amibroker. I have just bought the trial version and trying to write some afl.
I want a simple condition that if 6-ema crosses 18-ema then buy at next day's open price.
Sell on the open price on the day after buy was executed. for eg. if buy on 1st jan then sell on 2nd jan open price.
I only want to go long and not short.
I wrote the following AFL but it wasn't getting executed properly
fastma = MA(C,6);
slowma = MA(C,18);
SetTradeDelays(1,2,1,1);
BuyPrice=Open;
SellPrice=Open;
Buy=Cross(fastma,slowma);
Sell=Cross(fastma,slowma);
ExRem(Buy,Sell);
Could someone please explain me exrem function. I am not clear on how it works.
Thanks
SetOption( "HoldMinBars", 1 );
SetOption( "Allowsamebarexit", 1 );
SetPositionSize( 1, spsShares );
SetTradeDelays( 0, 0, 0, 0 ); // set to zero as we use Ref()
fastma = MA( C, 6 );
slowma = MA( C, 18 );
BuyPrice = O;
SellPrice = O;
Buy = Ref( Cross( fastma, slowma ), -1);
Sell = 1;
Short = Cover = 0;
Here is code for analysis.
Code:SetOption( "HoldMinBars", 1 ); SetOption( "Allowsamebarexit", 1 ); SetPositionSize( 1, spsShares ); SetTradeDelays( 0, 0, 0, 0 ); // set to zero as we use Ref() fastma = MA( C, 6 ); slowma = MA( C, 18 ); BuyPrice = O; SellPrice = O; Buy = Ref( Cross( fastma, slowma ), -1); Sell = 1; Short = Cover = 0;
It is buying and selling on the same day, whereas I want to sell on the day after it is bought.
Hello everyone,
I just went to the ASX website and downloaded the company directory CSV file.
Then I copied and pasted them all into a text file and renamed it .tls
I know I'm probably late to the party but here's the file so you can use it in AmiQuote to get EOD data from Yahoo Historical. A few of the codes have the error message and I don't know why... maybe someone can help answer this question?
Took me about half an hour to add a slash to the end of each ticker and then find replace .AX
Hope it helps the newbies!
View attachment 63384
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?