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 |

VolatilityStop Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
thnkbigr
Posted : Monday, August 11, 2008 11:01:10 AM
Platinum Customer 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

Nicole_sx110513
Posted : Monday, August 11, 2008 5:33:53 PM

Worden Staff

Joined: 8/16/2006
Posts: 320
thinkbigr,

          I will move this to the Ask a Trainer forum on your behalf. Thank you
Bruce_L
Posted : Thursday, August 14, 2008 4:30:29 PM


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
thnkbigr
Posted : Thursday, August 14, 2008 4:33:13 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
You know without you nothing I do here would be possible thanks a lot.
Bruce_L
Posted : Thursday, August 14, 2008 4:36:32 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Thursday, August 14, 2008 4:57:49 PM
Platinum Customer 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.

 
Bruce_L
Posted : Friday, August 15, 2008 12:04:44 PM


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
thnkbigr
Posted : Friday, August 15, 2008 3:20:45 PM
Platinum Customer 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?

Bruce_L
Posted : Friday, August 15, 2008 3:43:12 PM


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
jas0501
Posted : Friday, August 15, 2008 11:31:07 PM
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)?

Bruce_L
Posted : Monday, August 18, 2008 10:38:38 AM


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
thnkbigr
Posted : Monday, August 18, 2008 11:05:09 AM
Platinum Customer 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? 
Bruce_L
Posted : Monday, August 18, 2008 11:09:09 AM


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
thnkbigr
Posted : Monday, August 18, 2008 11:14:10 AM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
ok thanks
Bruce_L
Posted : Monday, August 18, 2008 11:16:30 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
thnkbigr,
You're welcome.

-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.