Linear Regression Trend ChannelThis is my first public release of indicator code and my PSv4.0 version of "Linear Regression Channel", as it is more commonly known. It replicates TV's built-in "Linear Regression" without the distraction of heavy red/blue fill bleeding into other indicators. We can't fill() line.new() at this time in Pine Script anyways. I entitled it Linear Regression Trend Channel, simply because it seems more accurate as a proper description. I nicely packaged this to the size of an ordinary napkin within 20 lines of compact code, simplifying the math to the most efficient script I could devise that fits in your pocket. This is commonly what my dense intricate code looks like behind the veil, and if you are wondering why there is no notes, that's because the notation is in the variable naming. I excluded Pearson correlation because it doesn't seem very useful to me, and it would comprise of additional lines of code I would rather avoid in this public release. Pearson correlation is included in my invite-only advanced version of "Enhanced Linear Regression Trend Channel", where I have taken Linear Regression Channeling to another level of fully featured novel attainability using this original source code.
Features List Includes:
"Period" adjustment
"Deviation(s)" adjustment
"Extend Method" option to extend or not extend the upper, medial, and lower channeling
Showcased in the chart below is my free to use "Enhanced Schaff Trend Cycle Indicator", having a common appeal to TV users frequently. If you do have any questions or comments regarding this indicator, I will consider your inquiries, thoughts, and ideas presented below in the comments section, when time provides it. As always, "Like" it if you simply just like it with a proper thumbs up, and also return to my scripts list occasionally for additional postings. Have a profitable future everyone!
الانحراف المعياري
Breakout Reversal Entry on WMA - NG1! Overnight ver 1This script is for learning purposes only
This strategy will plot arrows when price breaks so far above/below WMA. The strategy will enter when the price breaks away from WMA. All entries are reversals. Users can set WMA length and source; also the distance of the price away from WMA to enter. Adjustable bracket orders are placed for exit, with trailing stop or market stop choice. Last, users can set the time of day they want to enter a trade.
My Preference: I am testing this strategy on NG1! over night on 1 minute candle. with .003 on price drop/climb, I get entries almost every night. Also 10 tick stop and 5 tick profit seems backward to most, but with a high win/loss ratio, it performs quite well. Trailing stops generally help out as well.
INPUTS:
Length - The is the WMA length
Source - WMA source (High, Low, Open, Close...)
When Price Drops - This is the distance in ticks when the price drops away from WMA, an arrow is plotted, and reversal entry order is placed
When Price Climbs - Same as price drop, just in the opposite direction
Trailing Stop check box - Check if you want to place a trailing stop so many tick away from entry. Unchecked is Market (hard) stop so many ticks from entry.
Stop - Number of ticks away from entry a the stop or trailing stop is set (for NG 1 tick = $0.001)
Limit Out - Number of ticks away from entry a limit order is placed to take profits
Limit Time of day check box - check to use the time of day to limit what time of day order entry will occur.
Start/Stop Trades (Est Time) - First box is when the strategy will be allowed to start buying and stop is when the strategy will stop being allowed to buy. Sell orders continue until a stop or limit triggers an exit. These times are Eastern time zone
PROPERTIES:
Pyramiding - This feature will allow multiple entries to occur. If set to 1, the strategy should only trade 1 contract at a time. If set to 2, the strategy will enter a second order if entry requirements are met. This allows you to be holding 2 contracts. Basically on a good day, it will multiply your earnings, on a bad day, you'll just lose more. For testing, I keep this on 1.
TIPS:
- If you want to go long only, set "When Price Climbs" to an impossible number, like 10,000. It's not possible for NG to move $10 is a matter of minutes so it will not enter the market with a short order. Also keep in mind you can set different requirements for going long vs going short. If you think there is more pull on the market in a particular direction.
Standard Deviation - Sum Of The Squares Minus Square Of The SumsIntroduction
The standard deviation measure the dispersion of a data set, in short this metric will tell you if your data is on average closer or farther away from the mean. Its one of the most important tools in statistics and living without it is pretty much impossible, without it you can forget about Bollinger-bands, CCI, and even the LSMA (ouch this hurt) .
Now i don't want to extend myself about the standard deviation since that would require a huge post but i want to show you how to calculate the standard deviation from the stdev pinescript function.
Sum Of The Squares Minus Square Of The Sums
Any metric calculated from a moving average can be classified as "running", this mean that the metric constantly update itself and is not constant, this is why it is better to say "running standard deviation" but its okay. If we use the standard calculation for the standard deviation which would be sqrt(sma(pow(close - sma,2))) we might get something totally different from the stdev function :
In white the pine stdev function and in red the standard calculation of both period 4, its clear that both are not the same, one might try to use the Bessel's correction but that won't do either, this is because most technical analysis tools will calculate the square root of the "Sum Of The Squares Minus Square Of The Sums" method to estimate the standard deviation
Another way is to use :
a = sqrt(sma(pow(close,2),length) - pow(sma(close,length),2))
By returning the difference we might still see some errors :
Nothing relevant of course.
Conclusion
Some of you might already be aware of this but a reminder is always good since it can be confusing to make what can be considered the good standard deviation formula and then have something totally different from the pine function, i hope this post will be useful and that you learned something from it.
Thanks for reading :)
Realized VolatilityRealized / Historical Volatility
Calculates historical, i.e. realized volatility of any underlying. If frequency is not the daily, but for example 6h, 30min, weeks or months, it scales the initial setting to be suitable for the different time frame.
Examples with default settings (30 day volatility, 365 days per year):
A) Frequency = Daily:
Returns 30 day historical volatility, under the assumption that there are 365 trading days in a year.
B) Frequency = 6h:
Still returns 30 day historical volatility, under the assumption that there are 365 trading days in a year. However, since 6h granularity fits 4 times in 24 hours, it rescales the look back period to rather 30*4 = 120 units to still reflect 30 day historical volatility.
RSI & MACDJust combined the template RSI and MACD scripts from the pine library and it seems to work better in pine version 4 :) ty tradingview!
Self-Adjusting RSI +Here is an open source (no request needed!) version of the Self-Adjusting RSI by David Sepiashvili.
Published in Stocks & Commodities V. 24:2 (February, 2006): The Self-Adjusting RSI
David Sepiashvili's article, "The Self-Adjusting RSI," presents a technique to adjust the traditional RSI overbought and oversold thresholds so as to ensure that 70-80% of RSI values lie between the two thresholds. Sepiashvili presents two algorithms for adjusting the thresholds. One is based on standard deviation, the other on a simple moving average of the RSI.
This script allows you to choose between plotting the Self-Adjusting bands or the traditional bands. You can also plot a smoothed RSI (SMA or EMA) and change the theme color for dark or light charts.
If you find this code useful, please pass it forward by sharing open source!
Thank you to all of the open source heroes out there!
"If I have seen a little further it is by standing on the shoulders of Giants."
Deviation Magnet - JDThis indicator shows price in relation to the standard deviations in a normalised way.
It can be seen as a kind of Bollinger Bands, where the bands stay the same size apart and price amplitude is modified between them,
or as a 'normalised' version of my BBC indicator.
Contrary to the popular use where price is seen as BOUNCING AGAINST the different deviations (or upper and lower BBands),
I tend to find that price likes to STICK to those deviations once it hits them (with a high or a low wick) and "rides them" for a while.
I call this "THE MAGNET EFFECT" of the standard deviations.
The indicator highlights those "MAGNET MOVES".
For most assets I like to use 50 period deviations better than the standard 20 period because it shows the bigger trends better
but of course this can be modified to your liking!
JD.
#NotTradingAdvice
#DYOR
I build these indicators for myself and provide them open source, to use for free to use and improve upon,
as I believe the best way to learn is toghether.
ATR Z ScoreThis script normalizes ATR to a Z Score, or a number of standard deviations it is from its long term average, positive or negative.
Gann Square Of 9 LevelsThis script uses the last hlc3 value of 1H, 4H, D and/or W and rotates it 360º up/down with four increments of 90º to find out potential support and resistance areas. Can be used as a dynamic support & resistance tool or just to gauge how overbought/oversold the market is. Special thanks to @Nv56 for his assistance in writing this script.
Bollinger Bands MTF [LonesomeTheBlue]With this script you can follow Bollinger Bands for current and higher time frame together. Higher time frame is calculated by script.
if current period
1m => higher period=5m
3m => higher period=5m
5m => higher period=15m
15m => higher period=1h
30m => higher period=1h
45m => higher period=1h
1h => higher period=4h
2h => higher period=4h
3h => higher period=4h
4h => higher period=1day
1day => higher period=1week
Linear Regression Channel [jwammo12]This is a non-repaint version of the built-in linear regression indicator in pine. It creates moving bands where the current bar matches the built-in Linear Regression indicator exactly (see screenshot). The key to replicating the built-in function is calculating the std deviation across the length of bars away from the current Linear Regression line, as opposed to the linear regression line that would have been calculated at the historic bar.
[RESEARCH] Mean Absolute DeviationHello traders and developers!
I was wondering how built-in "dev" function in Pine is calculated so I made a little research.
I examined 7 samples:
0) "dev" function itself
1) "dev" according to its description: series - sma(series)
2) Mean Absolute Deviation
3) ratio of the absolute difference from 1) divided by period
4) ratio of the difference from 1) divided by period
5) Median Absolute Deviation
6) tricky for-loop to calculate Mean Absolute Deviation
The results of the null and sixth samples are identical.
So, TV built-in "dev" function represents Mean Absolute Deviation and it's description is incorrect.
Where it is used? For example: Commodity Channel Index. You can check its original formula and if you used simple standard deviation instead of MAD in your CCIs - well guys, you were wrong.
Good luck!
Objective Analysis of Spread (VSA)Note: Pardon for a busy chart. It really is irrelevant for this indicator. Just look at the bottom part of the chart for the indicator (SpAn).
This script is meant to add objectivity to the estimation of spread in VSA. This is best used with a similar volume indicator that measures volume in the same fashion, but a simple rule of "higher/lower than the previous 2 bars" for estimation of volume size can be used as well in conjunction with this indicator.
A 30-period (adjustable) SMA difference between the high and the close is used to estimate average spread. This value is used to plot bands of 0.8 and lower (blue) standard deviation for narrow spread, 0.8-1.3 (yellow) for medium spread, 1,3-1.8 (green) for wide spread, 1.8-3 (red) for ultra-wide spread. Anything above 3 (no color) is plain crazy. =)
How to use:
A histogram of each bar spread is plotted as well. See where each histogram bar ends. For example, if it ends in the green area, this bar has a wide spread.
Added indicator:
An ATR (14-period, adjustable) is plotted as a black line for your reference. May be used for stops. Otherwise, it is not necessary for VSA.
Feedback and suggestions for improvement are welcome.
VWAP Stdev BandsCurrent price always obeys VWAP and is very useful for intraday traders. The Price will never go beyond the second deviation of VWAP at any point of time. The deviation bands are also very useful in predicting the volatility of the script.
Breakout trades can be taken based on the previous day's VWAP and it's deviations.
One can say that the stock has experienced breakout if current price crosses the fourth deviation of the previous day's VWAP or price bounces off that level, the price movement will be rapid if this occurs providing a good trading opportunity with low risk-reward ratio.
WimbleA standard deviation toolbox. Highly configurable.
Inspired by Bollinger Bands, Wimble creates two bands (from standard deviation) for visually clarity of price movement.
See the comments at the beginning of the script for a complete description.
Historical Volatility RankSame formulation of IVR but based on Historical Volatility instead.
Serves the same purpose as IV rank.
Sapphire [use not suggested]Sapphire looks for standar deviation trade signals and does not filter the results in anyway. You will often be told by the indicator to buy & hold at a loss or to exit positions prematurely and miss out on noteworthy gains (in excess of 15% at times!).
This script was published as an educational example and not suggested for use in trading .
Standard Deviation For RecoveryStandard Deviation For Recovery, If you are using martin gale strategy, you can use this, just use the first GREEN line on the indicator, please note once GREEN, does not mean it's always safe to continue...
It's just a tool
SapphireTrade indicator based on standard deviation models. To avoid the numerous false trades this can trigger on normal charts, suggested use is with renko charts.
Ehlers Fisherized Deviation-Scaled OscillatorEhlers Fisherized Deviation-Scaled Oscillator script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 36:11: Probability - Probably A Good Thing To Know).
Ehlers Deviation-Scaled Moving Average (DSMA)Ehlers Deviation-Scaled Moving Average indicator script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 36:8: The Deviation-Scaled Moving Average).
Triple Standard Deviation==日本語説明も併記 // Japanese discription is following ==
■ Momentum Indicator (Triple Indication of Standard Deviation Volatilities)
■ Effective assets: All
■Example of utilization
1) Assume that a trend is generated at the timing when the yellow area chart (26) rises
2) Confirm the candlestick and if the price jumps out of the Bollinger band ± 1 σ, the trend toward that direction
3) If the closing price is confirmed within ± 1σ of the Bollinger band, close the position
■ Detailed explanation
Three standard deviation volatilities with different parameters are displayed at the same time. As represented by convergence divergence of Bollinger, it has a characteristic that it rises in the trend generation period and falls during the trend convergence period.
It develops color in a rising phase so that trend generation is easy to recognize, and fades in a falling phase.
Daily use is basic, but you can use it with the same parameters for other time feet.
The basic parameter (26) is displayed in yellow area for the most visibility.
The long-term parameter (52) is indicated by a yellow dot as an auxiliary element for judging the rising margin of the basic line.
The short-term parameter (13) is displayed as a line as an auxiliary element for recognizing the peak out of the basic line in advance.
In some cases, by changing short term (13) to super long term (100) you can recognize the major market price level once in several years.
Three periods The phrase "all lines" goes from "low position" to "rising together" is considered the strongest trend.
On the other hand, in the case where the short-term line rises backwards as the longer-term line goes down, it tends to end up with short-lived trends and failure to form trends.
If the trend speed is constant as a standard feature of calculating the standard deviation, the standard deviation may decrease even during trend continuation. Therefore, it is desirable to make a comprehensive judgment by comparing the shape of candlestick with the longer-term line.
Please note that there is no way to judge whether the trend suggested by this index rises or falls from this index, so it is necessary to confirm the main chart. (It is preferable to display parabolic or Bollinger band)
■ Remarks
It is an index created assuming that it is used as Triple STD-ADX in combination with Triple Smoothed ADX(to be posted later).
■ About Triple STD-ADX
Triple Standard Deviation "and" Triple Smoothed ADX "are superimposed and displayed as" Screen (without scale) "to function as" Triple STD - ADX ".
The method of utilization is the same as Triple Standard Deviation and Triple Smoothed ADX, but by simultaneously displaying two momentum indicators with different calculation approaches with multiple parameters, we aim to mutually complement the cognitive power of trends.
STD (13, 26, 52, 100, 200) and ADX (7, 14, 26, 52, 100) correspond to reaction rates respectively.
By choosing different reaction rates you can expect to further increase reliability.
You can estimate the reliability of the trend most reliably in a situation where all six signals in total rise from low to high.
■Sample: STD-ADX Trade Signal
========================================================
■ モメンタム指標(標準偏差ボラティリティの3連表示)
■ 有効アセット:すべて
■ 活用の一例
1)黄色のエリアチャート(26)が上昇したタイミングでトレンド発生を想定
2)ローソク足を確認し、ボリンジャーバンド±1σの外に価格が飛び出している場合はその方向へのトレンドと認識
3)ボリンジャーバンド±1σ以内で終値が確定した場合にはポジションクローズ
■ 詳細説明
パラメーターの異なる3つの標準偏差ボラティリティを同時に表示します。ボリンジャーの収束発散に代表されるように、トレンド発生期に上昇しトレンド収束期に低下する特性を持ちます。
トレンド発生を認識しやすいように上昇局面で発色し、下降局面で退色します。
活用は日足が基本ですが、他の時間足に対しても同一パラメーターで使用することができます。
基本パラメーター(26)は最も視認しやすいように黄色のエリア表示にしています。
長期パラメーター(52)は基本線の上昇余力を判断するための補助要素として黄色の丸点で表示しています。
短期パラメーター(13)は基本線のピークアウトを先行して認識するための補助要素としてラインで表示にしています。
場合によって、短期(13)を超長期(100)に変更することで数年に一度のレベルの大相場が認識できます。
3期間「全てのライン」が「低い位置」から「揃って上昇」する局面を最も強いトレンドと考えます。
一方、より長期のラインが低下する中、より短期のラインが逆行して上昇するケースでは、短命のトレンドやトレンド形成失敗に終わることが多くなります。
標準偏差の計算上の特徴としてトレンドの速度が一定の場合にトレンド継続中も標準偏差が低下することがあります。そのため、ローソク足の形状とより長期のラインを見比べて総合的に判断することが望ましいです。
なお、本指標が示唆するトレンドが上昇か下降かは本指標からは判断する術はないため、必ずメインチャートを確認する必要があります。(パラボリックやボリンジャーバンドを表示すると好適)
■備考
追って掲載するTriple Smoothed ADXと併用して、Triple STD-ADXとして使用することを想定して作成した指標です。
■Triple STD-ADXについて
「Triple Standard Deviation」と「Triple Smoothed ADX」を一方を「スクリーン(スケールなし)」として重ねて表示させることで「Triple STD-ADX」として機能します。
活用方法はTriple Standard DeviationやTriple Smoothed ADXと同じですが、算出アプローチの異なる2つのモメンタム指標を複数パラメーターで同時に表示させることで、トレンドの認識力を相互に補完する狙いがあります。
反応速度はそれぞれSTD(13,26,52,100,200)とADX(7,14,26,52,100)がほぼ対応します。
異なる反応速度を選択することで信頼度をさらに高めることを期待できます。
合計6本のシグナル全てが低い位置から揃って上昇する局面でトレンドの信頼性を最も高く見積もることができます。
Louis Bachelier's Random WalkSeveral tests of market efficiency have been developed over the years. The very first test, constructed by Louis Bachelier in 1900, measured the probability of a number of consecutively positive or consecutively negative price changes, or “runs.”
The randomness of runs is rejected with 95 percent statistical confidence whenever the plotted value is greater than 0. The randomness of runs cannot be rejected if it's < 0.