JayRogers

Multi Time Frame MA Duplicates [Colour Switch]

This is revision 2 of "Multi Time Frame MA Duplicates"

Honorable Mentions:
  • @RicardoSantos - helped me fix my brain. Narf.
Description:
  • One stop shop for multiple MA duplicates over different resolutions.
  • A veritable banquet of MA's to choose from.
  • Set up your MA variables, and then plot up to 4 duplicates all using different time frames.
r2 Changes:
  • Simple "Drag Length" for colour switch - average for X bars back versus current, it's like a crossover, but with less scribbles.
  • Added Arnaud Legoux moving average (and the related inputs) to the array of MA choices!

Original Version:
Von Favorisierten Skripten entfernen Zu Favorisierten Skripten hinzufügen
//@version=2

study(title="Multi Time Frame MA Duplicates [Colour Switch]", shorttitle="MA Duplicates", overlay=true)

// Revision:    2 ( r1 - Multi Time Frame MA Duplicates )
// Author:      JayRogers
//
// Honorable Mentions:
//  - @RicardoSantos - helped me fix my brain. Narf.
//
// Description:
//  - One stop shop for multiple MA duplicates over different resolutions.
//  - A veritable banquet of MA's to choose from.
//  - Set up you MA variables, and then plot up to 4 duplicates all using different time frames.
// r2 Changes:
//  - Simple "Drag Length" for colour switch - average for X bars back versus current, it's like a crossover, but cleaner.
//  - Added Arnaud Legoux moving average and relevant inputs to the array of MA choices!

// - INPUTS START
maType      = input(defval="HullMA", title="MA Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )", type=string)
maSource    = input(defval=open, title="MA Source", type=source)
maLength    = input(defval=50, title="MA Period", minval=1)
dragLength  = input(defval=10, title="Colour Switch Average Period", minval=0)
lsmaOffset  = input(defval=0, title="* Least Squares (LSMA) Only - Offset Value", minval=0)
almaOffset  = input(defval=0.85, title="* Arnaud Legoux (ALMA) Only - Offset Value", minval=0, step=0.01)
almaSigma   = input(defval=6, title="* Arnaud Legoux (ALMA) Only - Sigma Value", minval=0)
res1        = input(defval="15", title="MA Duplicate 1 Resolution", type=resolution)
res2        = input(defval="30", title="MA Duplicate 2 Resolution", type=resolution)
res3        = input(defval="60", title="MA Duplicate 3 Resolution", type=resolution)
res4        = input(defval="120", title="MA Duplicate 4 Resolution", type=resolution)
// - INPUTS END

// - FUNCTIONS
// Returns chosen MA input calculation, default to SMA if blank or typo.
variant(type, src, len) =>
    v1 = sma(src, len)                                                  // Simple
    v2 = ema(src, len)                                                  // Exponential
    v3 = 2 * v2 - ema(v2, len)                                          // Double Exponential
    v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)               // Triple Exponential
    v5 = wma(src, len)                                                  // Weighted
    v6 = vwma(src, len)                                                 // Volume Weighted
    v7 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len    // Smoothed
    v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))   // Hull
    v9 = linreg(src, len, lsmaOffset)                                   // Least Squares
    v10 = alma(src, len, almaOffset, almaSigma)                         // Arnaud Legoux
    type=="EMA"?v2 : type=="DEMA"?v3 : type=="TEMA"?v4 : type=="WMA"?v5 : type=="VWMA"?v6 : type=="SMMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : type=="ALMA"?v10 : v1
// return selected resolution series
reso(exp, res) => security(tickerid, res, exp)
// simple dragging average directional change switch
dragSwitch(exp, res, len) =>
    average = len >= 2 ? sum(exp, len) / len : exp[1]
    up      = exp > average
    down    = exp < average
    state   = reso(up ? true : down ? false : up[1], res)
// - FUNCTIONS END

// - SERIES VARIABLES
ma1 = reso(variant(maType, maSource, maLength), res1)
ma2 = reso(variant(maType, maSource, maLength), res2)
ma3 = reso(variant(maType, maSource, maLength), res3)
ma4 = reso(variant(maType, maSource, maLength), res4)
upColour    = #33CC33
downColour  = #FF5555
// - SERIES VARIABLES END

// - PLOTTING
plot(ma1, title = "MA 1", color = dragSwitch(ma1, res1, dragLength) ? upColour : downColour, linewidth = 1, style = line, transp = 20)
plot(ma2, title = "MA 2", color = dragSwitch(ma2, res2, dragLength) ? upColour : downColour, linewidth = 2, style = line, transp = 20)
plot(ma3, title = "MA 3", color = dragSwitch(ma3, res3, dragLength) ? upColour : downColour, linewidth = 3, style = line, transp = 20)
plot(ma4, title = "MA 4", color = dragSwitch(ma4, res4, dragLength) ? upColour : downColour, linewidth = 4, style = line, transp = 20)
// - PLOTTING END
Startseite Aktien-Screener Forex-Screener Krypto-Screener Wirtschaftskalender So funktioniert es! Chartmerkmale Preise Hausregeln Moderatoren Webseite & Brokerlösungen Widgets Charting Lösungen Hilfe holen Feature-Anfrage Blog & News FAQ - Häufige Fragen & Antworten Wiki Twitter
Profil Profileinstellungen Konto und Abrechnung Hilfe holen Veröffentlichte Ideen Followers Ich folge Private Nachrichten Chat Abmelden