Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Volatility Stop Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Sonja
Posted : Saturday, November 11, 2006 4:15:25 AM
Registered User
Joined: 10/22/2006
Posts: 17
hi, i wonder whether it is possible to apply the following to snap sheet or tc:
1) a volatility stop: a line drawn automatically above or below the market prices. it is like the parabolic stop in that the line is below when prices are trending up and flips above when prices are moving down, but is calculated differently from the parabolic stop. The lines are calculated as follows:
Long: [highest price] - [2.5 x (ATR of the last 9 bars)]
Short: [lowest price] + [2.5 x (ATR of the last 9 bars)]

Only one line is displayed at a time. If long, the line flips to short on bar close below the v-stop line. If short, the line flips to long on bar close above the v-stop line.
2) can the software automatically draw a line from the highest to the lowest price during the time prices where above the volatility stop after it flipped? after it flipped again connect low to high again and so on
thank you all very much
Craig_S
Posted : Saturday, November 11, 2006 4:29:21 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
A few questions:

QUOTE
when prices are trending up and flips above when prices are moving down

Over what period are you measuring to decide if it is trending up or down?

Is [highest price] the high for the day, the highest high for X days, the highest close for X days? If highest of X, what is X?

Is [lowest price] the low for the day, the lowest low for X days, the lowest close for X days? If lowest of X, what is X?

How does the program know if you are "long" or "short"?



- Craig
Here to Help!
Sonja
Posted : Monday, November 13, 2006 2:45:44 AM
Registered User
Joined: 10/22/2006
Posts: 17
hi, thank you for your fast reply! the volatility stop is also known as the Chandelier stop:
The Chandelier Stop is a trailing stop that is based on the volatility of the market. It has been successfully used and recommended by a number of traders, including Chuck LeBeau, for trend-following systems. The equations for the Chandelier Stop (CS) indicator recently incorporated into the FT Program are as follows:

If Long: CS=HH-Factor*EMA(Range, Length)
If Short: CS=LL+Factor*EMA(Range,Length)

Here, HH denotes the highest High since the indicator flipped from Short to Long, LL is the lowest Low since the indicator flipped from Long to Short, and EMA represents an exponential moving average. Values of Factor and Length are input by the user, with the default values set to 3 and 20, respectively. When used for long-term, trend-following systems, the best values for Factor in most markets range from 2.5 to 4.0, while the Length is usually set in the range from 10 to 20.

as to long /short: when price closes above the the last short stop (LL+2.5 ATR) then we are long and it flips to display the long stop, until price closes below it

i hope it helped, otherwise - just ask
thank you very much
Craig_S
Posted : Monday, November 13, 2006 6:38:42 AM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
In theory, this should be doable in SnapSheets. Let me play around with some ideas.

- Craig
Here to Help!
Sonja
Posted : Monday, November 13, 2006 5:57:44 PM
Registered User
Joined: 10/22/2006
Posts: 17
ok, thank you, that would be great! i know ensign and quotetracker have it if it helps you
Sonja
Posted : Tuesday, November 14, 2006 5:28:59 PM
Registered User
Joined: 10/22/2006
Posts: 17
this definition would be ok to use, too:
Volatility Stop Calculations

