Code:long = 0; // long backtest true/false period = 20; // number of averaging periods m = MA( Close, period ); // simple moving average if ( long ) { Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average SetFormulaName( Name() + "_Long Backtest" ); // displayed in the backtest result explorer. } else { Short = Sell; Cover = Buy; SetFormulaName( Name() + "_Short Backtest" ); // displayed in the backtest result explorer. }
or create one or two clones of a symbol (like ~AAPL_1 and ~AAPL_2 ) via addtocomposite
and then you could use individual backtester (not portfolio BT) to run over group 253:
Code:period = 20; // number of averaging periods m = MA( Close, period ); // simple moving average if ( StrFind( Name(), "_1" ) && groupID() == 253 ) { Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average SetFormulaName( Name() + "_Long Backtest" ); // displayed in the backtest result explorer. } if( StrFind( Name(), "_2" ) && groupID() == 253 ) { Short = Sell; Cover = Buy; SetFormulaName( Name() + "_Short Backtest" ); // displayed in the backtest result explorer. }
Short = Cross( m, Close );
Cover = Cross( Close, m );
SetOption( "GenerateReport", 1 ); // 0 - suppresses generation of report
// 1 - force generation of full report
// 2 - only one-line report is generated (in results.rlst file) viewable as single line in Report Explorer
SetOption( "RefreshwhenCompleted", True );
period = 20; // number of averaging periods
m = MA( Close, period ); // simple moving average
if ( StrFind( Name(), "_1" ) && groupID() == 253 )
{
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average
SetFormulaName( Name() + "_Long Backtest" ); // displayed in the backtest result explorer.
}
if( StrFind( Name(), "_2" ) && groupID() == 253 )
{
Short = Cross( m, Close );
Cover = Cross( Close, m );
SetFormulaName( Name() + "_Short Backtest" ); // displayed in the backtest result explorer.
}
if ( Status( "action" ) == actionScan )
{
atcmode = atcFlagDefaults;
for ( i = 1; i < 3; i++ )//create two clones
{
indexname = "~" + Name() + "_" + i;
AddToComposite( Open, indexname, "O", atcmode );
AddToComposite( High, indexname, "H", atcmode );
AddToComposite( Low, indexname, "L", atcmode );
AddToComposite( Close, indexname, "C", atcmode );
AddToComposite( Volume, indexname, "V", atcmode );
AddToComposite( OI, indexname, "I", atcmode );
}
Buy = 0;
}
Looks like I need to run the clones through the Portfolio backtester.
It seems odd (to me at least) that the Individual backtest does not allow simultaneous longs and shorts. Of course, I guess everything is possible with "custom backtest" procedures.
Pardon me for just barging in the convo, but does any one have a link that has detailed library explaining what each formulas function is. I have a general idea of my trading strategy but its difficult for me to translate it into the program because the functions of each formula is to technical and so I don't know which formula to choose. Even a simple formula such as entering when a 52 week high is breached is confusing.
Thanks
Pardon me for just barging in the convo, but does any one have a link that has detailed library explaining what each formulas function is. I have a general idea of my trading strategy but its difficult for me to translate it into the program because the functions of each formula is to technical and so I don't know which formula to choose. Even a simple formula such as entering when a 52 week high is breached is confusing.
Thanks
Hi all, I'm thinking about getting the new version of amibroker. Can someone that has the new version show what the volume profile addition can do? Or point me to an explanation of it as I cannot seem to find any detail on it.
MaxPositions = 4;
SetOption("MaxOpenPositions", MaxPositions );
SetOption("WorstRankHeld", MaxPositions + 2 );
SetPositionSize( 100 / MaxPositions, spsPercentOfEquity );
// trade on next day open
BuyPrice = Open;
SetTradeDelays( 1, 1, 1, 1 );
SetBacktestMode( backtestRotational );
SetForeign( "XAO" );
FastMALength = Optimize("FMA",62,30,70,2);
SlowMALength = Optimize("SMA",182,180,200,2);
Filter1 = EMA( C, FastMALength ) > EMA( C, SlowMALength );
RestorePriceArrays();
//This is the additional filter I have introduced to try and filter out low volume stocks
VolA = Volume * C;
MAVol = MA( VolA, 15 );
Filter = Filter1 AND MAVol > 350000;
// offsetting by large positive number
// makes sure that our score is always positive and we don't enter short trades
PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), 0 );
StaticVarSet( Name() + "Score", 10000 - ROC( C, 252 ) );
SetCustomBacktestProc("");
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.backtest( 1 );
// closed trades
for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{ // two additional columns
trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) );
trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) );
}
// open trades
for ( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() )
{ // two additional columns
trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) );
trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) );
}
bo.listTrades();
}
I have been running a backtest which has a filter for EMA. I have had assistance with this backtest about a month ago.
The code currently is:
Code:MaxPositions = 4; SetOption("MaxOpenPositions", MaxPositions ); SetOption("WorstRankHeld", MaxPositions + 2 ); SetPositionSize( 100 / MaxPositions, spsPercentOfEquity ); // trade on next day open BuyPrice = Open; SetTradeDelays( 1, 1, 1, 1 ); SetBacktestMode( backtestRotational ); SetForeign( "XAO" ); FastMALength = Optimize("FMA",62,30,70,2); SlowMALength = Optimize("SMA",182,180,200,2); Filter1 = EMA( C, FastMALength ) > EMA( C, SlowMALength ); RestorePriceArrays(); //This is the additional filter I have introduced to try and filter out low volume stocks VolA = Volume * C; MAVol = MA( VolA, 15 ); Filter = Filter1 AND MAVol > 350000; // offsetting by large positive number // makes sure that our score is always positive and we don't enter short trades PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), 0 ); StaticVarSet( Name() + "Score", 10000 - ROC( C, 252 ) ); SetCustomBacktestProc(""); if ( Status( "action" ) == actionPortfolio ) { bo = GetBacktesterObject(); bo.backtest( 1 ); // closed trades for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) { // two additional columns trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) ); trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) ); } // open trades for ( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() ) { // two additional columns trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) ); trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) ); } bo.listTrades(); }
The issue I am having is the EMA 62 is below EMA 182 on "XAO" and has been throughout December. The backtest has however entered into trades for 1 or two days, firstly entering 3 trades on 1 December [closing 2 December] and then entering another trade on 8 December before closing the next day.
Very strange - I note that both sets of trades have occurred on the Monday... possibly a coincidence, but....
Does anyone have an idea where this is messing up...
PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), scoreNoRotate );
Code:PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), scoreNoRotate );
PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), 0 );
Even though the 62 period exponential moving average close value of the XAO is clearly under the 182 period exponential moving average close value of the XAO, a scan on just that filter alone brings up stocks. Why, I don't know either.The issue I am having is the EMA 62 is below EMA 182 on "XAO" and has been throughout December. The backtest has however entered into trades for 1 or two days, firstly entering 3 trades on 1 December [closing 2 December] and then entering another trade on 8 December before closing the next day.
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?