Best way to identify close above a recent pullback bar

Hi,

I am trying to identify the bar that closes below recent pull back bar. I can check close below previous bar using Ref() but can't seem to find close if there are more than one pullback bar. I have attached image for describing the scenario

pullback bar

Thanks
Deepak

Take a look at the ValueWhen function.

In my opinion, the key here is how you define “recent pull back bar”? Recent would be something that happened in the last 5 candles, or 50?

You can have a look at the functions HHV and LLV, for when a new maximum or low is hit. Then writing a for loop to see if in a certain number of bars the price pullback below that level.

Hope this helps.
AK.

@ak87: no need for a loop in this case. Assuming you have identified the pullback bars, you can use BarsSince() to see how long it’s been since the most recent pullback.

1 Like

Thanks everyone for your pointers. I was able to plot a close above/below the recent pull back bar with this code

// close above pullback high
isBearBar = C < O;
PBHigh = ValueWhen(isBearBar,H,1);
PBBuy = Cross(C,PBHigh);
PBBuyBarIndex = ValueWhen(PBBuy,BarIndex(),1);
PlotShapes(PBBuy*shapeUpArrow,colorBlue,0,L,-12);

// close below pullback low
isBullBar = C > O;
PBLow = ValueWhen(isBullBar,L,1);
PBShort = Cross(PBLow,C);
PBBuyBarIndex = ValueWhen(PBBuy,BarIndex(),1);
PlotShapes(PBShort*shapeDownArrow,colorRed,0,H,-20);

pullback bar success

Regards
Deepak

3 Likes