HHV in case of TimeFrameCompress and TimeFrameExpand

Could anybody please tell, what I am coding incorrectly?

SetBarsRequired( 1000 );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

/*+------------------------------------------------------------------+
| calculate Monthly Highest By TimeFrameCompress and TimeFrameExpand |
+--------------------------------------------------------------------+*/
TimeFrameSet( inMonthly );
currentMonthlyHighestHighValue = HHV( H, 1 );
TimeFrameRestore();
expandedCurrentMonthlyHighestHighValue = TimeFrameExpand( currentMonthlyHighestHighValue, inMonthly, expandLast );
Plot( expandedCurrentMonthlyHighestHighValue , "expandedCurrentMonthlyHighestHighValue", colorRed, styleDots + styleNoLine );

/*+-----------------------------------------------------------+
| calculate the Expected Monthly Highest only for controlling |
+-------------------------------------------------------------+*/
newMonth = Month() != Ref(Month(),-1);

expectedMonthlyHighest = HHV( H , BarsSince(newMonth) + 1);
Plot( expectedMonthlyHighest , "expectedMonthlyHighest", colorGreen, styleDots + styleNoLine );

/*+----------------------------+
| Why it is here difference??? |
+------------------------------+*/
differenceBetweenExpandedAndExpectedHighest = expandedCurrentMonthlyHighestHighValue - expectedMonthlyHighest;

/*+--------+
| Plotting |
+----------+*/
Plot( C, "Close", IIf( newMonth , colorOrange , colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
Plot( differenceBetweenExpandedAndExpectedHighest , "differenceBetweenExpandedAndExpectedHighest", colorYellow , styleHistogram );

i made a few changes to the code. Best to do a replay in the daily time frame to see what is going on

SetBarsRequired( 1000 );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

/*+------------------------------------------------------------------+
| calculate Monthly Highest By TimeFrameCompress and TimeFrameExpand |
+--------------------------------------------------------------------+*/
TimeFrameSet( inMonthly );
currentMonthlyHighestHighValue = H;
TimeFrameRestore();
expandedCurrentMonthlyHighestHighValue = TimeFrameExpand( currentMonthlyHighestHighValue, inMonthly, expandFirst );
Plot( expandedCurrentMonthlyHighestHighValue , "expandedCurrentMonthlyHighestHighValue", colorRed, styleLine );//styleDots + styleNoLine );

/*+-----------------------------------------------------------+
| calculate the Expected Monthly Highest only for controlling |
+-------------------------------------------------------------+*/
newMonth = Month() != Ref(Month(),-1);

expectedMonthlyHighest = HHV( H , BarsSince(newMonth) + 1);
Plot( expectedMonthlyHighest , "expectedMonthlyHighest", colorGreen, styleLine );//styleDots + styleNoLine );

/*+----------------------------+
| Why it is here difference??? |
+------------------------------+*/
differenceBetweenExpandedAndExpectedHighest = expandedCurrentMonthlyHighestHighValue - expectedMonthlyHighest;

/*+--------+
| Plotting |
+----------+*/
Plot( C, "Close", IIf( newMonth , colorOrange , colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
//Plot( differenceBetweenExpandedAndExpectedHighest , "differenceBetweenExpandedAndExpectedHighest", colorYellow , styleHistogram );


Thank you for your kindness and help! It seems to be more-more better…

SetBarsRequired( 1000 );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

/*+------------------------------------------------------------------+
| calculate Monthly Highest By TimeFrameCompress and TimeFrameExpand |
+--------------------------------------------------------------------+*/
TimeFrameSet( inMonthly );
currentMonthlyOpenValue = O;
currentMonthlyHighestHighValue = HHV( H, 1 );
currentMonthlyLowestLowValue = LLV( L, 1 );
currentMonthlyCloseValue = C;
TimeFrameRestore();

expandedCurrentMonthlyOpen = TimeFrameExpand( currentMonthlyOpenValue, inMonthly, expandFirst );
Plot( expandedCurrentMonthlyOpen , "expandedCurrentMonthlyOpen", colorBrown, styleDots + styleNoLine );

expandedCurrentMonthlyHighestHighValue = TimeFrameExpand( currentMonthlyHighestHighValue, inMonthly, expandFirst );
Plot( expandedCurrentMonthlyHighestHighValue , "expandedCurrentMonthlyHighestHighValue", colorRed, styleDots + styleNoLine );

expandedCurrentMonthlyLowestLowValue = TimeFrameExpand( currentMonthlyLowestLowValue, inMonthly, expandFirst );
Plot( expandedCurrentMonthlyLowestLowValue , "expandedCurrentMonthlyLowestLowValue", colorGreen, styleDots + styleNoLine );

expandedCurrentMonthlyClose = TimeFrameExpand( currentMonthlyCloseValue, inMonthly, expandFirst );
Plot( expandedCurrentMonthlyClose , "expandedCurrentMonthlyClose", colorYellow, styleDots + styleNoLine );

/*+-----------------------------------------------------------+
| calculate the Expected Monthly Highest only for controlling |
+-------------------------------------------------------------+*/
newMonth = Month() != Ref(Month(),-1);

expectedMonthlyHighest = HHV( H , BarsSince(newMonth) + 1);
//Plot( expectedMonthlyHighest , "expectedMonthlyHighest", colorBlue, styleDots + styleNoLine );

/*+----------------------------+
| Why it is here difference??? |
+------------------------------+*/
differenceBetweenExpandedAndExpectedHighest = expandedCurrentMonthlyHighestHighValue - expectedMonthlyHighest;

/*+--------+
| Plotting |
+----------+*/
Plot( C, "Close", IIf( newMonth , colorOrange , colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
//Plot( differenceBetweenExpandedAndExpectedHighest , "differenceBetweenExpandedAndExpectedHighest", colorYellow , styleHistogram );