TradingView
fikira
1 juil. 2021 13:38

Dynamic SMA 

Bitcoin all time history indexINDEX

Description

This script uses dynamic length to create a different sma type.

The length of the "Dynamic SMA" - "dSMA" can be:
'RSI', 'Stoch', 'ATR', 'MFI' or '%R'

For example 'RSI' -> the length of the sSMA will be the RSI itself

The biggest challenge was:
'Pine cannot determine the referencing length of a series. Try using max_bars_back' error

The writer of 'referencing length of a series' issue gave following solution:

bar_index == 0 ? 4999 : len
or in case of values which don't go above 100:
bar_index == 0 ? 100 : len

This assigns the necessary buffer to the function.
I'm most grateful for the given solution!

These dSMA's can give Support/Resistance levels, also crossovers of different dSMA's can give extra information

Examples:


RSI


ATR (close / atr(len)


Stoch


MFI


%R


"show regular SMA" will show the "SMA" with the same length (with default lighter color)

Notes de version

Updated to v5
Due to evolution in Pine Script™, an error occurred,
should be fixed now.

Notes de version

Update, bugfix (max len 5000 allowed)

Notes de version

Further Bugfix, sorry guys!
Commentaires
MAC_Trader
we have a error
MAC_Trader
@MAC_Trader, error on bar 1 : invalid value of the 'length' argument (NaN) in the "sma" function. it must be >0
MAC_Trader
@MAC_Trader, how can ı fix ?
anzhelikafen3005
It does not work
fikira
@anzhelikafen3005, More information please, it works here
fikira
@anzhelikafen3005, Remove the indicator and add back please
anzhelikafen3005
Mistake
fikira
@anzhelikafen3005, @MAC_Trader Error should be fixed now, cheers
MAC_Trader
@fikira, tnx bro
Plus