End of Month trading, include a daily condition

I’m trying to convert an end of month trading strategy to run with the backtest set to ‘daily’. This is so that I can experiment with adding a daily filter. e.g. I want the end of month BUY signals to be conditional on the stock also being above it’s 10 day MA.

I’m hoping someone can see what the problem with my code is.

This is the MONTHLY strategy that works as it should with the backtest set on monthly.

// Simple breakout strategy
// Buys when 1 bar closes fully above 12 month moving Average of monthly highs
// Sells when 1 bar fully below 10 month moving average of monthly Lows
// A typical moving average index provides protection
// Volatile stocks are scored highest

// Backtest setup
PosQty = 10;
SetOption("MaxOpenPositions", PosQty);
SetPositionSize(100/PosQty, spsPercentOfEquity);
Lqd = EMA(V*C,3)/25 > 200000; // ensure at least $200K of money flow per day
Lot = C > 0.20; // avoiding penny stocks

// Index filter
Index = Foreign("XJO", "Close", True);
mBull = MA( Index, 9 );
Bearish = Index < mBull;
Bullish = Index > mBull ;

// Ranking
PositionScore = ATRP = (ATR(4)/Close) * 100;

// Trading rules
Buy = L > MA(H,12) AND Lqd AND Lot AND Bullish;
Sell = H < MA(L,10) OR Bearish; 

// Clear excess signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Below is my attempt to convert it to work the same with the backtest set to Daily.

// Backtest setup
PosQty = 10;
SetOption("MaxOpenPositions", PosQty);
SetPositionSize(100/PosQty, spsPercentOfEquity);

TimeFrameSet(inMonthly);
Lqd = EMA(V*C,3)/25 > 200000; // ensure at least $200K of money flow per day
TimeFrameRestore();

Lqd = TimeFrameExpand(Lqd, inMonthly);

Lot = C > 0.20; // avoiding penny stocks

// Index filter
TimeFrameSet (inMonthly);
Index = Foreign("XJO", "Close", True);
mBull = MA( Index, 9 );
Bearish = Index < mBull;
Bullish = Index > mBull ;
TimeFrameRestore();

Bearish = TimeFrameExpand(Bearish, inMonthly);
Bullish = TimeFrameExpand(Bullish, inMonthly);

// Ranking
PositionScore = ATRP = (ATR(100)/Close) * 100;

isLastOfMonth = TimeframeExpand(1, inMonthly, expandPoint);

// Trading rules
TimeFrameSet (inMonthly);
BuyCondition = L > MA(H,12);
SellCondition = H < MA(L,10); 
TimeFrameRestore();

BuyCondition = TimeFrameExpand(BuyCondition, inMonthly);
SellCondition = TimeFrameExpand(SellCondition, inMonthly);

Buy = BuyCondition AND isLastOfMonth AND Lqd AND Lot AND Bullish;
Sell = (SellCondition OR Bearish) AND IsLastOfMonth; 

// Clear excess signals
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

I removed position score from the timeframeset because it is producing more similar results without it.

I’ve been working off the guide: https://www.amibroker.com/guide/h_timeframe.html
And picked up the last trading day of the month code from this forum.

Any tips greatly appreciated.