True Range = High - Low
(Substitute the previous bar's Close for the High, if higher than the current High.)
(Substitute the previous bar's Close for the Low, if lower than the current Low.)
Average True Range (ATR) = Exponential moving average of each bar's true range using N periods.
Volatility Stop (when short) = Lowest Close (since entering the trade) + (ATR * Multiplier)
Volatility Stop (when long) = Highest Close (since entering the trade) - (ATR * Multiplier)

thank you very much
bustermu
Posted : Wednesday, November 15, 2006 2:35:32 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (Sonja)
The equations for the Chandelier Stop (CS) indicator ... are as follows:

If Long: CS=HH-Factor*EMA(Range, Length)
If Short: CS=LL+Factor*EMA(Range,Length)

Here, HH denotes the highest High since ... (going) ... Long, LL is the lowest Low since ... (going) ... Short.


In the following, we will plot the CSs where Factor = 2.5 and Length = 9. Since the CSs are applied to the Close they are assumed to be calculated at the Close.

The CSs are plotted for SP-500 as Custom Indicators with "Plot using price scale" checked. The trades are entered at the Close on the dates specified.

Long 10/20/06:
ABS(V0=16391)*(MAXH1-2.5*(XAVGH9-XAVGL9))
+ABS(V1=16391)*(MAXH2-2.5*(XAVGH9-XAVGL9))
+ABS(V2=16391)*(MAXH3-2.5*(XAVGH9-XAVGL9))
+ABS(V3=16391)*(MAXH4-2.5*(XAVGH9-XAVGL9))
+ABS(V4=16391)*(MAXH5-2.5*(XAVGH9-XAVGL9))
+ABS(V5=16391)*(MAXH6-2.5*(XAVGH9-XAVGL9))
+ABS(V6=16391)*(MAXH7-2.5*(XAVGH9-XAVGL9))
+ABS(V7=16391)*(MAXH8-2.5*(XAVGH9-XAVGL9))
+ABS(V8=16391)*(MAXH9-2.5*(XAVGH9-XAVGL9))
+ABS(V9=16391)*(MAXH10-2.5*(XAVGH9-XAVGL9))
+ABS(V10=16391)*(MAXH11-2.5*(XAVGH9-XAVGL9))
+ABS(V11=16391)*(MAXH12-2.5*(XAVGH9-XAVGL9))
+ABS(V12=16391)*(MAXH13-2.5*(XAVGH9-XAVGL9))
+ABS(V13=16391)*(MAXH14-2.5*(XAVGH9-XAVGL9))
+ABS(V14=16391)*(MAXH15-2.5*(XAVGH9-XAVGL9))
+ABS(V15=16391)*(MAXH16-2.5*(XAVGH9-XAVGL9))
+ABS(V16=16391)*(MAXH17-2.5*(XAVGH9-XAVGL9))
+ABS(V17=16391)*(MAXH18-2.5*(XAVGH9-XAVGL9))
+ABS(V18=16391)*(MAXH19-2.5*(XAVGH9-XAVGL9))
+ABS(V19=16391)*(MAXH20-2.5*(XAVGH9-XAVGL9))

Short 11/03/06:
ABS(V0=15189)*(MINL1+2.5*(XAVGH9-XAVGL9))
+ABS(V1=15189)*(MINL2+2.5*(XAVGH9-XAVGL9))
+ABS(V2=15189)*(MINL3+2.5*(XAVGH9-XAVGL9))
+ABS(V3=15189)*(MINL4+2.5*(XAVGH9-XAVGL9))
+ABS(V4=15189)*(MINL5+2.5*(XAVGH9-XAVGL9))
+ABS(V5=15189)*(MINL6+2.5*(XAVGH9-XAVGL9))
+ABS(V6=15189)*(MINL7+2.5*(XAVGH9-XAVGL9))
+ABS(V7=15189)*(MINL8+2.5*(XAVGH9-XAVGL9))
+ABS(V8=15189)*(MINL9+2.5*(XAVGH9-XAVGL9))
+ABS(V9=15189)*(MINL10+2.5*(XAVGH9-XAVGL9))

The Long position was reversed upon the stop violation on 11/03/06. The Short position was closed upon the stop violation on 11/14/06. The two volumes, 16391 and 15189, are used solely for the purpose of marking the dates of entry of the trades.

The PCFs could have been written using ATR in place of Average Range, but they would be very long. Also, one PCF could have been written which would switch the CSs each time a stop was violated. The length would be well beyond my tolerance limits.

Suppose we wish to plot the CS curve which switched each time a stop is violated. Two additional constraints are needed regardless of the program language used:

1) An initial entry position and date.

2) The procedure to follow when a stop is violated and a position reversal would result in a new stop violation on the same day.

Thanks,
Jim Murphy
Sonja
Posted : Wednesday, November 15, 2006 5:16:05 PM
Registered User
Joined: 10/22/2006
Posts: 17
as to 2) as it is only close - it can only be above or below the volatility line!
but as i get it one would have to code it every day. in ensign or quotetracker you simply add the volatility stop as an indicator and it is displayed as a line above or below the prices. too bad i am a bad programmer - but thank you for your ideas
bustermu
Posted : Friday, November 17, 2006 3:31:11 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (Sonja)
... too bad i am a bad programmer - but thank you for your ideas


Sonja,

Just a note to point out that no one can code the CS Indicator regardless of their skill or the program language without knowing the response to Items 1) and 2) in my previous post.

