Multi TimeFrame Intraday - problems with loop

Hi all,
I have written a trend following breakout system that draws entry and exit lines for both long end short trades (4 lines in total). When I run it on one timeframe everything works well, both from a backtest and chart perspective. Every trade is correct and the lines are drawn correctly. When I use an higher timeframe to calculate the values (let's say hourly) and then look at the chart on lower timeframe the problems start:

  1. on some assets (FX) I can see the hourly lines if I run it on a 15 mins, but not on 5 or 1 min
  2. on other assets (futures) the lines simply do not appear or are fixed at a certain level
    I have the same issue if I use monthly as higher time frame and daily as lower, sometimes actually when i scroll the chart the lines appear/disappear.

I am using timeframeset and timeframerestore at the beginning/end of the code
I am also using the required loop to avoid blanks
for( start = 0; start < BarCount; start++ ) { if( (NOT IsNull( Close[ start ] )) AND (NOT IsNull( High[ start ] )) AND (NOT IsNull( Low[ start ] ))AND (NOT IsNull( Open[ start ] ))) break; }

I read all articles in the knowledge base that relate to this subject but I could not find the problem.
My end objective is simply to run the system at an higher timeframe to set the scene like this:
"monthly trend is up/down = only take long/short trades on lower timeframe"
and then add the same code below to trade the signals on a lower timeframe.

I am fine using simple arrays, used plenty of multi timeframe indicators before but I can't understand what is wrong when using loops. Also I have run explorations at lower timeframes and, based on where I put timeframeset 2 out 4 of the lines show data, the other 2 no. If i run the code on the higher timeframe everything is fine also using exploration.
Can anyone point me in the right direction please?
Many thanks for any help.

Adapt code as required

Thanks for this but I already read both pages and I could not make it work.