| Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
I have custom formula that Bruce created a while ago called Volatility stop in 2.0 we had to write a code block on this how do I recreate this in 3.1? Do I just copy and paste the Block?
Thanks
|
|
 Worden Staff
Joined: 8/16/2006 Posts: 320
|
thinkbigr,
I will move this to the Ask a Trainer forum on your behalf. Thank you
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
thnkbigr,
Please try creating the following RealCode Indicator:
'# period = UserInput.Single = 14
'# factor = UserInput.Single = 3
'#Cumulative
Static TR As Single
Static ATR As Single
Static termRatio As Single
static Weight As Single
Static sumWeight As Single
Static extreme As Single
Static tstop As Single
Static state As Boolean
If isFirstBar Then
TR = Price.High - Price.Low
termRatio = (period - 1) / period
ATR = TR
sumweight = termratio + 1
weight = 1 / sumweight
If Price.Last(-1) - System.Math.Min(Price.Low,Price.Low(-1)) < _
System.Math.Max(Price.High,Price.High(-1)) - Price.Last(-1) Then
extreme = Price.Last
tstop = extreme + factor * TR
state = False
Else
extreme = Price.Last
tstop = extreme - factor * TR
state = True
End If
Plot = tstop
Else
TR = (Price.High-Price.Low+ _
System.Math.Abs(Price.High-Price.Last(1))+ _
System.Math.Abs(Price.Last(1)-Price.Low))/2
ATR = ATR * (1 - weight) + weight * TR
sumweight = sumweight * termratio + 1
weight = 1 / sumweight
If state
If Price.Last < tstop
state = False
extreme = Price.Last
tstop = extreme + factor * ATR
End If
Else
If Price.Last > tstop
state = True
extreme = Price.Last
tstop = extreme - factor * ATR
End If
End If
Plot = tstop
If state
extreme = System.Math.Max(extreme,Price.Last)
tstop = extreme - factor * ATR
Else
extreme = System.Math.Min(extreme,Price.Last)
tstop = extreme + factor * ATR
End If
End If
It is based on the Custom Code Block in the Parabolic SAR using ATR topic.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
You know without you nothing I do here would be possible thanks a lot.
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce I created 2 conditions 1)price above Volatility stop and 2) Price below it and when I run a test on COMPQX alone it doesn't create any trades but when i change it to Crossing above and below it works I have no idea why the above and below doesn't work.
Also I ran the same test in 2.0 I get the same # of trades with same # of winners and losers but the Startegy Equity Line is at a different value. This is the same issue on all other tests that i have and you are already looking into.
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I get Trades when using Above and Below Conditions (I do not need to change it to Crossing Up Through or Crossing Down Through). I don't know why it wouldn't work for you.
You are correct that it probably is the same issue. I have not been able to figure out the differences in the Equity Lines in Blocks 2 and Blocks 3.1 yet.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
it works now thank
I now need to make a market indicator with this that it will only buy stocks that are part of the active watch list when COMPQX it self is above its volatility stop and sell all when COMPQX fall below its volatility stop.
In 2.0 I just had to change the Test symbol block to COMPQX in 3.1 I think I need to change the Bar Chart Price History to COMPQX if this is correct where do I get the COMPQX Block?
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
thnkbigr,
Select Indicators | Price History to add an additional Price History Pane with an adjustable Symbol to the Chart (you can left-click on the new Price History to bring up QuickEdit and adjust the Symbol).
You'll then need to create a RealCode Indicator that uses this as the "parent" instead of using Price.
- Select RealCode Editor | Indicator.
- Drag and Drop the new Price History into the RealCode Editor. It should create something like the following:
'# PH = indicator.PriceHistory.5
We're actually going to change the PH to parent, but that would be necessary, it's just a variable name. You'll want the RealCode to look like the following (but the indicator.PriceHistory.5 part could be whatever Indicator you decided to Drag and Drop into the RealCode Editor and rename to parent - again, the name isn't important):
'# parent = indicator.PriceHistory.5
'# period = UserInput.Single = 14
'# factor = UserInput.Single = 3
'#Cumulative
Static TR As Single
Static ATR As Single
Static termRatio As Single
static Weight As Single
Static sumWeight As Single
Static extreme As Single
Static tstop As Single
Static state As Boolean
If isFirstBar Then
TR = parent.High - parent.Low
termRatio = (period - 1) / period
ATR = TR
sumweight = termratio + 1
weight = 1 / sumweight
If parent.Last(-1) - System.Math.Min(parent.Low,parent.Low(-1)) < _
System.Math.Max(parent.High,parent.High(-1)) - parent.Last(-1) Then
extreme = parent.Last
tstop = extreme + factor * TR
state = False
Else
extreme = parent.Last
tstop = extreme - factor * TR
state = True
End If
Plot = tstop
Else
TR = (parent.High-parent.Low+ _
System.Math.Abs(parent.High-parent.Last(1))+ _
System.Math.Abs(parent.Last(1)-parent.Low))/2
ATR = ATR * (1 - weight) + weight * TR
sumweight = sumweight * termratio + 1
weight = 1 / sumweight
If state
If parent.Last < tstop
state = False
extreme = parent.Last
tstop = extreme + factor * ATR
End If
Else
If parent.Last > tstop
state = True
extreme = parent.Last
tstop = extreme - factor * ATR
End If
End If
Plot = tstop
If state
extreme = System.Math.Max(extreme,parent.Last)
tstop = extreme - factor * ATR
Else
extreme = System.Math.Min(extreme,parent.Last)
tstop = extreme + factor * ATR
End If
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
Bruce can you explain the one bar look ahead in the if statement
...
...
If parent.Last(-1) - System.Math.Min(parent.Low,parent.Low(1)) < _
System.Math.Max(parent.High,parent.High(1)) - parent.Last(1) Then
extreme = parent.Last
tstop = extreme + factor * TR
state = False
Else
extreme = parent.Last
tstop = extreme - factor * TR
state = True
End If
...
...
It seems like a bug as 3 bars worth of data is being used:
Tomorrow's Close: Last(-1)
and Yesterday's H, L and C: High(1) and Low(1) and Last(1)
Today's H, L : High and Low
Maybe just Last instead of Last(-1)?
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
jas0501,
It's wrong, but actually everything that has a 1 should have a -1, not the other way around. I've corrected it above. There aren't any previous Bars on the the first Bar of the Plot.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
Bruce,
I should just click on the indicator then Edit realcode erase everthing but the first line and paste the above since you corrected somethings?
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
thnkbigr,
Yes. That is what you would need to do to correct the RealCode. I will point out however that this is just a bit of code that determines the initial state of the Indicator. It should have little or no effect once the Indicator his switched states a few times (I even thought about setting the state randomly when originally creating the Indicator).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 3/31/2006 Posts: 3,207
|
ok thanks
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
thnkbigr,
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
|
Guest-1 |