I am unaware that I presented any ideas in my post, but you are welcome anyway.

Thanks,
Jim Murphy
Sonja
Posted : Friday, November 17, 2006 10:27:26 AM
Registered User
Joined: 10/22/2006
Posts: 17
1.Volatility Stop (when short) = Lowest Close (since entering the trade) + (ATR * Multiplier)
2.Volatility Stop (when long) = Highest Close (since entering the trade) - (ATR * Multiplier)

once price closes above the "short volatility stop" it flips to long, and the long volatility stop is displayed as a line below the prices. when a price closes below the "long volatility stop line" the volatility stop flips and the "short volatility stop" is displayed as a line above the prices and so on.

so "you are long" when price closes above the 1. volatility stop, and "you are short" when price closes below the 2. volatility stop
so you do not need a initial entry date. as this is end of thay it can only close above or below the line, so there cannot be a intraday reversal of stops
Sonja
Posted : Friday, November 17, 2006 10:48:17 AM
Registered User
Joined: 10/22/2006
Posts: 17
i found a example of how it looks in ensignsoftware:


the orange line is the volatility stop that flips from above to below prices

thank you all
Sonja
Posted : Monday, November 20, 2006 10:19:13 AM
Registered User
Joined: 10/22/2006
Posts: 17
seems like my answers don´t help any ideas?
bustermu
Posted : Monday, November 20, 2006 10:51:19 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Sonja,

The plot is interesting.

Ensign says of the Volatility Stop "The average true range is multiplied by a specified value and then added to the lowest close (since entering the trade) while short, or subtracted from the highest close (since entering the trade) while long."

If we take "specified value" to mean a constant, the description is obviously not what the orange line shows.

The description is adequate to plot a stop for a particular trade but not complete enough to plot the Volatility Stop Indicator. That is so since, in general, the plot the cannot be constructed without knowing the response to the Items 1) and 2) in my previous post.

It would be nice to have a more complete description.

Suppose we had a response to Item 2 adequate to prevent the program from going into a limit cycle (which would require a defibrillator). It would be interesting to know a characterization of those price data sequences for which the plot is asymptotically invariant with the initial date (bar) and position (long or short), i.e., the plots all eventually coincide regardless of the starting date and position. But, that is a question for mathematicians, not traders.

Thanks,
Jim Murphy
Sonja
Posted : Monday, November 20, 2006 11:59:45 AM
Registered User
Joined: 10/22/2006
Posts: 17
Hi Jim,
sorry, the Correct Formula is:
1.Volatility Stop (when short) = Lowest Close (since entering the trade) + (ATR * Multiplier)
2.Volatility Stop (when long) = Highest Close (since entering the trade) - (ATR * Multiplier)
Here ATR is 9 and Multiplier 2.5
I guess it simply starts calculating both lines with the first 9 bars, then checks whether price is above the long volatility stop or below the short volatility stop. as i said, long and short are not really positions, only a name for the upper and lower line.
thanks
Sonja
Posted : Wednesday, November 22, 2006 12:53:17 PM
Registered User
Joined: 10/22/2006
Posts: 17
do you have a idea, craig? thank you
Bruce_L
Posted : Wednesday, November 22, 2006 2:25:09 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Sonja,
I've been playing with this. It looks like the easiest way to do this in SnapSheets will involve writing a Custom Code Block. I will hopefully have something for you fairly soon.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Wednesday, November 22, 2006 4:05:05 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (Bruce_L)
Sonja,
I've been playing with this. It looks like the easiest way to do this in SnapSheets will involve writing a Custom Code Block. I will hopefully have something for you fairly soon.


Bruce,

I have not yet seen sufficient information for defining the the Volatility Stop Indicator. Have you?

I have considered the following:

1a) Go long at the close X bars ago, or,
1b) Go short at the close X bars ago.
2) Reverse a long or short position at the close if the stop is violated by the close.
3a) Do not decrease a long stop.
3b) Do not increase a short stop.
4a) If the position is long, plot:
Highest Close (since entering the long position) - (ATR*Multiplier)
4b) If the position is short, plot:
Lowest Close (since entering the short position) + (ATR*Multiplier)

I believe these conditions are sufficient to define the plot.

Condition 1a) or 1b) supplies the initial condition. Without similar conditions, it is not known how to start the plot.

