This indicator finds trend following engulfings, and draws order blocks based on the 1st candle’s range (the first candle of the engulfing pattern). It does filter the trend with simple moving averages of 21 and 55 periods, but it doesn’t filter for retracements in the trend (you should consider only the order blocks that are coming from engulfings after a retracement) .
Converted as requested here https://www.prorealcode.com/topic/ema-speed-acceleartion-para-prt/.
//EMA21 Speed & Accel
//
//
//https://www.prorealcode.com/topic/ema-speed-acceleartion-para-prt/
//
//@version=4 by Saltapones
//
backgroundcolor("White")
NP = 1
len1 = 21
//out1 = average[len1,1](close)
SMAS = (1.50*average[len1,1](close)-2*average[len1,1](close[NP])+0.5*average[len1,1](close[2*NP]))/(NP*average[len1,1](close))
SMASMA = average[5,0](SMAS)
y = max(SMASMA*100,-5)
CURV = (average[len1,1](close)-2*average[len1,1](close[NP])+average[len1,1](close[2*NP]))/(NP*NP)
CURVMA = average[5,0](CURV)
maxslope = highest[200](SMASMA)*100
maxcurvature = highest[200](CURVMA)
scale = 1*maxslope/maxcurvature
x = min(CURVMA*scale,5)
IF CURV <= 0 THEN
x = max(CURVMA*scale,-5)
ENDIF
IF CURVMA >= 0 AND SMASMA >= 0 THEN
backgroundcolor("LawnGreen")
ENDIF
RETURN x AS "Curvature" coloured(255,0,255,255),y AS "Average" coloured(65,105,225,255)