Is it a bug??? HHV in case of TimeFrameCompress and TimeFramExpand

#1
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 );

/*+--------+
| ERROR??? |
+----------+*/
errorBetweenExpandedAndExpectedHighest = expandedCurrentMonthlyHighestHighValue - expectedMonthlyHighest;

/*+--------+
| Plotting |
+----------+*/
Plot( C, "Close", IIf( newMonth , colorOrange , colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot( errorBetweenExpandedAndExpectedHighest , "errorBetweenExpandedAndExpectedHighest", colorYellow , styleHistogram );
 
#3
Zoltan, your code is not comparing two equal calculations. There is no "Bug", your code is wrong.

In your Monthly calculation you are looking at the Previous Monthly Highest High.

In your daily calculation you are calculating the CURRENT months's Highest High so far.

Run an EXPLORE or a SCAN and follow the values you have calculated. It will clarify the difference.
 
#4
Thank you for your quick answer! And sry but i dont understand. I m using the same function with the same parameter.
HHV( H , 1 ) ===> and it means the current highest high value.

[ I mean Previous monthly HHV should be this: Ref( HHV(H, 1), -1) ]

I can do others, but the question is same, how can i get the CURRENT monthly highest high value with timeframecompress and expand. My oppinion, that compress and expand works not correctly, because it gives back a value FROM the future.

I mean it is not reliable...

(Of course i want use another function not HHV, but this is currently the best for clarifying my problem.)
 
#5
expandFirst is the keyword [instead of expandLast].

And here is a working code:

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 );
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?