Hey,
I'm working on a strategy that consists of many sub strategies (28 in this example). The way I test it is to save equity curves from those sub strategies (during optimization), then add those equity curves to a watchlist and, finally, to run simple buy and hold strategy using this watchlist like this:
PositionSize = -100/28;
Buy = 1;
Sell = 0;
The problem is that this is not how it works in real world, my scripts which I use for trading, give 1/28 of equity to every sub strategy on every entry (and this code assumes every sub strategy has its own capital which is never shared with other strategies and trades it until the end of backtest).
It's probably not possible to simulate this behaviour in Amibroker (I'd be very pleased if it's not true).
So I tried another approach: buy all strategies every day.
The code is:
PositionSize = -100/28;
SetOption("CommissionMode", 1);
SetOption("CommissionAmount", 0);
SetOption("HoldMinBars", 1);
SetOption("AllowSameBarExit", 1);
SetOption("MinShares", 0);
SetOption("MinPosValue", 0);
SetTradeDelays(0,0,0,0);
BuyPrice = SellPrice = C;
Buy = 1;
Sell = 1;
And this works (if the number of substrategies * number of bars is not too high).
Are there any other methods to do it?
Everything is possible in AmiBroker
/// ############################# 1. create Symbol Clones ###################################
/// @link https://forum.amibroker.com/t/combining-multiple-strategies-into-one-ensemble-strategies/19232/2
// 1. In Analysis choose "Apply to: Current", "Range: All quotes",
// 2. Choose "Periodicity" in backtester settings
// 3. Click "Scan" to clone symbol
// (As for giving a composite name don't forget starting with tilde!)
num_systems= 2;//number of systems / symbol clones
nm = Name();
appendix = "_System";
if ( Status( "actionex" ) == actionScan ) {
atcmode = atcFlagDefaults;
for ( i = 1; i <= num_systems; i++ ) {
indexname = "~" + nm + appendix + 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 );
}
}
/// ############################# 2. Run Postfolio backtest ###################################
/// @link https://forum.amibroker.com/t/combining-multiple-strategies-into-one-ensemble-strategies/19232/2
/// Multi system portfolio, single market
/// Put symbol clones to a WL first!
SetOption( "InitialEquity", 100000 );
SetOption( "FuturesMode", False );
SetOption( "MaxOpenPositions", num_systems ); // number of systems here
SetOption( "AllowPositionShrinking", 1 );
wl_num = 10;// GetOption("FilterIncludeWatchlist");//
size = 100;
size_mode = spsPercentOfEquity;
if( Status( "actionex" ) == actionBacktest ) {
if( InWatchList(wl_num) ) { // watchlist membership of symbol clones
enterlong = exitlong = 0;
// first symbol clone and system
if ( StrFind( nm, "System1" ) ) {
enterlong = Cross( C, MA( C, 20 ) );
exitlong = Cross( MA( C, 20 ), C );
SetPositionSize( size/num_systems, size_mode ); // 50% into first system
}
// second symbol clone and system
if ( StrFind( nm, "System2" ) ) {
enterlong = Cross( C, MA( C, 50 ) );
exitlong = Cross( MA( C, 50 ), C );
SetPositionSize( size/num_systems, size_mode ); // 50% into second system
}
//
Buy = Ref( enterlong, -1 );
Sell = Ref( exitlong, -1 );
BuyPrice = SellPrice = Open;
Short = Cover = 0;
}
}
3 Likes
BTW, your thread is duplicate.
There are other examples.
E.g. by @Tomasz
You could do that without ApplyStop and without CBT. See example below:
TriggerPrice1 = Ref( HHV( High, 50 ), -1 );
TriggerPrice2 = Ref( HHV( High, 30 ), -1 );
Buy1 = High > TriggerPrice1;
Buy2 = High > TriggerPrice2;
ExitPrice1 = Ref( LLV( Low, 50 ), -1 );
ExitPrice2 = Ref( LLV( Low, 30 ), -1 );
Sell1 = Low < ExitPrice1;
Sell2 = Low < ExitPrice2;
InTrade = 0;
Buy = 0;
Sell = 0;
for( i = 0; i < BarCount; i++ )
{
switch( InTrade )
{
case 0: // not in trade
if( Buy1[ i ] )
InTrade …
Search forum.
1 Like
konradp
October 29, 2021, 10:14pm
#4
Hi! Is it possible to use PositionScore separately for each strategy using this method?
1 Like
system
Closed
February 6, 2022, 10:15pm
#5
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.