For 2), a position is reversed with a stop violation by the close because if it was reversed with a violation by any portion of the bar, the new stop could be immediately violated.

The conditions 3a) and 3b) are optional.

Conditions 4a) and 4b) use the Higest Close and the Lowest Close because if the Highest High and Lowest Low were used, a position reversal could result in an immediate violation of the new stop.

Please notice that both stops should be plotted for a position reversal bar.

I would greatly appreciate your comments on these conditions and whatever alternatives you may be considering.

I might even be willing to plot it in TeleChart for X = 3 (or maybe even 4) if we delete 3a) and 3b) and replace ATR by Average Range. With a little prodding, I might even include 3a) and 3b), but no ATR for me.

Thanks,
Jim Murphy
diceman
Posted : Thursday, November 23, 2006 10:26:56 AM
Registered User
Joined: 1/28/2005
Posts: 6,049
Obviously I could be wrong since there is no info on this but it
appears to my eye that the orange line is some type of MINL
or MAXH.(over some period) Possibly delayed a few bars. MINL.1 or MINL.3.

Notice when the indicator "flatlines" it does so exactly at previous
highs and lows. Which would indicate there is no volatility offset.

Also the indicator does not appear to change in its relationship to
price. A volatility stop will typically "rush" to meet price as volatility
drops.

The last thing is its title. "Trend" implies it my not be a stop at all.
Just a greenlight/redlight to go long or short when price is above it.

If it was called VSTOP or VS I would have a greater belief it
was a volatility stop.

There is an indicator I believe called the "high low activator". It draws
an exponential moving average of the lows or highs depending if
price is above or below it. I believe this is a version of the same thing.
except it substitutes MAXH or MINL. (or some version of them:
MINL10.3 or MINL8.6 and so on)

There is nothing by my eyes to indicate ATR is even being used
in this indicator.

Thanks
diceman

bustermu
Posted : Thursday, November 23, 2006 11:49:43 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
diceman,

Nice observation.

I knew the orange line was not a Volatility Stop, but I did not know what it was until I read your post.

The orange line is constructed as follows:

1) Reverse a long or short position if the stop is violated by any portion of the bar.
2a) If the position is long, plot: MINL10.1
2b) If the position is short, plot: MAXH10.1

That may not be the exact algorithm used to obtain the plot, but, for the chart shown, they will overlay exactly.

Thanks,
Jim Murphy
Sonja
Posted : Friday, November 24, 2006 2:59:31 PM
Registered User
Joined: 10/22/2006
Posts: 17
i posted a daily chart and you can see that the volatility stop is calculated using the atr as i mentioned it in the formula. it may be though that i chose a wrong chart the longer i look at it - sorry
here is the new one:
http://charts.dacharts.com/2006-11-24/JF-28.png

thank you bruce and all
bustermu
Posted : Saturday, November 25, 2006 10:00:22 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
I have not found anything about the new plot that disagrees with the description except that it is delayed one bar. The exception to the one bar delay is that the new stop is also plotted without a delay at a position reversal bar.

Thanks,
Jim Murphy
Sonja
Posted : Monday, November 27, 2006 5:53:33 PM
Registered User
Joined: 10/22/2006
Posts: 17
wow, if it looks the same it should work! great - thank you! i am not a programmer and simply rely on the info of ensignsoftware! as written earlier Quotetracker uses a ema to construct the volatility stop. what would the chart look like the way you constructed the volatility stop? do you have a picture?
thank you very much for your efforts to help me!
Sonja
Posted : Wednesday, December 6, 2006 5:28:33 PM
Registered User
Joined: 10/22/2006
Posts: 17
did you find anything bruce?
Bruce_L
Posted : Wednesday, December 6, 2006 8:23:13 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Sonja,
I apologize. The last post I'd seen in this topic was bustermu's Thursday, November 23, 2006 11:49:43 AM ET post. The discussion at that point seemed to have determined how to reproduce the picture you had posted. I did not notice another picture had been posted since.

You may wish to review the following before attempting this:

Hello World! Writing Code Blocks for SnapSheets in Visual Basic.NET
Creating a True Range Block
Your First 3 Block Diagrams

