Amiboker Rotational Momentum Code Help

#1
I got the Rotational Momentum code from below URL.

http://dtr-trading.blogspot.com/2016/09/momentum-rotation-system-amibroker-code.html

I modified the above code a bit & 'Backtested' a bit as per below logic:

1) Calculate the PositionScore on End of Month
2) The Next trading day (Start of Next Month) Buy the Top1/5/10/30 stocks as per PositonScore (I took the Top 1 stock for current example)
3) Repeat the Process every month. Don't do any trade in mid of month

Below is my code & it's result with Entry/Exit backtested from 1/1/2015 to Current

Code:
SetBacktestMode( backtestRotational );

// 1 ###### BACKTESTER SETTINGS - 1. GENERAL TAB
SetOption(    "InitialEquity",                    1000000    );
SetOption(    "MinShares",                         1        );
SetOption(    "MinPosValue",                        0        );
SetOption(    "FuturesMode",                         False    );
SetOption(    "AllowPositionShrinking",             True    );
SetOption(    "ActivateStopsImmediately",            False    );
SetOption(    "ReverseSignalForcesExit",             False    );
SetOption(    "AllowSameBarExit",                    False    );
RoundLotSize    = 1;          // 0 for Funds, 100 for Stocks
TickSize        = 0;          // 0 for no min. size
MarginDeposit    = 0;
PointValue        = 1;        // For futures
SetOption(    "CommissionMode",                     1        );
SetOption(    "CommissionAmount",                 0.01    );
SetOption(    "InterestRate",                     0        );
SetOption(    "AccountMargin",                    100        );
SetOption(    "MarginRequirement",                 100        );

// 2 ###### BACKTESTER SETTINGS - 2. TRADES TAB
BuyPrice = SellPrice = ShortPrice = CoverPrice = Close;
SetTradeDelays( 1, 1, 1, 1);

// 5 ###### BACKTESTER SETTINGS - 5. PORTFOLIO TAB
//SetOption(    "MaxOpenPositions",                 1        );
// check the box to "Add artificial future bar..."
// Limit trade size as % - use 10 for live trading
// check the box to "Disable trade size limit..."
SetOption(    "UsePrevBarEquityForPosSizing",        True    );
SetOption(    "UseCustomBacktestProc",            False    );

// 6 ###### BACKTESTER SETTINGS - 6. WALK FORWARD TAB
//SetOption(    "WorstRankHeld",                     1        );


Totalpositions = 1;    //optimize("Totalpositions", 1, 1, 10, 1 );
SetOption("WorstRankHeld", Totalpositions);
SetOption("MaxOpenPositions", Totalpositions );

//Cumulative
//PositionSize = -100/Totalpositions ;
//Fixed
PositionSize = 1000000/Totalpositions;

//Our own filters
VOL_AVG = MA(VOLUME, 200) * MA( Close, 200);
//VOL_AVG_COMP = 30000000;    //optimize("VOL_AVG_COMP", 10000000, 10000000, 100000000, 10000000 );
myfilter = Close > 40 AND Close > MA( Close, 200);// AND VOL_AVG > VOL_AVG_COMP;

LastDayOfMonth = IIf( (Month() != Ref( Month(), 1)) , 1, 0);
TradeDay = LastDayOfMonth ;

ROCDays = 240;    //optimize("ROCDays", 240, 60, 240, 60 );
Score = ROC(Close, ROCDays);
Score = IIf(Score < 0 || myfilter != True, 0, Score ); // Long only

PositionScore = IIf(TradeDay , Score , scoreNoRotate);
Below is the screenshot of result:
2.jpg


I wanted to add a additional Exit filter as per below

1) If a Stock falss below 200MA in mid of month, Exit Next day.
2) Wait upto Month end & buy the stock with Top Position Score(s)

I tried to modify 'PositionScore' calculation as per below

Code:
MA200ExitVal = IIf(Close > MA( Close, 200), scoreNoRotate, 0);
PositionScore = IIf(TradeDay , Score , MA200ExitVal);
Screenshot of modified code
1.jpg


But as per above results, I am getting many False Exits in Mid of month although the Stock > 200 MA. Even the Date is wrong (showing weekend dates)
I feel that I am missing a small AFL logic but unable to get it.

Can anyone Please help me in fixing above code.

Thanks in advance.
 

Similar threads