Color coding histogram indicator bars following multiple pivot points

I want to be able to manually select multiple pivot points on a price chart and mark them (using a vertical line as in this example or something else) so that I can refer to them using AFL. I then want to color code the bars of a histogram indicator that are within a range of bars after the pivots (range = the number of lookback bars of the indicator). The value of these bars should also exceed a specified threshold.

For example, if the indicator lookback = 6 bars, I want to assign a unique color to the 6 bars of the indicator that follow every pivot point, but only if their value exceeds 2.

What I have been able to achieve is getting the BarIndex() values at the pivot points and using those to color code the desired bars after the first pivot only. I just don't have the coding experience to know which of the new tools I'm learning could be used to get these same results at all of the pivots. Thus, my feeble attempt with "anypivot" and a basic IIf statement.

I would appreciate if someone could steer me in the general direction toward applying this result at all pivot points.

_SECTION_BEGIN("color code histogram after pivot points");
Plot( C, "Price", colorBlack, styleCandle );

pivotA = Study("PA", GetChartID() );//5 pivot bars manually identified using vertical line drawing studies
pivotB = Study("PB", GetChartID() );
pivotC = Study("PC", GetChartID() );
pivotD = Study("PD", GetChartID() );
pivotE = Study("PE", GetChartID() );

dateA = LastValue( ValueWhen( IsNull( pivotA ), DateTime() ) );//get the x-axis DateTime property of the 5 vertical lines
dateB = LastValue( ValueWhen( IsNull( pivotB ), DateTime() ) );
dateC = LastValue( ValueWhen( IsNull( pivotC ), DateTime() ) );
dateD = LastValue( ValueWhen( IsNull( pivotD ), DateTime() ) );
dateE = LastValue( ValueWhen( IsNull( pivotE ), DateTime() ) );

pivotIndexA = Lookup (BarIndex(), dateA, 0);//Lookup BarIndex value for each vertical line using DateTime property
pivotIndexB = Lookup (BarIndex(), dateB, 0);
pivotIndexC = Lookup (BarIndex(), dateC, 0);
pivotIndexD = Lookup (BarIndex(), dateD, 0);
pivotIndexE = Lookup (BarIndex(), dateE, 0);

anyPivot = pivotIndexA OR pivotIndexB OR pivotIndexC OR pivotIndexD OR pivotIndexE;//feebleness on parade

Period = Param ("Lookback", 1, 1, 15, 1);
histogram = ROC(C, Period);//just a simple histogram indicator for the exercise

histogramColor = IIf( (BarIndex() > anyPivot) AND (BarIndex() <= (anyPivot + Period)) AND abs(histogram) >= 2,colorPink,
				IIf ( abs(histogram) >= 2, colorViolet, IIf( abs(histogram) < 0.5, colorBlack, colorGrey40)));

Plot (histogram, "ROC", histogramColor, styleHistogram | styleOwnScale | styleThick | styleNoLabel);

//Title used to validate dates and barindices ... not needed in final code
Title = "{{NAME}} {{DATE}}    ROC = " + NumToStr(histogram, 1.2) +
  "\nPivot A Date = " + WriteVal( dateA, formatDateTime ) + "  BarIndex = " + NumToStr(pivotIndexA, 1.0) +
  "\nPivot B Date = " + WriteVal( dateB, formatDateTime ) + "  BarIndex = " + NumToStr(pivotIndexB, 1.0) +
  "\nPivot C Date = " + WriteVal( dateC, formatDateTime ) + "  BarIndex = " + NumToStr(pivotIndexC, 1.0) +
  "\nPivot D Date = " + WriteVal( dateD, formatDateTime ) + "  BarIndex = " + NumToStr(pivotIndexD, 1.0) +
  "\nPivot E Date = " + WriteVal( dateE, formatDateTime ) + "  BarIndex = " + NumToStr(pivotIndexE, 1.0);
_SECTION_END();

/*  REFERENCES
https://forum.amibroker.com/t/how-to-get-manual-drawed-vertical-line-date-in-afl/19760
https://forum.amibroker.com/t/study-values-change-unexpectedly/15410/3
https://www.amibroker.com/kb/2006/03/07/getting-x-y-co-ordinates-of-study */

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.