Finding and plotting HH7 in higher timeframe

I am plotting 25 minute bar in my 5 minute timeframe db. the plot works fine. I want to plot bars where the 25 minute bar had a highest range in last 7 bars. this is where the plots don't line up consistently.

intervaltimeframe=Interval();
_SECTION_BEGIN("MultiTimeframe");

//if(intervaltimeframe==inDaily){
//wo = TimeFrameGetPrice( "O", inWeekly, 0, expandPoint ); 
//wh = TimeFrameGetPrice( "H", inWeekly, 0, expandPoint ); 
//wl = TimeFrameGetPrice( "L", inWeekly, 0, expandPoint ); 
//wc = TimeFrameGetPrice( "C", inWeekly, 0, expandPoint ); 


//PlotOHLC( wo, wh, wl, wc, "weekly Close", colorWhite, styleCandle );
//}
//else
{
wo = TimeFrameGetPrice( "O", intervaltimeframe*5, 0, expandPoint ); 
wh = TimeFrameGetPrice( "H", intervaltimeframe*5, 0, expandPoint ); 
wl = TimeFrameGetPrice( "L", intervaltimeframe*5, 0, expandPoint ); 
wc = TimeFrameGetPrice( "C", intervaltimeframe*5, 0, expandPoint ); 
RANGE = wh - wl;

//
PlotOHLC( wo, wh, wl, wc, "25 minute timeframe", colorWhite, styleCandle );

TimeFrameSet(  intervaltimeframe*5 ); // switch to 5 minute frame 

/* MA now operates on 5 minute data, ma5_13 holds time-compressed 13 bar MA of 5min bars */ 
RANGEinhigh = wh - wl;
hh7 = RANGE == HHV( RANGEinhigh, 7 );
atr15= ATR(14);

TimeFrameRestore(); // restore time frame to original  
 atr15_expanded= TimeFrameExpand( atr15, intervaltimeframe*5);
 hh7_expanded= TimeFrameExpand( hh7, intervaltimeframe*5);
min5greterthanhighertimeframe=H-L>  atr15_expanded;
PlotShapes( min5greterthanhighertimeframe * shapeStar , colorYellow, 0,wc );
PlotShapes(  hh7_expanded*shapeDigit7 , colorYellow, 0,wh+3*ATR(14) );
}
LineThickness=1; 
//PlotShapes(shapeSquare,IIf(MA(C,50)>MA(C,200),colorGreen,colorRed),0,status("axisminy"));
_SECTION_END();

If you haven' t solved your problem, can you try to restate what you want to do in a more exact way.
I mean, do you want to plot a shape (the number 7?). I see you mention which is wrong and which is not plotted. Which ones are right?