This code should do it. Just set up a watchlist with the three ETFs that you want to rebalance weekly, use that as your Apply to Filter, set up the daterange and hit backtest.
EnableRotationalTrading();
SetTradeDelays( 0,0,0,0 );
firstdayofweek = DayOfWeek() < Ref( DayOfWeek(), -1 );
EachPosPercent = 33.333;
PositionScore = IIf( firstdayofweek, 1, scoreNoRotate );
PositionSize = -EachPosPercent;
SetOption( "InitialEquity", 100000 );
SetOption( "WorstRankHeld", 3 );
SetOption( "MaxOpenPositions", 3 );
SetOption( "UseCustomBacktestProc", True );
if( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.PreProcess();
for( bar = 0; bar < BarCount; bar++ )
{
bo.ProcessTradeSignals( bar );
CurEquity = bo.Equity;
if( firstdayofweek[bar] == 1 )
{
for( pos = bo.GetFirstOpenPos(); pos; pos = bo.GetNextOpenPos() )
{
posval = pos.GetPositionValue();
diff = posval - 0.01 * EachPosPercent * CurEquity;
price = pos.GetPrice( bar, "O" );
if( diff != 0 AND abs( diff ) > price )
{
bo.ScaleTrade( bar, pos.Symbol, diff < 0, price, abs( diff ) );
}
}
}
}
bo.PostProcess();
}
__._,_.___
Posted by: jani <jani.talikka@gmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (2) |
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
.
__,_._,___
EmoticonEmoticon