Ensign volatility stop

Category: Indicators By: carlvan Created: January 4, 2022, 9:01 AM
January 4, 2022, 9:01 AM
Indicators
4 Comments

This is a code converted from AFL and based on a volatility stop originally developed by Ensign, now public domain.

Benefit of this stop: parametrable “elasticity” in order to avoid early stop-out within existing trend- this stop “absorbs” the inevitable little pullbacks of the prices.

But, drawbacks of my converted code – and here I am keenfully awaiting the help of Nicolas:

it takes literally forever for the code to chart (45 secondes of calculation on my very fast machine) before charting. And when using Defparam calculate on last x bars, it doesn’t help really.  Is there a way to make this code much quicker?

I didn’t find the equivalent of AFL “Null” instructions: in this case, it would be used in the calculation of upline and dnline for the value given after the “else” condition. “Null” then generates NO plotting of the indicator. Due to that, I had to use the “coloured” params to try make the indicator invisible on the chart (white colour on a white background chart) but it is not very “handsome”

Enjoy this nice indicator, and thank you for any improvement/help.

PRT code for EnsignVolatStop

//Defparam Calculateonlastbars = 6000
VSraw = k * exponentialaverage[period](AverageTrueRange[1](close))
// for longs, VS line is below price
loline = HIGHEST[PERIOD](CLOSE) - VSraw
// for shorts, VS line is above price
hiline = LOWEST[period](Close) + VSraw

if close < hiline and close > loline then
between = 1
else
between = 0
endif

if close>hiline or (high > high[1] and high > hiline) then
up = 1
else
up = 0
endif

if close < loline or (low < low[1] and low < loline) then
dn = 1
else
dn = 0
endif

if between and barssince(up) < barssince(dn) then
upcond = 1
else
upcond = 0
endif

if between and barssince(dn) < barssince(up) then
dncond = 1
else
dncond = 0
endif

if up or upcond then
upline = loline
r1= 0
g1= 0
b1= 255

else
upline = upline[1]
r1=255
g1=255
b1=255
endif

if dn or dncond then
dnline= hiline
r3=255
g3=0
b3=0
else
dnline = dnline[1]
r3=255
g3=255
b3=255
endif

return upline coloured(r1,g1,b1) as "Upline", dnline coloured(r3,g3,b3)as "DownLine"

 

 

Download
Filename: Ensign-volatility-stop.itf
Downloads: 406
carlvan Average
Code artist, my biography is a blank page waiting to be scripted. Imagine a bio so awesome it hasn't been coded yet.
Author’s Profile

Comments

Logo Logo
Loading...