Semi-Monthly Rebalance

How can I get Semi-Monthly Rebalance with Amibroker ?

See ready to use code

With Periodicity "Daily" or "Weekly" i get Daily or Weekly Rebalance. But how can I get Semi-Monthly rebalance ?
Screenshot (486)

An alternative could be choosing periodicity "Weekly" and rebalancing every second week.
But how could this be done ?

It also works with daily or lower intervals.

mth = Month();
dd = Day();
dow = DayOfWeek();
new_mth = mth != Ref(mth, -1);
new_week = dow < Ref(dow,-1);
if ( Interval() <= inDaily ) { // <= inDaily
	is_midMonth = SumSince(new_mth, new_week) == 2 AND
					SumSince(new_week, dd >= 15) == 1; 
} else // inWeekly
	is_midMonth = BarsSince(new_mth) == 2;
SetBacktestMode( backtestRotational );
SetPositionSize( 5, spsPercentOfEquity );
SetOption("WorstRankHeld", 40 );
SetOption("MaxOpenPositions", 20 ); 

// rotate mid of month
rotation = is_midMonth;
score = Ref(ROC( C, 20 ), -1); 
PositionScore = IIf(rotation, score, scoreNoRotate);
BuyPrice = Open;

Screenshot (487)
I get 2 errors !

1 Like

There is no error (if using appropriate AB version).

Please stop your use of exclamation marks if you are not able to investigate what SumSince function is.
For SumSince you need minimum AB 6.10.
(AB 6.00 is six years old, so it's time to update. Hint: most recent public version -> 6.40 RC.)


Thank You !
After updating to 6.3 there are no errors anymore.
Maybe it would be a better solution if choosing "Periodicity Weekly" and rebalance every second week.
How could this be done ?

Please study the code it is already in there!
It works for both in daily and smaller intervals as well as for in weekly.

Can you see and read the words "inWeekly" in the code? No? Too bad...

Sometimes I wonder how people even find location of buy/sell buttons in their trading app.

1 Like

Thank You !
It seems to function also with "Periodicity weekly".
But there is still one problem with your AFL.
Despite of having set "Positions : Long" it also generates Short trades !

It is more the lack of your understanding on how the Rotational Mode works rather than a code issue!

See Long Only Rotational System.

1 Like

Thank You !
Now it functions !

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.