It's possible to create all of this without creating any Custom Code Blocks, but the Block Diagrams can become quite complex. One way to create your Volatility Stop in SnapSheets is to start by creating the following Code Block as Bar to Line (please keep in mind I'm not a programmer):

BEL Volatility Stop:

Replace:

'************ Your Code Here ***************

With:

If InputCount > 1
Dim H As Single = InputHigh(1)
Dim L As Single = InputLow(1)
Dim H1 As Single = InputHigh(0)
Dim L1 As Single = InputLow(0)
Dim C1 As Single = InputLast(0)
Dim TR As Single = (H-L+System.Math.Abs(H-C1)+System.Math.Abs(C1-L))/2
Dim ATR As Double = 0
Dim period As Integer = 9
Dim factor As Single = 2.5
Dim extreme As Single = System.Math.Min(InputLow(0),InputLow(1))
Dim tstop As Single = extreme + factor * TR
Dim state As Integer = 0
Dim termratio As Double = (period - 1) / period
Dim weight As Double = 1
Dim sumweight As Double = 1
For bar As Integer = 1 To InputCount - 1
H = InputHigh(bar)
L = InputLow(bar)
H1 = InputHigh(bar-1)
L1 = InputLow(bar-1)
C1 = InputLast(bar-1)
TR = (H-L+System.Math.Abs(H-C1)+System.Math.Abs(C1-L))/2
ATR = ATR * (1 - weight) + weight * TR
sumweight = sumweight * termratio + 1
weight = 1 / sumweight
If state
If L < tstop
state = 0
extreme = L
tstop = extreme + factor * ATR
End If
Else
If H > tstop
state = 1
extreme = H
tstop = extreme - factor * ATR
End If
End If
AddToOutput(InputDate(bar),tstop)
If state
extreme = System.Math.Max(extreme,H)
tstop = System.Math.Max(tstop,extreme - factor * ATR)
Else
extreme = System.Math.Min(extreme,L)
tstop = System.Math.Min(tstop,extreme + factor * ATR)
End If
Next
End If

Then create a Plot in New Pane with a Block Diagram similar to:



The Bar Chart Price History Block is your existing Price Plot. You may wish to review the following:

SnapSheets Website
SnapSheets Tutorial Videos

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Thursday, December 7, 2006 4:07:25 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

I do not know the code, but I have some comments.

1) The Stop (tstop) is initialized with the short position (state = 0).
2) Reverse a long or short position if the Stop is violated by any portion of the price bar.
3a) A long Stop is not decreased.
3b) A short Stop is not increased.
4a) If the position is long, plot:
Highest High (since entering the long position) - factor*ATR
4b) If the position is short, plot:
Lowest Low (since entering the short position) + factor*ATR

In order to match the requirements, the code should be changed as follows:

1) I do not know the initialization.
2) Reverse a long or short position if the stop (delayed by one bar) is violated by the close.
3a) A long Stop can decrease.
3b) A short Stop can increase.
4a) If the position is long,
Stop = Highest Close (since entering the long position) - factor*ATR
4b) If the position is short,
Stop = Lowest Close (since entering the short position) + factor*ATR

Notes:
a) The ATR should be calculated as an EMA9 rather than a Wilder Smoothing of Period 9.
b) The H and L are used only in calculating True Range (TR).
c) The Stop is plotted delayed one bar except at a reversal bar the new stop is also plotted.
d)I believe the two "If state" should be "If state = 1".

Thanks,
Jim Murphy
Bruce_L
Posted : Thursday, December 7, 2006 9:09:20 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (bustermu)
1) The Stop (tstop) is initialized with the short position (state = 0).
-----code above-----requirements below-----
1) I do not know the initialization.

It really doesn't matter much unless you are looking at the very start of the chart. I fiddled with different types of initialization, but kept taking it out because it just made the code longer with little benefit.

QUOTE (bustermu)
2) Reverse a long or short position if the Stop is violated by any portion of the price bar.
-----code above-----requirements below-----
2) Reverse a long or short position if the stop (delayed by one bar) is violated by the close.

I couldn't tell that from looking at the supplied chart (can you see anyplace on the chart where this distinction could be made?), but I see Sonja supplied this information elsewhere.

QUOTE (bustermu)
3a) A long Stop is not decreased.
3b) A short Stop is not increased.
-----code above-----requirements below-----
3a) A long Stop can decrease.
3b) A short Stop can increase.

