diff --git a/LICENSE b/LICENSE index ceb7f59..607d043 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 André Eduardo Pérez Álvarez - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2021 André Eduardo Pérez Álvarez + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Moving Averages Collection [andre_007].pine b/Moving Averages Collection [andre_007].pine index 093ad1d..1a5b8a5 100644 --- a/Moving Averages Collection [andre_007].pine +++ b/Moving Averages Collection [andre_007].pine @@ -1,356 +1,325 @@ -// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ -// @version=4 -// @author=andre_007 -// -// Last updated: 15-june-2021 - -study(title="Moving Averages Collection", shorttitle="Moving Averages Collection", format=format.inherit, overlay=true, resolution="") - -//----------------------------------------------------------- -// Type of Moving Averages -//----------------------------------------------------------- - -var string SMA = "Simple" -var string EMA = "Exponential" -var string DEMA = "Double Exponential" -var string TEMA = "Triple Exponential" -var string WMA = "Weighted" -var string SMMA = "Smoothed" -var string LSMA = "Least Squares" -var string HMA = "Hull" -var string ALMA = "Arnaud Legoux" - -//----------------------------------------------------------- -// Calculations -//----------------------------------------------------------- -var float calc_1 = na -var float calc_2 = na -var float calc_3 = na -var float calc_4 = na -var float calc_5 = na -var float calc_6 = na -var float calc_7 = na -var float calc_8 = na -var float calc_9 = na -var float calc_10 = na -var float calc_11 = na -var float calc_12 = na -var float calc_13 = na -var float calc_14 = na - -//----------------------------------------------------------- -// Periods of Moving Averages -//----------------------------------------------------------- -var len_1 = 8 -var len_2 = 13 -var len_3 = 21 -var len_4 = 34 -var len_5 = 50 -var len_6 = 80 -var len_7 = 120 -var len_8 = 160 -var len_9 = 200 -var len_10 = 240 -var len_11 = 280 -var len_12 = 320 -var len_13 = 365 -var len_14 = 730 - -//----------------------------------------------------------- -// Colors -//----------------------------------------------------------- -var color COLOR_BULL_01 = #3af13c -var color COLOR_BULL_02 = #00e85f -var color COLOR_BULL_03 = #00de7e -var color COLOR_BULL_04 = #00d39c -var color COLOR_BULL_05 = #00c7b6 -var color COLOR_BULL_06 = #00bace -var color COLOR_BULL_07 = #00ace2 -var color COLOR_BULL_08 = #009ef0 -var color COLOR_BULL_09 = #0090f7 -var color COLOR_BULL_10 = #0080f7 -var color COLOR_BULL_11 = #006ff0 -var color COLOR_BULL_12 = #005ce1 -var color COLOR_BULL_13 = #0048cc -var color COLOR_BULL_14 = #002fb1 - -var color COLOR_BEAR_01 = #ce0000 -var color COLOR_BEAR_02 = #d90019 -var color COLOR_BEAR_03 = #e4002b -var color COLOR_BEAR_04 = #ed003d -var color COLOR_BEAR_05 = #f6004e -var color COLOR_BEAR_06 = #fd005f -var color COLOR_BEAR_07 = #ff0071 -var color COLOR_BEAR_08 = #ff0084 -var color COLOR_BEAR_09 = #ff0496 -var color COLOR_BEAR_10 = #ff22a9 -var color COLOR_BEAR_11 = #ff35bc -var color COLOR_BEAR_12 = #ff45cf -var color COLOR_BEAR_13 = #ff54e2 -var color COLOR_BEAR_14 = #ff62f4 - -//----------------------------------------------------------- -// Params for all Moving Averages -//----------------------------------------------------------- -var string GROUP_ALL = "Params for all Moving Averages" -bool i_same_params = input(title="Same parameters for all moving averages?", type=input.bool, defval=true, tooltip="Check this to apply same type, source and offset for all moving averages", inline="02", group=GROUP_ALL) -string i_type_all = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="03", group=GROUP_ALL) -float i_src_all = input(close, title="Source", inline="03", group=GROUP_ALL) -int i_offset_all = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="03", group=GROUP_ALL) -bool i_fill = input(title="Fill background between averages?", type=input.bool, defval=true, inline="03", group=GROUP_ALL) - -//----------------------------------------------------------- -// Params for Arnaud Legoux Moving Average (ALMA) -//----------------------------------------------------------- -var string GROUP_ALMA = "Exclusive for Arnaud Legoux Moving Average (ALMA)" -alma_offset = input(title="Offset", type=input.float, defval=0.85, group=GROUP_ALMA, inline="04", tooltip="This offset is considered in the formula, not in the graphic! Offset is the Gaussian applied to the combo line and it is 0.85 by default. Setting offset at 1 makes it fully aligned to the current price just like the exponential moving average. While setting it to zero makes it just like a simple moving average. Traders may try offset combinations according to their own needs and preferences.") -alma_sigma = input(title="Sigma", type=input.float, defval=6, group=GROUP_ALMA, inline="04", tooltip="The standard deviation applied to the combo line. It makes the combo line sharper.") - -//----------------------------------------------------------- -// Averages -//----------------------------------------------------------- -var string GROUP_AVG = "Moving Averages" - -// ————— Average 1 -bool i_show_avg_1 = input(title="Moving Average 1", type=input.bool, defval=true, inline="10", group=GROUP_AVG) -color i_color_1 = input(COLOR_BULL_01, "", inline="10", group=GROUP_AVG) -string i_type_1 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="11", group=GROUP_AVG) -int i_length_1 = input(len_1, minval=1, title="Length", inline="11", group=GROUP_AVG) -float i_src_1 = input(close, title="Source", inline="12", group=GROUP_AVG) -int i_offset_1 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="12", group=GROUP_AVG) - -// ————— Average 2 -bool i_show_avg_2 = input(title="Moving Average 2", type=input.bool, defval=true, inline="13", group=GROUP_AVG) -color i_color_2 = input(COLOR_BULL_02, "", inline="13", group=GROUP_AVG) -string i_type_2 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="14", group=GROUP_AVG) -int i_length_2 = input(len_2, minval=1, title="Length", inline="14", group=GROUP_AVG) -float i_src_2 = input(close, title="Source", inline="15", group=GROUP_AVG) -int i_offset_2 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="15", group=GROUP_AVG) - -// ————— Average 3 -bool i_show_avg_3 = input(title="Moving Average 3", type=input.bool, defval=true, inline="16", group=GROUP_AVG) -color i_color_3 = input(COLOR_BULL_03, "", inline="16", group=GROUP_AVG) -string i_type_3 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="17", group=GROUP_AVG) -int i_length_3 = input(len_3, minval=1, title="Length", inline="17", group=GROUP_AVG) -float i_src_3 = input(close, title="Source", inline="18", group=GROUP_AVG) -int i_offset_3 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="18", group=GROUP_AVG) - -// ————— Average 4 -bool i_show_avg_4 = input(title="Moving Average 4", type=input.bool, defval=true, inline="19", group=GROUP_AVG) -color i_color_4 = input(COLOR_BULL_04, "", inline="19", group=GROUP_AVG) -string i_type_4 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="20", group=GROUP_AVG) -int i_length_4 = input(len_4, minval=1, title="Length", inline="20", group=GROUP_AVG) -float i_src_4 = input(close, title="Source", inline="21", group=GROUP_AVG) -int i_offset_4 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="21", group=GROUP_AVG) - -// ————— Average 5 -bool i_show_avg_5 = input(title="Moving Average 5", type=input.bool, defval=true, inline="22", group=GROUP_AVG) -color i_color_5 = input(COLOR_BULL_05, "", inline="22", group=GROUP_AVG) -string i_type_5 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="23", group=GROUP_AVG) -int i_length_5 = input(len_5, minval=1, title="Length", inline="23", group=GROUP_AVG) -float i_src_5 = input(close, title="Source", inline="24", group=GROUP_AVG) -int i_offset_5 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="24", group=GROUP_AVG) - -// ————— Average 6 -bool i_show_avg_6 = input(title="Moving Average 6", type=input.bool, defval=true, inline="25", group=GROUP_AVG) -color i_color_6 = input(COLOR_BULL_06, "", inline="25", group=GROUP_AVG) -string i_type_6 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="26", group=GROUP_AVG) -int i_length_6 = input(len_6, minval=1, title="Length", inline="26", group=GROUP_AVG) -float i_src_6 = input(close, title="Source", inline="27", group=GROUP_AVG) -int i_offset_6 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="27", group=GROUP_AVG) - -// ————— Average 7 -bool i_show_avg_7 = input(title="Moving Average 7", type=input.bool, defval=true, inline="28", group=GROUP_AVG) -color i_color_7 = input(COLOR_BULL_07, "", inline="28", group=GROUP_AVG) -string i_type_7 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="29", group=GROUP_AVG) -int i_length_7 = input(len_7, minval=1, title="Length", inline="29", group=GROUP_AVG) -float i_src_7 = input(close, title="Source", inline="30", group=GROUP_AVG) -int i_offset_7 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="30", group=GROUP_AVG) - -// ————— Average 8 -bool i_show_avg_8 = input(title="Moving Average 8", type=input.bool, defval=true, inline="31", group=GROUP_AVG) -color i_color_8 = input(COLOR_BULL_08, "", inline="31", group=GROUP_AVG) -string i_type_8 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="32", group=GROUP_AVG) -int i_length_8 = input(len_8, minval=1, title="Length", inline="32", group=GROUP_AVG) -float i_src_8 = input(close, title="Source", inline="33", group=GROUP_AVG) -int i_offset_8 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="33", group=GROUP_AVG) - -// ————— Average 9 -bool i_show_avg_9 = input(title="Moving Average 9", type=input.bool, defval=true, inline="34", group=GROUP_AVG) -color i_color_9 = input(COLOR_BULL_09, "", inline="34", group=GROUP_AVG) -string i_type_9 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="35", group=GROUP_AVG) -int i_length_9 = input(len_9, minval=1, title="Length", inline="35", group=GROUP_AVG) -float i_src_9 = input(close, title="Source", inline="36", group=GROUP_AVG) -int i_offset_9 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="36", group=GROUP_AVG) - -// ————— Average 10 -bool i_show_avg_10 = input(title="Moving Average 10", type=input.bool, defval=true, inline="37", group=GROUP_AVG) -color i_color_10 = input(COLOR_BULL_10, "", inline="37", group=GROUP_AVG) -string i_type_10 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="38", group=GROUP_AVG) -int i_length_10 = input(len_10, minval=1, title="Length", inline="38", group=GROUP_AVG) -float i_src_10 = input(close, title="Source", inline="39", group=GROUP_AVG) -int i_offset_10 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="39", group=GROUP_AVG) - -// ————— Average 11 -bool i_show_avg_11 = input(title="Moving Average 11", type=input.bool, defval=true, inline="40", group=GROUP_AVG) -color i_color_11 = input(COLOR_BULL_11, "", inline="40", group=GROUP_AVG) -string i_type_11 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="41", group=GROUP_AVG) -int i_length_11 = input(len_11, minval=1, title="Length", inline="41", group=GROUP_AVG) -float i_src_11 = input(close, title="Source", inline="42", group=GROUP_AVG) -int i_offset_11 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="42", group=GROUP_AVG) - -// ————— Average 12 -bool i_show_avg_12 = input(title="Moving Average 12", type=input.bool, defval=true, inline="43", group=GROUP_AVG) -color i_color_12 = input(COLOR_BULL_12, "", inline="43", group=GROUP_AVG) -string i_type_12 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="44", group=GROUP_AVG) -int i_length_12 = input(len_12, minval=1, title="Length", inline="44", group=GROUP_AVG) -float i_src_12 = input(close, title="Source", inline="45", group=GROUP_AVG) -int i_offset_12 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="45", group=GROUP_AVG) - -// ————— Average 13 -bool i_show_avg_13 = input(title="Moving Average 13", type=input.bool, defval=true, inline="46", group=GROUP_AVG) -color i_color_13 = input(COLOR_BULL_13, "", inline="46", group=GROUP_AVG) -string i_type_13 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="47", group=GROUP_AVG) -int i_length_13 = input(len_13, minval=1, title="Length", inline="47", group=GROUP_AVG) -float i_src_13 = input(close, title="Source", inline="48", group=GROUP_AVG) -int i_offset_13 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="48", group=GROUP_AVG) - -// ————— Average 14 -bool i_show_avg_14 = input(title="Moving Average 14", type=input.bool, defval=true, inline="49", group=GROUP_AVG) -color i_color_14 = input(COLOR_BULL_14, "", inline="49", group=GROUP_AVG) -string i_type_14 = input(SMA, "Type", options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline="50", group=GROUP_AVG) -int i_length_14 = input(len_14, minval=1, title="Length", inline="50", group=GROUP_AVG) -float i_src_14 = input(close, title="Source", inline="51", group=GROUP_AVG) -int i_offset_14 = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, inline="51", group=GROUP_AVG) - -//----------------------------------------------------------- -// Functions -//----------------------------------------------------------- -f_sma(_src, _len) => - out = sma(_src, _len) - -f_ema(_src, _len) => - out = ema(_src, _len) - -f_dema(_src, _len) => - e1 = ema(_src, _len) - e2 = ema(e1, _len) - out = 2 * e1 - e2 - -f_tema(_src, _len) => - ema1 = ema(_src, _len) - ema2 = ema(ema1, _len) - ema3 = ema(ema2, _len) - out = 3 * (ema1 - ema2) + ema3 - -f_wma(_src, _len) => - out = wma(_src, _len) - -f_smma(_src, _len) => - smma = 0.0 - smma := na(smma[1]) ? sma(_src, _len) : (smma[1] * (_len - 1) + _src) / _len - -f_lsma(_src, _len) => - out = linreg(_src, _len, 0) - -f_hullma(_src, _len) => - out = wma(2*wma(_src, _len/2)-wma(_src, _len), floor(sqrt(_len))) - -f_alma(_src, _len) => - out = alma(_src, _len, alma_offset, alma_sigma) - -f_average(_type, _src, _len) => - if _type == SMA - f_sma(_src, _len) - else if _type == EMA - f_ema(_src, _len) - else if _type == DEMA - f_dema(_src, _len) - else if _type == TEMA - f_tema(_src, _len) - else if _type == WMA - f_wma(_src, _len) - else if _type == SMMA - f_smma(_src, _len) - else if _type == LSMA - f_lsma(_src, _len) - else if _type == HMA - f_hullma(_src, _len) - else if _type == ALMA - f_alma(_src, _len) - -f_apply_type(_type) => - type_out = i_same_params ? i_type_all : _type - -f_apply_src(_src) => - src_out = i_same_params ? i_src_all : _src - -f_apply_offset(_offset) => - offset_out = i_same_params ? i_offset_all : _offset - -//----------------------------------------------------------- -// Calculations -//----------------------------------------------------------- -if i_show_avg_1 - calc_1 := f_average( f_apply_type(i_type_1), f_apply_src(i_src_1), i_length_1 ) -if i_show_avg_2 - calc_2 := f_average( f_apply_type(i_type_2), f_apply_src(i_src_2), i_length_2 ) -if i_show_avg_3 - calc_3 := f_average( f_apply_type(i_type_3), f_apply_src(i_src_3), i_length_3 ) -if i_show_avg_4 - calc_4 := f_average( f_apply_type(i_type_4), f_apply_src(i_src_4), i_length_4 ) -if i_show_avg_5 - calc_5 := f_average( f_apply_type(i_type_5), f_apply_src(i_src_5), i_length_5 ) -if i_show_avg_6 - calc_6 := f_average( f_apply_type(i_type_6), f_apply_src(i_src_6), i_length_6 ) -if i_show_avg_7 - calc_7 := f_average( f_apply_type(i_type_7), f_apply_src(i_src_7), i_length_7 ) -if i_show_avg_8 - calc_8 := f_average( f_apply_type(i_type_8), f_apply_src(i_src_8), i_length_8 ) -if i_show_avg_9 - calc_9 := f_average( f_apply_type(i_type_9), f_apply_src(i_src_9), i_length_9 ) -if i_show_avg_10 - calc_10 := f_average( f_apply_type(i_type_10), f_apply_src(i_src_10), i_length_10 ) -if i_show_avg_11 - calc_11 := f_average( f_apply_type(i_type_11), f_apply_src(i_src_11), i_length_11 ) -if i_show_avg_12 - calc_12 := f_average( f_apply_type(i_type_12), f_apply_src(i_src_12), i_length_12 ) -if i_show_avg_13 - calc_13 := f_average( f_apply_type(i_type_13), f_apply_src(i_src_13), i_length_13 ) -if i_show_avg_14 - calc_14 := f_average( f_apply_type(i_type_14), f_apply_src(i_src_14), i_length_14 ) - -//----------------------------------------------------------- -// Plots -//----------------------------------------------------------- -plot_1 = plot( calc_1, color=close>=calc_1 ? i_color_1 : COLOR_BEAR_01, offset=f_apply_offset(i_offset_1), linewidth=1 ) -plot_2 = plot( calc_2, color=close>=calc_2 ? i_color_2 : COLOR_BEAR_02, offset=f_apply_offset(i_offset_2), linewidth=1 ) -plot_3 = plot( calc_3, color=close>=calc_3 ? i_color_3 : COLOR_BEAR_03, offset=f_apply_offset(i_offset_3), linewidth=1 ) -plot_4 = plot( calc_4, color=close>=calc_4 ? i_color_4 : COLOR_BEAR_04, offset=f_apply_offset(i_offset_4), linewidth=1 ) -plot_5 = plot( calc_5, color=close>=calc_5 ? i_color_5 : COLOR_BEAR_05, offset=f_apply_offset(i_offset_5), linewidth=1 ) -plot_6 = plot( calc_6, color=close>=calc_6 ? i_color_6 : COLOR_BEAR_06, offset=f_apply_offset(i_offset_6), linewidth=1 ) -plot_7 = plot( calc_7, color=close>=calc_7 ? i_color_7 : COLOR_BEAR_07, offset=f_apply_offset(i_offset_7), linewidth=1 ) -plot_8 = plot( calc_8, color=close>=calc_8 ? i_color_8 : COLOR_BEAR_08, offset=f_apply_offset(i_offset_8), linewidth=1 ) -plot_9 = plot( calc_9, color=close>=calc_9 ? i_color_9 : COLOR_BEAR_09, offset=f_apply_offset(i_offset_9), linewidth=1 ) -plot_10 = plot( calc_10, color=close>=calc_10 ? i_color_10 : COLOR_BEAR_10, offset=f_apply_offset(i_offset_10), linewidth=1 ) -plot_11 = plot( calc_11, color=close>=calc_11 ? i_color_11 : COLOR_BEAR_11, offset=f_apply_offset(i_offset_11), linewidth=1 ) -plot_12 = plot( calc_12, color=close>=calc_12 ? i_color_12 : COLOR_BEAR_12, offset=f_apply_offset(i_offset_12), linewidth=1 ) -plot_13 = plot( calc_13, color=close>=calc_13 ? i_color_13 : COLOR_BEAR_13, offset=f_apply_offset(i_offset_13), linewidth=1 ) -plot_14 = plot( calc_14, color=close>=calc_14 ? i_color_14 : COLOR_BEAR_14, offset=f_apply_offset(i_offset_14), linewidth=1 ) - -//----------------------------------------------------------- -// Fills -//----------------------------------------------------------- -fill(plot_1, plot_2, color=i_fill ? (color.new(calc_1 > calc_2 ? i_color_1 : COLOR_BEAR_02, 90)) : na ) -fill(plot_2, plot_3, color=i_fill ? (color.new(calc_2 > calc_3 ? i_color_2 : COLOR_BEAR_03, 90)) : na ) -fill(plot_3, plot_4, color=i_fill ? (color.new(calc_3 > calc_4 ? i_color_3 : COLOR_BEAR_04, 90)) : na ) -fill(plot_4, plot_5, color=i_fill ? (color.new(calc_4 > calc_5 ? i_color_4 : COLOR_BEAR_05, 90)) : na ) -fill(plot_5, plot_6, color=i_fill ? (color.new(calc_5 > calc_6 ? i_color_5 : COLOR_BEAR_06, 90)) : na ) -fill(plot_6, plot_7, color=i_fill ? (color.new(calc_6 > calc_7 ? i_color_6 : COLOR_BEAR_07, 90)) : na ) -fill(plot_7, plot_8, color=i_fill ? (color.new(calc_7 > calc_8 ? i_color_7 : COLOR_BEAR_08, 90)) : na ) -fill(plot_8, plot_9, color=i_fill ? (color.new(calc_8 > calc_9 ? i_color_8 : COLOR_BEAR_09, 90)) : na ) -fill(plot_9, plot_10, color=i_fill ? (color.new(calc_9 > calc_10 ? i_color_9 : COLOR_BEAR_10, 90)) : na ) -fill(plot_10, plot_11, color=i_fill ? (color.new(calc_10 > calc_11 ? i_color_10 : COLOR_BEAR_11, 90)) : na ) -fill(plot_11, plot_12, color=i_fill ? (color.new(calc_11 > calc_12 ? i_color_11 : COLOR_BEAR_12, 90)) : na ) -fill(plot_12, plot_13, color=i_fill ? (color.new(calc_12 > calc_13 ? i_color_12 : COLOR_BEAR_13, 90)) : na ) -fill(plot_13, plot_14, color=i_fill ? (color.new(calc_13 > calc_14 ? i_color_13 : COLOR_BEAR_14, 90)) : na ) \ No newline at end of file +//@version=5 +// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ +// @author=andre_007 +// +// Last updated: 08-september-2021 + +indicator(title='Moving Averages Collection', shorttitle='Moving Averages Collection', format=format.inherit, overlay=true, timeframe='') + +//----------------------------------------------------------- +// Type of Moving Averages +//----------------------------------------------------------- + +var string SMA = 'Simple' +var string EMA = 'Exponential' +var string DEMA = 'Double Exponential' +var string TEMA = 'Triple Exponential' +var string WMA = 'Weighted' +var string SMMA = 'Smoothed' +var string LSMA = 'Least Squares' +var string HMA = 'Hull' +var string ALMA = 'Arnaud Legoux' + +//----------------------------------------------------------- +// Calculations +//----------------------------------------------------------- +var float calc_1 = na +var float calc_2 = na +var float calc_3 = na +var float calc_4 = na +var float calc_5 = na +var float calc_6 = na +var float calc_7 = na +var float calc_8 = na +var float calc_9 = na +var float calc_10 = na + +//----------------------------------------------------------- +// Periods of Moving Averages +//----------------------------------------------------------- +var len_1 = 8 +var len_2 = 13 +var len_3 = 21 +var len_4 = 34 +var len_5 = 55 +var len_6 = 89 +var len_7 = 144 +var len_8 = 233 +var len_9 = 377 +var len_10 = 610 + +//----------------------------------------------------------- +// Colors +//----------------------------------------------------------- +var color COLOR_BULL_01 = #3af13c +var color COLOR_BULL_02 = #00e85f +var color COLOR_BULL_03 = #00de7e +var color COLOR_BULL_04 = #00d39c +var color COLOR_BULL_05 = #00c7b6 +var color COLOR_BULL_06 = #00bace +var color COLOR_BULL_07 = #00ace2 +var color COLOR_BULL_08 = #009ef0 +var color COLOR_BULL_09 = #0090f7 +var color COLOR_BULL_10 = #0080f7 + +var color COLOR_BEAR_01 = #ce0000 +var color COLOR_BEAR_02 = #d90019 +var color COLOR_BEAR_03 = #e4002b +var color COLOR_BEAR_04 = #ed003d +var color COLOR_BEAR_05 = #f6004e +var color COLOR_BEAR_06 = #fd005f +var color COLOR_BEAR_07 = #ff0071 +var color COLOR_BEAR_08 = #ff0084 +var color COLOR_BEAR_09 = #ff0496 +var color COLOR_BEAR_10 = #ff22a9 + +//----------------------------------------------------------- +// Params for all Moving Averages +//----------------------------------------------------------- +var string GROUP_ALL = 'Params for all Moving Averages' +bool i_same_params = input.bool(title='Same parameters for all moving averages?', defval=true, tooltip='Check this to apply same type, source and offset for all moving averages', inline='02', group=GROUP_ALL) +string i_type_all = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='03', group=GROUP_ALL) +float i_src_all = input.source(close, title='Source', inline='03', group=GROUP_ALL) +int i_offset_all = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='03', group=GROUP_ALL) +bool i_fill = input.bool(title='Fill background between averages?', defval=true, inline='03', group=GROUP_ALL) + +//----------------------------------------------------------- +// Params for Arnaud Legoux Moving Average (ALMA) +//----------------------------------------------------------- +var string GROUP_ALMA = 'Exclusive for Arnaud Legoux Moving Average (ALMA)' +alma_offset = input.float(title='Offset', defval=0.85, group=GROUP_ALMA, inline='04', tooltip='This offset is considered in the formula, not in the graphic! Offset is the Gaussian applied to the combo line and it is 0.85 by default. Setting offset at 1 makes it fully aligned to the current price just like the exponential moving average. While setting it to zero makes it just like a simple moving average. Traders may try offset combinations according to their own needs and preferences.') +alma_sigma = input.float(title='Sigma', defval=6, group=GROUP_ALMA, inline='04', tooltip='The standard deviation applied to the combo line. It makes the combo line sharper.') + +//----------------------------------------------------------- +// Averages +//----------------------------------------------------------- +var string GROUP_AVG = 'Moving Averages' + +// ————— Average 1 +bool i_show_avg_1 = input.bool(title='Moving Average 1', defval=true, inline='10', group=GROUP_AVG) +color i_color_bull_1 = input.color(COLOR_BULL_01, '', inline='10', group=GROUP_AVG) +color i_color_bear_1 = input.color(COLOR_BEAR_01, '', inline='10', group=GROUP_AVG) +string i_type_1 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='11', group=GROUP_AVG) +int i_length_1 = input.int(len_1, minval=1, title='Length', inline='11', group=GROUP_AVG) +float i_src_1 = input.source(close, title='Source', inline='12', group=GROUP_AVG) +int i_offset_1 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='12', group=GROUP_AVG) + +// ————— Average 2 +bool i_show_avg_2 = input.bool(title='Moving Average 2', defval=true, inline='13', group=GROUP_AVG) +color i_color_bull_2 = input.color(COLOR_BULL_02, '', inline='13', group=GROUP_AVG) +color i_color_bear_2 = input.color(COLOR_BEAR_02, '', inline='13', group=GROUP_AVG) +string i_type_2 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='14', group=GROUP_AVG) +int i_length_2 = input.int(len_2, minval=1, title='Length', inline='14', group=GROUP_AVG) +float i_src_2 = input.source(close, title='Source', inline='15', group=GROUP_AVG) +int i_offset_2 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='15', group=GROUP_AVG) + +// ————— Average 3 +bool i_show_avg_3 = input.bool(title='Moving Average 3', defval=true, inline='16', group=GROUP_AVG) +color i_color_bull_3 = input.color(COLOR_BULL_03, '', inline='16', group=GROUP_AVG) +color i_color_bear_3 = input.color(COLOR_BEAR_03, '', inline='16', group=GROUP_AVG) +string i_type_3 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='17', group=GROUP_AVG) +int i_length_3 = input.int(len_3, minval=1, title='Length', inline='17', group=GROUP_AVG) +float i_src_3 = input.source(close, title='Source', inline='18', group=GROUP_AVG) +int i_offset_3 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='18', group=GROUP_AVG) + +// ————— Average 4 +bool i_show_avg_4 = input.bool(title='Moving Average 4', defval=true, inline='19', group=GROUP_AVG) +color i_color_bull_4 = input.color(COLOR_BULL_04, '', inline='19', group=GROUP_AVG) +color i_color_bear_4 = input.color(COLOR_BEAR_04, '', inline='19', group=GROUP_AVG) +string i_type_4 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='20', group=GROUP_AVG) +int i_length_4 = input.int(len_4, minval=1, title='Length', inline='20', group=GROUP_AVG) +float i_src_4 = input.source(close, title='Source', inline='21', group=GROUP_AVG) +int i_offset_4 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='21', group=GROUP_AVG) + +// ————— Average 5 +bool i_show_avg_5 = input.bool(title='Moving Average 5', defval=true, inline='22', group=GROUP_AVG) +color i_color_bull_5 = input.color(COLOR_BULL_05, '', inline='22', group=GROUP_AVG) +color i_color_bear_5 = input.color(COLOR_BEAR_05, '', inline='22', group=GROUP_AVG) +string i_type_5 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='23', group=GROUP_AVG) +int i_length_5 = input.int(len_5, minval=1, title='Length', inline='23', group=GROUP_AVG) +float i_src_5 = input.source(close, title='Source', inline='24', group=GROUP_AVG) +int i_offset_5 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='24', group=GROUP_AVG) + +// ————— Average 6 +bool i_show_avg_6 = input.bool(title='Moving Average 6', defval=true, inline='25', group=GROUP_AVG) +color i_color_bull_6 = input.color(COLOR_BULL_06, '', inline='25', group=GROUP_AVG) +color i_color_bear_6 = input.color(COLOR_BEAR_06, '', inline='25', group=GROUP_AVG) +string i_type_6 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='26', group=GROUP_AVG) +int i_length_6 = input.int(len_6, minval=1, title='Length', inline='26', group=GROUP_AVG) +float i_src_6 = input.source(close, title='Source', inline='27', group=GROUP_AVG) +int i_offset_6 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='27', group=GROUP_AVG) + +// ————— Average 7 +bool i_show_avg_7 = input.bool(title='Moving Average 7', defval=true, inline='28', group=GROUP_AVG) +color i_color_bull_7 = input.color(COLOR_BULL_07, '', inline='28', group=GROUP_AVG) +color i_color_bear_7 = input.color(COLOR_BEAR_07, '', inline='28', group=GROUP_AVG) +string i_type_7 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='29', group=GROUP_AVG) +int i_length_7 = input.int(len_7, minval=1, title='Length', inline='29', group=GROUP_AVG) +float i_src_7 = input.source(close, title='Source', inline='30', group=GROUP_AVG) +int i_offset_7 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='30', group=GROUP_AVG) + +// ————— Average 8 +bool i_show_avg_8 = input.bool(title='Moving Average 8', defval=true, inline='31', group=GROUP_AVG) +color i_color_bull_8 = input.color(COLOR_BULL_08, '', inline='31', group=GROUP_AVG) +color i_color_bear_8 = input.color(COLOR_BEAR_08, '', inline='31', group=GROUP_AVG) +string i_type_8 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='32', group=GROUP_AVG) +int i_length_8 = input.int(len_8, minval=1, title='Length', inline='32', group=GROUP_AVG) +float i_src_8 = input.source(close, title='Source', inline='33', group=GROUP_AVG) +int i_offset_8 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='33', group=GROUP_AVG) + +// ————— Average 9 +bool i_show_avg_9 = input.bool(title='Moving Average 9', defval=true, inline='34', group=GROUP_AVG) +color i_color_bull_9 = input.color(COLOR_BULL_09, '', inline='34', group=GROUP_AVG) +color i_color_bear_9 = input.color(COLOR_BEAR_09, '', inline='34', group=GROUP_AVG) +string i_type_9 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='35', group=GROUP_AVG) +int i_length_9 = input.int(len_9, minval=1, title='Length', inline='35', group=GROUP_AVG) +float i_src_9 = input.source(close, title='Source', inline='36', group=GROUP_AVG) +int i_offset_9 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='36', group=GROUP_AVG) + +// ————— Average 10 +bool i_show_avg_10 = input.bool(title='Moving Average 10', defval=true, inline='37', group=GROUP_AVG) +color i_color_bull_10 = input.color(COLOR_BULL_10, '', inline='37', group=GROUP_AVG) +color i_color_bear_10 = input.color(COLOR_BEAR_10, '', inline='37', group=GROUP_AVG) +string i_type_10 = input.string(SMA, 'Type', options=[SMA, EMA, DEMA, TEMA, WMA, SMMA, LSMA, HMA, ALMA], inline='38', group=GROUP_AVG) +int i_length_10 = input.int(len_10, minval=1, title='Length', inline='38', group=GROUP_AVG) +float i_src_10 = input.source(close, title='Source', inline='39', group=GROUP_AVG) +int i_offset_10 = input.int(title='Offset', defval=0, minval=-500, maxval=500, inline='39', group=GROUP_AVG) + +//----------------------------------------------------------- +// Functions +//----------------------------------------------------------- +f_sma(_src, _len) => + out = ta.sma(_src, _len) + out + +f_ema(_src, _len) => + out = ta.ema(_src, _len) + out + +f_dema(_src, _len) => + e1 = ta.ema(_src, _len) + e2 = ta.ema(e1, _len) + out = 2 * e1 - e2 + out + +f_tema(_src, _len) => + ema1 = ta.ema(_src, _len) + ema2 = ta.ema(ema1, _len) + ema3 = ta.ema(ema2, _len) + out = 3 * (ema1 - ema2) + ema3 + out + +f_wma(_src, _len) => + out = ta.wma(_src, _len) + out + +f_smma(_src, _len) => + smma = 0.0 + smma := na(smma[1]) ? ta.sma(_src, _len) : (smma[1] * (_len - 1) + _src) / _len + smma + +f_lsma(_src, _len) => + out = ta.linreg(_src, _len, 0) + out + +f_hullma(_src, _len) => + out = ta.wma(2 * ta.wma(_src, _len / 2) - ta.wma(_src, _len), math.floor(math.sqrt(_len))) + out + +f_alma(_src, _len) => + out = ta.alma(_src, _len, alma_offset, alma_sigma) + out + +f_average(_type, _src, _len) => + if _type == SMA + f_sma(_src, _len) + else if _type == EMA + f_ema(_src, _len) + else if _type == DEMA + f_dema(_src, _len) + else if _type == TEMA + f_tema(_src, _len) + else if _type == WMA + f_wma(_src, _len) + else if _type == SMMA + f_smma(_src, _len) + else if _type == LSMA + f_lsma(_src, _len) + else if _type == HMA + f_hullma(_src, _len) + else if _type == ALMA + f_alma(_src, _len) + +f_apply_type(_type) => + type_out = i_same_params ? i_type_all : _type + type_out + +f_apply_src(_src) => + src_out = i_same_params ? i_src_all : _src + src_out + +f_apply_offset(_offset) => + offset_out = i_same_params ? i_offset_all : _offset + offset_out + +//----------------------------------------------------------- +// Calculations +//----------------------------------------------------------- +if i_show_avg_1 + calc_1 := f_average(f_apply_type(i_type_1), f_apply_src(i_src_1), i_length_1) + calc_1 +if i_show_avg_2 + calc_2 := f_average(f_apply_type(i_type_2), f_apply_src(i_src_2), i_length_2) + calc_2 +if i_show_avg_3 + calc_3 := f_average(f_apply_type(i_type_3), f_apply_src(i_src_3), i_length_3) + calc_3 +if i_show_avg_4 + calc_4 := f_average(f_apply_type(i_type_4), f_apply_src(i_src_4), i_length_4) + calc_4 +if i_show_avg_5 + calc_5 := f_average(f_apply_type(i_type_5), f_apply_src(i_src_5), i_length_5) + calc_5 +if i_show_avg_6 + calc_6 := f_average(f_apply_type(i_type_6), f_apply_src(i_src_6), i_length_6) + calc_6 +if i_show_avg_7 + calc_7 := f_average(f_apply_type(i_type_7), f_apply_src(i_src_7), i_length_7) + calc_7 +if i_show_avg_8 + calc_8 := f_average(f_apply_type(i_type_8), f_apply_src(i_src_8), i_length_8) + calc_8 +if i_show_avg_9 + calc_9 := f_average(f_apply_type(i_type_9), f_apply_src(i_src_9), i_length_9) + calc_9 +if i_show_avg_10 + calc_10 := f_average(f_apply_type(i_type_10), f_apply_src(i_src_10), i_length_10) + calc_10 + +//----------------------------------------------------------- +// Plots +//----------------------------------------------------------- +plot_1 = plot(calc_1, color=close >= calc_1 ? i_color_bull_1 : i_color_bear_1, offset=f_apply_offset(i_offset_1), linewidth=1) +plot_2 = plot(calc_2, color=close >= calc_2 ? i_color_bull_2 : i_color_bear_2, offset=f_apply_offset(i_offset_2), linewidth=1) +plot_3 = plot(calc_3, color=close >= calc_3 ? i_color_bull_3 : i_color_bear_3, offset=f_apply_offset(i_offset_3), linewidth=1) +plot_4 = plot(calc_4, color=close >= calc_4 ? i_color_bull_4 : i_color_bear_4, offset=f_apply_offset(i_offset_4), linewidth=1) +plot_5 = plot(calc_5, color=close >= calc_5 ? i_color_bull_5 : i_color_bear_5, offset=f_apply_offset(i_offset_5), linewidth=1) +plot_6 = plot(calc_6, color=close >= calc_6 ? i_color_bull_6 : i_color_bear_6, offset=f_apply_offset(i_offset_6), linewidth=1) +plot_7 = plot(calc_7, color=close >= calc_7 ? i_color_bull_7 : i_color_bear_7, offset=f_apply_offset(i_offset_7), linewidth=1) +plot_8 = plot(calc_8, color=close >= calc_8 ? i_color_bull_8 : i_color_bear_8, offset=f_apply_offset(i_offset_8), linewidth=1) +plot_9 = plot(calc_9, color=close >= calc_9 ? i_color_bull_9 : i_color_bear_9, offset=f_apply_offset(i_offset_9), linewidth=1) +plot_10 = plot(calc_10, color=close >= calc_10 ? i_color_bull_10 : i_color_bear_10, offset=f_apply_offset(i_offset_10), linewidth=1) + +//----------------------------------------------------------- +// Fills +//----------------------------------------------------------- +fill(plot_1, plot_2, color=i_fill ? color.new(calc_1 > calc_2 ? i_color_bull_1 : i_color_bear_2, 90) : na, transp=90) +fill(plot_2, plot_3, color=i_fill ? color.new(calc_2 > calc_3 ? i_color_bull_2 : i_color_bear_3, 90) : na, transp=90) +fill(plot_3, plot_4, color=i_fill ? color.new(calc_3 > calc_4 ? i_color_bull_3 : i_color_bear_4, 90) : na, transp=90) +fill(plot_4, plot_5, color=i_fill ? color.new(calc_4 > calc_5 ? i_color_bull_4 : i_color_bear_5, 90) : na, transp=90) +fill(plot_5, plot_6, color=i_fill ? color.new(calc_5 > calc_6 ? i_color_bull_5 : i_color_bear_6, 90) : na, transp=90) +fill(plot_6, plot_7, color=i_fill ? color.new(calc_6 > calc_7 ? i_color_bull_6 : i_color_bear_7, 90) : na, transp=90) +fill(plot_7, plot_8, color=i_fill ? color.new(calc_7 > calc_8 ? i_color_bull_7 : i_color_bear_8, 90) : na, transp=90) +fill(plot_8, plot_9, color=i_fill ? color.new(calc_8 > calc_9 ? i_color_bull_8 : i_color_bear_9, 90) : na, transp=90) +fill(plot_9, plot_10, color=i_fill ? color.new(calc_9 > calc_10 ? i_color_bull_9 : i_color_bear_10, 90) : na, transp=90) + diff --git a/README.md b/README.md index 3a67686..4432d76 100644 --- a/README.md +++ b/README.md @@ -1,147 +1,147 @@ -# ![logo](images/Pine.png "Pine") - -## Moving Averages Collection - -## Summary 💊 - -This is a collection of moving averages indicators. -It's developed in PineScript for the technical analysis platform of **TradingView**. - -## Motivation 💊 - -To use the different types of moving averages (for example: simple, exponential, etc.), it is necessary to insert each indicator separately. - -This can be tedius, requiring the inclusion or removal of the indicators every time you want to make the change. - -Basically, what this script does, is to allow the dynamic use of these indicators. -That is, it is possible to choose the type of moving average as needed, facilitating the comparison and creation of setups. - -## Caution 💊 - -No technical indicators are 100% accurate as they can sometimes generate false signals. - -You should never rely on a single indicator and always use a range of them when making trading decisions. - ---- - -## How to use this tool 💊 - -Simply choose the type desired as the figure. -In all are fourteen moving averages. -There is also the possibility of choosing the indidual type of each. - -![alt](images/10-Params_1.png) - ---- - -## Definitions 💊 - -### 1. Moving Averages 📈 - -The moving average (MA) is a delayed (or reactive) price-based indicator that displays the average price of a title for a defined period of time. -A moving average is a good way to evaluate the moment, confirm trends and set support and resistance areas. -Essentially, the moving averages soften the "noise" when trying to interpret graphics. -Noise is composed of price and volume fluctuations. -As a moving average is a delay indicator and reacts to events that have already occurred, It is not used as a predictive indicator, but as an interpretive indicator, used for confirmations and analyzes. -In fact, moving averages are the basis of several other known technical analysis tools such as Bollinger bands and MACD. - -### 2. Simple Moving Average (SMA) 📈 - -The Simple Moving Average is an arithmetic moving average calculated by adding recent prices and then dividing then by the number of time periods in the calculation average. -This average is a non-weighted moving average, so this means that every day in the dataset they have equal importance and have the same weight. -Although old, it is a very efficient indicator to demonstrate supports and resistances and if the market is in a high, low or lateral tendency. - -![alt](images/01-Simple.png) - -### Exponential Moving Average (EMA) 📈 - -The Exponential Moving Average (EMA) is a specific type of moving average that points towards the importance of the most recent data and information from the market. -It’s exponential, weighting the most recent prices more than the less recent prices. - -Although using the Exponential Moving Average has a lot of advantages when analyzing market trends, -it is also uncertain whether or not the use of most recent data points truly affects technical and market analysis. -In addition, the EMA relies on historical data as its basis for operating and because news, events, -and other information can change rapidly the indicator can misinterpret this information by weighting the current prices higher than when the event actually occurred. - -![alt](images/02-Exponential.png) - -### Double Exponential Moving Average (DEMA) 📈 - -The Double Exponential Moving Average is a technical indicator that uses two moving averages to help confirm uptrends when price moves above average, and confirm downtrends when the price moves below average. A trend change might be occurring when the price moves in a direction away from the average. In addition, moving averages can be used to signify support and/or resistance territories. - -The Double EMA has a quicker response when compared with traditional EMAs and can be used in the same ways. Remember that if you are using Double EMAs that it reacts quicker and therefore you should be planning your strategies around this information - alterations may be in order. - -Traditional moving averages are good to use to identify trends in markets, but they don’t give much data when prices are choppy or not smooth. When price crosses the moving average or Double EMA, it is difficult to determine results and decide on when a trade will be profitable. - -For this reason, it is great to pair the Double EMA with other technical indicators, or other price and/or fundamental analysis tools. By pairing the Double EMA, investors and traders can better determine market trends while looking at the big picture, and not getting hung up on the limitations or focusing on one sole indicator. - -Reducing lag can be beneficial in some instances, such as if there is a reversal in actual price. It can help get a trader out quickly and before any major losses occur. However, reduced lag may also result in something called overtrading; when an indicator provides a trader with too many signals at once. An indicator that has less lag is also more susceptible to reacting to small shifts in price that would normally not have a large effect. So remember that lag can be good at times, but at others it can really get in the way. It is up to the trader to decide whether or not lag is something they want or need from their indicator. - -![alt](images/03-DoubleExponential.png) - -### Triple Exponential Moving Average (TEMA) 📈 - -The Triple Exponential Moving Average (EMA) indicator was created to make it easier for traders to determine strength or weakness without the traditional lag associated with regular moving averages (MAs). In order to accomplish this, the Triple EMA takes multiple EMAs of the original EMA and then subtracts lag from the result. - -Although the Triple EMA is known by many traders as a great indicator for reducing lag, it still has its faults as is true for any other indicator. MAs, for example, are very useful for trending markets, when price direction is particularly strong. When trends are choppy and price direction is weak, MAs, and the Triple EMA as well, may generate false signals as price fluctuates and the direction is in flux. - -The Triple Exponential Moving Average reduces lag, smooths price fluctuations, and is an alternative to other moving averages because of its different calculation. Its calculation takes multiple EMAs of the original EMA and then subtracts lag from the result. - -![alt](images/04-TripleExponential.png) - -### Weighted Exponential Moving Average (WMA) 📈 - -The weighted average is any mean multiplies factors to provide different weights for different data. -In the technical analysis, the weighted moving average represents, specifically, the value of weights that decrease arithymetically. -Thus, on a day X, the last day WMA has weight X, from the penultimate day has X-1 weight and so on until the day 0. - -The weighted moving average is used to "solve" the problem of equal weights. -This indicator is calculated by the sum of all closing prices divided for a certain period of time and multiplying them from the sum of the values (weights) each day. -For example, for a powerful average of five days, today's closing price will be multiplied by five, yesterday per four and so on until the first day on the period of the period is reached. -These values are then added and divided by the sum of the multipliers. - -![alt](images/05-Weighted.png) - -### Smoothed Moving Average 📈 - -The Smoothed Moving Average compares recent prices to historical ones and makes sure they are weighed and considered equally. -The calculation of this indicator does not reference a specific or fixed period, rather uses all available data in the series for analysis. The Smoothed Moving Average differs from the Exponential Moving Average (EMA) because it’s generally used with a longer time period. - -The Smoothed Moving Average compares recent prices to historical ones and ensures they are analyzed with equal weight. The indicator does not refer to a fixed period when calculating results, but rather it uses all data available and does not remove specific data points once they have passed a specific time threshold. - -![alt](images/06-Smothed.png) - -### Least Squares Moving Average 📈 - -Least Square Moving Average is also called Linear regression moving average. -Moving linear regression may look similar to a moving average, but differs in its calculation. -Moving averages are calculated using an average of closing prices, like with simple moving averages (SMA). -Alternatively, they can be calculated by assigning greater weights to more recent prices and proportionately lower weights to prices farther in the past and then averaging those together (in this case, the most common form is the exponential moving average, or EMA). - -Moving linear regression takes a continuous series of linear regression line endpoints and joins them together. - -Based on these different methodologies, moving linear regression tends to hug price a lot more closely than moving averages of the same periodicity. - -![alt](images/07-LeastSquares.png) - -### Hull Moving Average 📈 - -The Hull Moving Average (HMA) is a directional trend indicator. It captures the current state of the market and uses recent price action to determine if conditions are bullish or bearish relative to historical data. - -The Hull differs from more traditional trend indicators like the Exponential Moving Average (EMA) and the Simple Moving Average (SMA). It is designed to reduce the lag often associated with those MAs by providing a faster signal on a smoother visual plane. - -The Hull Moving Average (HMA) is a quick and smooth moving average that is distinct in its own nature. The HMA attempts to remove lag in its entirety, while simultaneously improving upon smoothing. - -![alt](images/08-Hull.png) - -### Arnaud Legoux Moving Average (ALMA) 📈 - -The ALMA is a technical analysis tool that aims to give investors and traders a more reliable trading signal by reducing the noise that can interfere with traditional moving averages. It eliminates the small fluctuations in an asset price to make the trend clearer. - -The ALMA reduces price lag and creates a smoother line than other moving averages. Rather than a straightforward moving average for a certain period, it applies a moving average twice – from left to right as well as right to left. - -The ALMA is a relatively new technical indicator, as many of them were developed during the 1970s, but it has quickly become popular. Arnaud Legoux and Dimitrios Kouzis Loukas developed the average in 2009 as they sought to address the weaknesses of simple moving averages (SMAs) and exponential moving averages (EMAs). They were inspired by Gaussian filters, which remove detail and noise to create a smooth image. - -Legoux and Kouzis Loukas aimed to provide a leading indicator, as SMAs, EMAs and Smoothed Moving Averages (SMMAs) are considered lagging indicators. - +# ![logo](images/Pine.png "Pine") + +## Moving Averages Collection + +## Summary 💊 + +This is a collection of moving averages indicators. +It's developed in PineScript for the technical analysis platform of **TradingView**. + +## Motivation 💊 + +To use the different types of moving averages (for example: simple, exponential, etc.), it is necessary to insert each indicator separately. + +This can be tedius, requiring the inclusion or removal of the indicators every time you want to make the change. + +Basically, what this script does, is to allow the dynamic use of these indicators. +That is, it is possible to choose the type of moving average as needed, facilitating the comparison and creation of setups. + +## Caution 💊 + +No technical indicators are 100% accurate as they can sometimes generate false signals. + +You should never rely on a single indicator and always use a range of them when making trading decisions. + +--- + +## How to use this tool 💊 + +Simply choose the type desired as the figure. +In all are fourteen moving averages. +There is also the possibility of choosing the indidual type of each. + +![alt](images/10-Params_1.png) + +--- + +## Definitions 💊 + +### 1. Moving Averages 📈 + +The moving average (MA) is a delayed (or reactive) price-based indicator that displays the average price of a title for a defined period of time. +A moving average is a good way to evaluate the moment, confirm trends and set support and resistance areas. +Essentially, the moving averages soften the "noise" when trying to interpret graphics. +Noise is composed of price and volume fluctuations. +As a moving average is a delay indicator and reacts to events that have already occurred, It is not used as a predictive indicator, but as an interpretive indicator, used for confirmations and analyzes. +In fact, moving averages are the basis of several other known technical analysis tools such as Bollinger bands and MACD. + +### 2. Simple Moving Average (SMA) 📈 + +The Simple Moving Average is an arithmetic moving average calculated by adding recent prices and then dividing then by the number of time periods in the calculation average. +This average is a non-weighted moving average, so this means that every day in the dataset they have equal importance and have the same weight. +Although old, it is a very efficient indicator to demonstrate supports and resistances and if the market is in a high, low or lateral tendency. + +![alt](images/01-Simple.png) + +### Exponential Moving Average (EMA) 📈 + +The Exponential Moving Average (EMA) is a specific type of moving average that points towards the importance of the most recent data and information from the market. +It’s exponential, weighting the most recent prices more than the less recent prices. + +Although using the Exponential Moving Average has a lot of advantages when analyzing market trends, +it is also uncertain whether or not the use of most recent data points truly affects technical and market analysis. +In addition, the EMA relies on historical data as its basis for operating and because news, events, +and other information can change rapidly the indicator can misinterpret this information by weighting the current prices higher than when the event actually occurred. + +![alt](images/02-Exponential.png) + +### Double Exponential Moving Average (DEMA) 📈 + +The Double Exponential Moving Average is a technical indicator that uses two moving averages to help confirm uptrends when price moves above average, and confirm downtrends when the price moves below average. A trend change might be occurring when the price moves in a direction away from the average. In addition, moving averages can be used to signify support and/or resistance territories. + +The Double EMA has a quicker response when compared with traditional EMAs and can be used in the same ways. Remember that if you are using Double EMAs that it reacts quicker and therefore you should be planning your strategies around this information - alterations may be in order. + +Traditional moving averages are good to use to identify trends in markets, but they don’t give much data when prices are choppy or not smooth. When price crosses the moving average or Double EMA, it is difficult to determine results and decide on when a trade will be profitable. + +For this reason, it is great to pair the Double EMA with other technical indicators, or other price and/or fundamental analysis tools. By pairing the Double EMA, investors and traders can better determine market trends while looking at the big picture, and not getting hung up on the limitations or focusing on one sole indicator. + +Reducing lag can be beneficial in some instances, such as if there is a reversal in actual price. It can help get a trader out quickly and before any major losses occur. However, reduced lag may also result in something called overtrading; when an indicator provides a trader with too many signals at once. An indicator that has less lag is also more susceptible to reacting to small shifts in price that would normally not have a large effect. So remember that lag can be good at times, but at others it can really get in the way. It is up to the trader to decide whether or not lag is something they want or need from their indicator. + +![alt](images/03-DoubleExponential.png) + +### Triple Exponential Moving Average (TEMA) 📈 + +The Triple Exponential Moving Average (EMA) indicator was created to make it easier for traders to determine strength or weakness without the traditional lag associated with regular moving averages (MAs). In order to accomplish this, the Triple EMA takes multiple EMAs of the original EMA and then subtracts lag from the result. + +Although the Triple EMA is known by many traders as a great indicator for reducing lag, it still has its faults as is true for any other indicator. MAs, for example, are very useful for trending markets, when price direction is particularly strong. When trends are choppy and price direction is weak, MAs, and the Triple EMA as well, may generate false signals as price fluctuates and the direction is in flux. + +The Triple Exponential Moving Average reduces lag, smooths price fluctuations, and is an alternative to other moving averages because of its different calculation. Its calculation takes multiple EMAs of the original EMA and then subtracts lag from the result. + +![alt](images/04-TripleExponential.png) + +### Weighted Exponential Moving Average (WMA) 📈 + +The weighted average is any mean multiplies factors to provide different weights for different data. +In the technical analysis, the weighted moving average represents, specifically, the value of weights that decrease arithymetically. +Thus, on a day X, the last day WMA has weight X, from the penultimate day has X-1 weight and so on until the day 0. + +The weighted moving average is used to "solve" the problem of equal weights. +This indicator is calculated by the sum of all closing prices divided for a certain period of time and multiplying them from the sum of the values (weights) each day. +For example, for a powerful average of five days, today's closing price will be multiplied by five, yesterday per four and so on until the first day on the period of the period is reached. +These values are then added and divided by the sum of the multipliers. + +![alt](images/05-Weighted.png) + +### Smoothed Moving Average 📈 + +The Smoothed Moving Average compares recent prices to historical ones and makes sure they are weighed and considered equally. +The calculation of this indicator does not reference a specific or fixed period, rather uses all available data in the series for analysis. The Smoothed Moving Average differs from the Exponential Moving Average (EMA) because it’s generally used with a longer time period. + +The Smoothed Moving Average compares recent prices to historical ones and ensures they are analyzed with equal weight. The indicator does not refer to a fixed period when calculating results, but rather it uses all data available and does not remove specific data points once they have passed a specific time threshold. + +![alt](images/06-Smothed.png) + +### Least Squares Moving Average 📈 + +Least Square Moving Average is also called Linear regression moving average. +Moving linear regression may look similar to a moving average, but differs in its calculation. +Moving averages are calculated using an average of closing prices, like with simple moving averages (SMA). +Alternatively, they can be calculated by assigning greater weights to more recent prices and proportionately lower weights to prices farther in the past and then averaging those together (in this case, the most common form is the exponential moving average, or EMA). + +Moving linear regression takes a continuous series of linear regression line endpoints and joins them together. + +Based on these different methodologies, moving linear regression tends to hug price a lot more closely than moving averages of the same periodicity. + +![alt](images/07-LeastSquares.png) + +### Hull Moving Average 📈 + +The Hull Moving Average (HMA) is a directional trend indicator. It captures the current state of the market and uses recent price action to determine if conditions are bullish or bearish relative to historical data. + +The Hull differs from more traditional trend indicators like the Exponential Moving Average (EMA) and the Simple Moving Average (SMA). It is designed to reduce the lag often associated with those MAs by providing a faster signal on a smoother visual plane. + +The Hull Moving Average (HMA) is a quick and smooth moving average that is distinct in its own nature. The HMA attempts to remove lag in its entirety, while simultaneously improving upon smoothing. + +![alt](images/08-Hull.png) + +### Arnaud Legoux Moving Average (ALMA) 📈 + +The ALMA is a technical analysis tool that aims to give investors and traders a more reliable trading signal by reducing the noise that can interfere with traditional moving averages. It eliminates the small fluctuations in an asset price to make the trend clearer. + +The ALMA reduces price lag and creates a smoother line than other moving averages. Rather than a straightforward moving average for a certain period, it applies a moving average twice – from left to right as well as right to left. + +The ALMA is a relatively new technical indicator, as many of them were developed during the 1970s, but it has quickly become popular. Arnaud Legoux and Dimitrios Kouzis Loukas developed the average in 2009 as they sought to address the weaknesses of simple moving averages (SMAs) and exponential moving averages (EMAs). They were inspired by Gaussian filters, which remove detail and noise to create a smooth image. + +Legoux and Kouzis Loukas aimed to provide a leading indicator, as SMAs, EMAs and Smoothed Moving Averages (SMMAs) are considered lagging indicators. + ![alt](images/09-ALMA.png) \ No newline at end of file