Envelope-ATR consist of 3 WeightedAverages(21) and the AverageTrueRange(14).
In fact its very simple, take the WeightedAverage (21) of the Close, the high and the low. The WeightedAverage of the close count as the arbiter of the game.
The WeightedAverage of the High decide the upper band and the WeightedAverage of the Low decide the lower band.
The background of the channel is coloured with conditions based on the slope of the envelope.
//Berekening van het gemiddelde en zijn banden
once n=21
e=WeightedAverage[n](close)
e1=Weightedaverage[n](high)+2.618*AverageTrueRange[14](close)
e2=Weightedaverage[n](low)-2.618*AverageTrueRange[14](close)
//Opwaartse koersen blauwe lijnen
//Neerwaartse koersen rode lijnen
//Gele rechthoeken zijwaartse koersen
if e1>=e1[2] then
DRAWSEGMENT(barindex, e1, barindex, e)coloured(0,125,175,255)//Stijgende koersen
elsif e2<=e2[1] then
DRAWSEGMENT(barindex, e2, barindex, e)coloured(204,0,255,255)//Dalende koersen
else
//We tekenen een rexhthoek als de koersen zijwaarts gaan
DRAWRECTANGLE(barindex,e1, barindex[1], e2[1])coloured(255,255,0,255)//Zijwaartse koersen
endif
return e as"Middellijn", e1 as"Stijgende koersen", e2 as"Dalende koersen"