That doesn't make for a very disciplined stop... then again, I guess it's not a real trade is it? It actually shortens the code ever so slightly to do it this way and it is obvious from the supplied chart that this is actually the case.

QUOTE (bustermu)
4a) If the position is long, plot:
Highest High (since entering the long position) - factor*ATR
4b) If the position is short, plot:
Lowest Low (since entering the short position) + factor*ATR
-----code above-----requirements below-----
4a) If the position is long,
Stop = Highest Close (since entering the long position) - factor*ATR
4b) If the position is short,
Stop = Lowest Close (since entering the short position) + factor*ATR

Are you sure? There appear to be several instances on the chart where the stop moves with a new extreme in price and not a new extreme in the close. I suppose it could be entirely the result of changes in the ATR, but it doesn't look like it.

QUOTE (bustermu)
a) The ATR should be calculated as an EMA9 rather than a Wilder Smoothing of Period 9.

I just automatically think Wilder's Smoothing when I think ATR, but it is easy enough to change. Sonja did indicate Exponential Smoothing.

QUOTE (bustermu)
b) The H and L are used only in calculating True Range (TR).

This certainly seems to be the case based on the descriptions, but I'm not so sure it's true based on the evidence of the chart (see above).

QUOTE (bustermu)
c) The Stop is plotted delayed one bar except at a reversal bar the new stop is also plotted.

I think I'm actually doing these steps in the right order:

- Check for violation of existing stop.
-- Reverse and set new stop if violated.
- Plot stop.
- Calculate new stop.

QUOTE (bustermu)
d)I believe the two "If state" should be "If state = 1".

We could "state" this explicitly, but it doesn't need to be. "If state" is True when state = 1 and False when state = 0 anyway.

I'll write another version (or two) to compare to the supplied chart. The chart has a symbol and dates, so there's a chance to figure out which version most closely emulates the charted indicator.

PS - You do know SnapSheets is free, right?

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Thursday, December 7, 2006 10:17:45 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
Bruce,

Thanks for your response.

I am going to respond in detail, but I am wondering if you are always looking at the correct Chart? By my count, the bar (not the close) violates the Stop nine times without reversing position.

Did you know that you can zoom in by clicking on the Chart?

Thanks,
Jim Murphy
Bruce_L
Posted : Thursday, December 7, 2006 11:11:59 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bustermu,
So far, the closest result appears to be:

If InputCount > 1
Dim H As Single = InputHigh(1)
Dim L As Single = InputLow(1)
Dim C As Single = InputLast(0)
Dim H1 As Single = InputHigh(0)
Dim L1 As Single = InputLow(0)
Dim C1 As Single = InputLast(0)
Dim TR As Single = H-L
Dim ATR As Double = 0
Dim period As Integer = 9
Dim factor As Single = 2.5
Dim extreme As Single
Dim tstop As Single
Dim state As Integer
If C - System.Math.Min(L,L1) < System.Math.Max(H,H1) - C
extreme = C1
tstop = extreme + factor * TR
state = 0
Else
extreme = C1
tstop = extreme - factor * TR
state = 1
End If
AddToOutput(InputDate(0),tstop)
Dim termratio As Double = (period - 1) / period
Dim weight As Double = 1
Dim sumweight As Double = 1
For bar As Integer = 1 To InputCount - 1
H = InputHigh(bar)
L = InputLow(bar)
C = InputLast(bar)
H1 = InputHigh(bar-1)
L1 = InputLow(bar-1)
C1 = InputLast(bar-1)
TR = (H-L+System.Math.Abs(H-C1)+System.Math.Abs(C1-L))/2
ATR = ATR * (1 - weight) + weight * TR
sumweight = sumweight * termratio + 1
weight = 1 / sumweight
If state
If C < tstop
state = 0
extreme = C
tstop = extreme + factor * ATR
End If
Else
If C > tstop
state = 1
extreme = C
tstop = extreme - factor * ATR
End If
End If
AddToOutput(InputDate(bar),tstop)
If state
extreme = System.Math.Max(extreme,C)
tstop = extreme - factor * ATR
Else
extreme = System.Math.Min(extreme,C)
tstop = extreme + factor * ATR
End If
Next
End If

