LazyBear

Volatility Switch Indicator [LazyBear]

The Volatility Switch (VOLSWITCH) indicator, by Ron McEwan, estimates current volatility in respect to historical data, thus indicating whether the market is trending or in mean reversion mode. Range is normalized to 0 - 1.

When Volatility Switch rises above the 0.5 level, volatility in the market is increasing, thus the price action can be expected to become choppier with abrupt moves. When the indicator falls below the 0.5 level from recent high readings, volatility decreases, which may be considered a sign of trend formation.

Trading strategy as suggested by Ron McEwan is:
- If VOLSWITCH is less than 0.5, volatility decreases, which may be considered a sign of trend formation
- If VOLSWITCH is greater than 0.5, market is in high volatility mode. Can be choppy. Use RSI to look for OB/OS levels.

I have implemented support for 2 lengths (14 and 21) Note that, Pine doesn't support loops. Once it is introduced, I will publish an updated version.

Building a strategy out of this is straightforward (refer to my strategy explanation above), I strongly encourage new Pinescript coders to try to a plotarrow() based overlay indicator to get more familiar with Pine.

More info:
---------
The Volatility (Regime) Switch Indicator : traders.com/Document.../2013/02/McEwan.html

Complete list of my indicators:
-------------------------------------
docs.google.com...ByMEvm5MLo/edit?usp=sharin...

List of my free indicators: bit.ly/1LQaPK8
List of my indicators at Appstore: blog.tradingview.com/?p=970
สคริปต์โอเพนซอร์ซ

ด้วยจิตวิญญาณของ TradingView อย่างแท้จริง ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ไชโยให้กับผู้เขียน! คุณสามารถใช้ได้ฟรี แต่การใช้รหัสนี้ซ้ำในสิ่งพิมพ์อยู่ภายใต้กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ เงื่อนไขการใช้บริการ

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?
//
// @author LazyBear 
// List of all my indicators: 
// https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9WIKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
//
study(title="Volatility Switch [LazyBear]", shorttitle="VOLSWITCH_LB")
dr= roc(close,1)/sma(close,2)
dummy=input(false, title="------- Choose lengths below ----"), il21=input(true, title="21"), il14=input(false, title="14")

vola21=stdev(dr, 21)
vswitch21=((vola21[1] <= vola21 ) + (vola21[2] <= vola21 ) +   (vola21[3] <= vola21 ) +   
		(vola21[4] <= vola21 ) +  (vola21[5] <= vola21 ) + (vola21[6] <= vola21 ) +   
		(vola21[7] <= vola21 ) +  (vola21[8] <= vola21 ) +  (vola21[9] <= vola21 ) +  
		(vola21[10] <= vola21 ) + (vola21[11] <= vola21 ) +  (vola21[12] <= vola21 ) +  
		(vola21[13] <= vola21 ) +  (vola21[14] <= vola21 ) +  (vola21[15] <= vola21 ) +  
		(vola21[16] <= vola21 ) +  (vola21[17] <= vola21 ) +  (vola21[18] <= vola21 ) +  
		(vola21[19] <= vola21 ) +  (vola21[20] <= vola21 ) + 1) / 21

vola14=stdev(dr, 14)
vswitch14=((vola14[1] <= vola14 ) + (vola14[2] <= vola14 ) +   (vola14[3] <= vola14 ) +   
		(vola14[4] <= vola14 ) +  (vola14[5] <= vola14 ) + (vola14[6] <= vola14 ) +   
		(vola14[7] <= vola14 ) +  (vola14[8] <= vola14 ) +  (vola14[9] <= vola14 ) +  
		(vola14[10] <= vola14 ) + (vola14[11] <= vola14 ) +  (vola14[12] <= vola14 ) +  
		(vola14[13] <= vola14 ) + 1) / 14 
 
hline(0.5, title="Median")
plot(il21?vswitch21:na, color=red, linewidth=2, title="VOLSWITCH_21")
plot(il14?vswitch14:na, color=green, linewidth=2, title="VOLSWITCH_14")