Hello
I am just wondering if HHV function in amibroker is close enough to replace pivothigh in pinescript. If it's not is there anything we can use to replicate this function
Thank you
Hello
I am just wondering if HHV function in amibroker is close enough to replace pivothigh in pinescript. If it's not is there anything we can use to replicate this function
Thank you
No, HHV is not that, but Peak() function might be somewhat similar.
PivotHigh can be however, implemented using simple comparisons to past / future bars, like this:
PivotHigh = H > Ref( H, -1 ) AND H > Ref( H, -2 ) /* past */
AND H > Ref( H, 1 ) AND H > Ref( H, 2 ) /* future */;
more generic function
function PivotHigh( input, left, right )
{
sumhigh = 0;
for( i = 1; i <= left; i++ ) sumhigh += input> Ref( input, -i ); // past
for( i = 1; i <= right; i++ ) sumhigh += input> Ref( input, i ); // future
// pivot if all specified points are lower
return sumhigh == (left + right);
}
Generally avoid functions like "pivothigh" or peak, because they both look into the future and as such can't be directly used in realistic trading systems, unless DELAY is applied for last leg to stabilise.
Tomasz, since you mentioned "unless DELAY is applied for last leg to stabilise."is there any example how the delay being implemented in both function so that both function can be used ?
Is that simply add a Ref(,-1) on the function to validate and an exrem()?
You have to delay the signal for as many bars as right
parameter.
Here is the code for both Pivor high and Pivot Low
_SECTION_BEGIN("Price");
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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
function PivotHigh( input, left, right )
{
sumhigh = 0;
for( i = 1; i <= left; i++ ) sumhigh += input>= Ref( input, -i ); // past
for( i = 1; i <= right; i++ ) sumhigh += input> Ref( input, i ); // future
// pivot if all specified points are lower
return sumhigh == (left + right);
}
function PivotLow( input, left, right )
{
sumLow = 0;
for( i = 1; i <= left; i++ ) sumLow += input<= Ref( input, -i ); // past
for( i = 1; i <= right; i++ ) sumLow += input< Ref( input, i ); // future
// pivot if all specified points are lower
return sumLow == (left + right);
}
Top_Para = Param("HL of Previous N Bar", 10, 1, 100, 1);
Bot_Para = Param("HL of Next N Bar", 3, 1, 100, 1);
High_Get = PivotHigh( High, Top_Para, Bot_Para ) ;
High_Low = PivotLow( Low, Top_Para, Bot_Para ) ;
Short = Ref(High_Get, -Bot_Para);
Buy = Ref(High_Low, -Bot_Para);
Sell = Short;
Cover = Buy;
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -15 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -25 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -20 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 15 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 25 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -20 );
PlotShapes( IIf( Cover AND !Buy, shapeStar, shapeNone ), colorRed, 0, L, Offset = -20 );
PlotShapes( IIf( Sell AND !Short, shapeStar, shapeNone ), colorGreen, 0, H, Offset = 20 );
PlotShapes( IIf( Cover AND Buy, shapeStar, shapeNone ), colorRed, 0, L, Offset = -40 );
PlotShapes( IIf( Sell AND Short, shapeStar, shapeNone ), colorGreen, 0, H, Offset = 40 );
PlotShapes(IIf(High_Low, shapeSmallUpTriangle, shapeNone),colorBlue, 0, L, Offset= -15);
PlotShapes(IIf(High_Get, shapeSmallDownTriangle, shapeNone),colorOrange, 0, H, Offset= -15);