Which would seem to pretty much verify all of your observations. Well, the line seems to match a little bit better with a less sensitive Wilder's Smoothed ATR, but I could be wrong (my powers of observation seem weak). You can try the Exponentially Smoothed version by changing:

Dim termratio As Double = (period - 1) / period

To:

Dim termratio As Double = (period - 1) / (period + 1)

(Before you point it out, technically it isn't Exponentially Smoothed, but the difference approaches zero with enough data points and I like this version better).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Thursday, December 7, 2006 3:53:03 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (Bruce_L)
You can try the Exponentially Smoothed version by changing:

Dim termratio As Double = (period - 1) / period

To:

Dim termratio As Double = (period - 1) / (period + 1)

(Before you point it out, technically it isn't Exponentially Smoothed, but the difference approaches zero with enough data points and I like this version better).


Bruce,

Contrary to your expectations, I am going to point out that your algorithm is absolutely fascinating. You are overqualified and underpaid.

I could not believe that I actually solved the nonlinear difference equation (probably the second in my life), so I know how you got there.

Hopefully, I am not alone in recognizing talent when I see it.

Amazing!

Thanks,
Jim Murphy
Bruce_L
Posted : Thursday, December 7, 2006 5:29:55 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
bustermu,
It is gratifying to read about your impression of the algorithm.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Craig_S
Posted : Thursday, December 7, 2006 6:12:32 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
QUOTE
Hopefully, I am not alone in recognizing talent when I see it.

You are not alone, bustermu.

- Craig
Here to Help!
dmwr
Posted : Wednesday, December 20, 2006 5:07:33 PM
Registered User
Joined: 12/17/2006
Posts: 69
I went through the code and got the stop but it doesn't look like any of the ATR-based stops I've ever seen. For examples:

As examples:

(external links removed by moderator)

This is what I'm trying to get to - looking at the example above a little bit closer, it looks like if I could replace the code with dots it might look very similar - but I would love some feedback.

Secondly, how would I use this as a condition? Say I want to set it as a sell condition? I haven't figured out how to do that.

Thanks in advance,

Damian
dmwr
Posted : Wednesday, December 20, 2006 5:29:57 PM
Registered User
Joined: 12/17/2006
Posts: 69
Studying those pictures a bit more - sorry about the URL problem - it seems like it holds the line until some condition moves the stop up or down.
Bruce_L
Posted : Wednesday, December 20, 2006 6:37:54 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
dmwr,
In the first version of the code (still posted above), the stop does not retreat, but this was altered to match the charts provided by Sonja (since that's what we were attempting).

A Numeric Plot does not currently have an option to plot a single dot for each value. This can be faked however by using a True Markers Plot with a Block Diagram similar to the following:



In the upper right hand corner, change the Flag Type to Circle, the Offset from line to 0, and the Width of flag to something greater than 1. The rest of the settings would be up to you. You may wish to review the following:

Customizing with Properties

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
dmwr
Posted : Thursday, December 21, 2006 2:39:51 PM
Registered User
Joined: 12/17/2006
Posts: 69
That's great - works very well. How would I set this up as a sell condition?

Rocking,

/d/
Bruce_L
Posted : Thursday, December 21, 2006 5:43:44 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
The short answer is that you would check for Bar Low Crossing Down Through the Volatility Stop. I'm not even going to provide a Block Diagram for that because it is not what I would do and I doubt it is what you want to do either. Despite the name, BEL Volatility Stop is not a Stop, it is an Indicator like any other. It doesn't know if you are long or short and it switches its position based on automatic rules.

If you were to use this as a Sell BackScan Condition, it would not know anything about the Buy BackScan Condition. If the BackScan goes Long, but BEL Volatility Stop is Short, BEL Volatility Stop would need to go Long before it could trigger. This means the symbol could go into a free-fall without ever triggering the Stop.

What you want is a Trade Stop Condition. A Trade Stop Condition has a history of the trade available since the Buy BackScan Condition or Sell Short BackScan Condition triggered. I've attached a BackScan Condition to this post. Download the .scond file to:

\My Documents\Blocks Files\Tool Parts\BackScan Conditions

Once downloaded, you should be able to select Add Condition | My Computer when adding a BackScan Condition to access it. You can view its Block Diagram to see how it works. Please let me know if it doesn't do what you want.

Attachments:
Long Volatility Stop.scond - 5 KB, downloaded 672 time(s).



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.