-
-
Save niquedegraaff/0ebf5efaef95c1fdcd6af1f62ebf4756 to your computer and use it in GitHub Desktop.
Momentum Waves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
// © niquedegraaff | |
// @version=5 | |
// @description Calculates momentum waves | |
indicator(title = "MOMENTUM_WAVES", | |
shorttitle = "MOMENTUM WAVES", | |
precision = 2, | |
overlay = false) | |
// MAIN: COLOR PALETTE | |
color TEAL = color.new(#3ab7a6, 0) | |
color DARKBLUE = color.new(#3a4bb7, 0) | |
color LIGHTBLUE = color.new(#3a8ab7, 0) | |
color RED = color.new(#b73a4b, 0) | |
color YELLOW = color.new(#b7a63a, 0) | |
color GREEN = color.new(#89b73a, 0) | |
color PURPLE = color.new(#683ab7, 0) | |
color PINK = color.new(#b73a89, 0) | |
color ORANGE = color.new(#b7683a, 0) | |
color SILVER = color.new(#cccccc, 0) | |
color TRANSPARENT = color.new(#ffffff, 100) | |
// ------------------------------------------------------------------------------------------------------ | |
// MOMENTUM WAVES | |
// ------------------------------------------------------------------------------------------------------ | |
// MW: INPUT | |
int i_mwAnchorLvl = input(60, "Anchor Level") | |
int i_mwTriggerLvl = input(53, "Trigger Level") | |
// MW: Basic | |
// @function Calculates Momentum Waves and returns basic parameters | |
// @param src Series to use (`hlc3` is used if no argument is supplied). | |
// @param chLen Length used for chLen (`5` is used if no argument is supplied). | |
// @param fastLen Length used for fast wave (`9` is used if no argument is supplied). | |
// @param slowLen Length used for slow wave (`3` is used if no argument is supplied). | |
// @returns mw1 Fast Wave | |
// @returns mw2 Slow Wave | |
// @returns mwGreenDot Green Dot? | |
// @returns mwGreenDotAnch Green Dot at Anchor level? | |
// @returns mwGreenDotTrig Green Dot at Trigger level? | |
// @returns mwRedDot Red Dot | |
// @returns mwGreenDotAnch Red Dot at Anchor level? | |
// @returns mwRedDotTrig Red Dot at Trigger level? | |
mw(float src = hlc3, simple int chLen = 5, simple int fastLen = 9, simple int slowLen = 3, simple int anchLvl = 60, simple int trigLvl = 53) => | |
float esa = ta.ema(src, chLen) | |
float de = ta.ema(math.abs(src - esa), chLen) | |
float ci = (src - esa) / (0.015 * de) | |
float mw1 = ta.ema(ci, fastLen) // Fast Wave | |
float mw2 = ta.sma(mw1, slowLen) // Slow Wave | |
float mwv = mw1 - mw2 // Wave VWAP | |
bool mwRedDot = ta.crossover(mw2, mw1) // Green Dot | |
bool mwRedDotAnch = mwRedDot and mw2 <= -anchLvl // Red Dot Anchor | |
bool mwRedDotTrig = mwRedDot and mw2 <= -trigLvl // Red Dot Trigger | |
bool mwGreenDot = ta.crossunder(mw2, mw1) // Green Dot | |
bool mwGreenDotAnch = mwGreenDot and mw2 >= anchLvl // Green Dot Anchor | |
bool mwGreenDotTrig = mwGreenDot and mw2 >= trigLvl // Green Dot Trigger | |
[mw1, | |
mw2, | |
mwv, | |
mwRedDot, | |
mwRedDotAnch, | |
mwRedDotTrig, | |
mwGreenDot, | |
mwGreenDotAnch, | |
mwGreenDotTrig] | |
// MW: Extended | |
// @function Calculates Momentum Waves and returns extended parameters | |
// @param src Series to use (`hlc3` is used if no argument is supplied). | |
// @param chLen Length used for chLen (`9` is used if no argument is supplied). | |
// @param fastLen Length used for fast wave (`12` is used if no argument is supplied). | |
// @param slowLen Length used for slow wave (`3` is used if no argument is supplied). | |
// @returns mw1 Fast Wave | |
// @returns mw2 Slow Wave | |
// @returns mwGreenDot Green Dot? (slow wave crosses above fast wave) | |
// @returns mwGreenDotAnch Green Dot at Anchor level? | |
// @returns mwGreenDotTrig Green Dot at Trigger level? | |
// @returns mwRedDot Is Red Dot? (slow wave crosses below fast wave) | |
// @returns mwGreenDotAnch Is Red Dot at Anchor level? | |
// @returns mwRedDotTrig Is Red Dot at Trigger level? | |
// @returns mwIsPositive Is slow wave above zero? | |
// @returns mwIsNegative Is slow wave below zero? | |
// @returns mwAboveMw1 Is slow wave above fast wave? | |
// @returns mwBelowMw1 Is slow wave below fast wave? | |
// @returns mwAtAnchLvlTop Is slow wave above top anchor level? | |
// @returns mwAtAnchLvlBot Is slow wave below bottom anchor level? | |
// @returns mwAtTrigLvlTop Is slow wave above top trigger level? | |
// @returns mwAtTrigLvlBot Is slow wave below bottom trigger level? | |
// @returns mwDot Is green or red dot? | |
// @returns mwDotB Bars back to previous dot | |
// @returns mwCrossOverZero Is slow wave crossing above zero? | |
// @returns mwCrossUnderZero Is slow wave crossing below zero? | |
// TODO: FINISH THE DESCRIPTION FOR THIS FUNCTION | |
mwe(float src = hlc3, simple int chLen = 5, simple int fastLen = 9, simple int slowLen = 3, simple int anchLvl = 60, simple int trigLvl = 53) => | |
[mw1, mw2, mwv, mwRedDot, mwRedDotAnch, mwRedDotTrig, mwGreenDot, mwGreenDotAnch, mwGreenDotTrig] = mw(src, chLen, fastLen, slowLen, anchLvl, trigLvl) | |
int mwRedDotB = math.min(500, ta.barssince(mwRedDot)) | |
int mwGreenDotB = math.min(500, ta.barssince(mwGreenDot)) | |
bool mwIsPositive = mw2 > 0 | |
bool mwIsNegative = mw2 < 0 | |
bool mwAboveMw1 = mw2 - mw1 >= 0 | |
bool mwBelowMw1 = mw2 - mw1 <= 0 | |
bool mwAtAnchLvlTop = mw2 >= anchLvl | |
bool mwAtAnchLvlBot = mw2 <= -anchLvl | |
bool mwAtTrigLvlTop = mw2 >= trigLvl | |
bool mwAtTrigLvlBot = mw2 <= -trigLvl | |
bool mwAtAnchLvl = mwAtAnchLvlTop or mwAtAnchLvlBot | |
bool mwAtTrigLvl = mwAtTrigLvlTop or mwAtTrigLvlBot | |
bool mwDot = mwGreenDot or mwRedDot | |
int mwDotB = math.min(mwGreenDotB, mwRedDotB) | |
bool mwCrossOverZero = ta.crossover(mw2, 0) | |
bool mwCrossUnderZero = ta.crossunder(mw2, 0) | |
bool mwCrossZero = mwCrossOverZero or mwCrossUnderZero | |
int mwCrossOverZeroB = int(math.min(500, ta.barssince(mwCrossOverZero))) | |
int mwCrossUnderZeroB = int(math.min(500, ta.barssince(mwCrossUnderZero))) | |
int mwCrossZeroB = int(math.min(500, ta.barssince(mwCrossZero))) | |
bool mwCrossOverTrigLvl = ta.crossover(mw2, trigLvl) or ta.crossover(mw2, -trigLvl) | |
bool mwCrossUnderTrigLvl = ta.crossunder(mw2, -trigLvl) or ta.crossunder(mw2, trigLvl) | |
bool mwCrossOverTrigLvlTop = mwCrossOverTrigLvl and mwIsPositive | |
bool mwCrossOverTrigLvlBot = mwCrossOverTrigLvl and mwIsNegative | |
bool mwCrossUnderTrigLvlTop = mwCrossUnderTrigLvl and mwIsPositive | |
bool mwCrossUnderTrigLvlBot = mwCrossUnderTrigLvl and mwIsNegative | |
bool mwIsCrossingTrigLvl = mwCrossOverTrigLvl or mwCrossUnderTrigLvl | |
int mwCrossOverTrigLvlB = mwAtTrigLvl ? int(math.min(500, ta.barssince(mwCrossOverTrigLvl))) : na | |
int mwCrossUnderTrigLvlB = mwAtTrigLvl ? int(math.min(500, ta.barssince(mwCrossUnderTrigLvl))) : na | |
int mwCrossOverTrigLvlTopB = mwAtTrigLvl and mwIsPositive ? int(math.min(500, ta.barssince(mwCrossOverTrigLvlTop))) : na | |
int mwCrossOverTrigLvlBotB = mwAtTrigLvl and mwIsPositive ? int(math.min(500, ta.barssince(mwCrossUnderTrigLvlTop))) : na | |
int mwCrossUnderTrigLvlBotB = mwAtTrigLvl and mwIsNegative ? int(math.min(500, ta.barssince(mwCrossUnderTrigLvlBot))) : na | |
int mwCrossUnderTrigLvlTopB = mwAtTrigLvl and mwIsPositive ? int(math.min(500, ta.barssince(mwCrossUnderTrigLvlTop))) : na | |
bool mwTrigger = mwAtTrigLvl and mwDot | |
bool mwAnchor = mwAtAnchLvl and mwDot | |
bool mwRegTop = mwIsPositive and mwRedDot | |
bool mwRegBot = mwIsNegative and mwGreenDot | |
bool mwTrigTop = mwIsPositive and mwRedDot and mwAtTrigLvlTop | |
bool mwTrigBot = mwIsNegative and mwGreenDot and mwAtTrigLvlBot | |
bool mwAnchTop = mwIsPositive and mwRedDot and mwAtAnchLvlTop | |
bool mwAnchBot = mwIsNegative and mwGreenDot and mwAtAnchLvlBot | |
int mwAnchTopB = int(math.min(500, ta.barssince(mwAnchTop))) | |
int mwAnchBotB = int(math.min(500, ta.barssince(mwAnchBot))) | |
[mw1, | |
mw2, | |
mwv, | |
mwRedDot, | |
mwRedDotAnch, | |
mwRedDotTrig, | |
mwGreenDot, | |
mwGreenDotAnch, | |
mwGreenDotTrig, | |
mwIsPositive, | |
mwIsNegative, | |
mwAboveMw1, | |
mwBelowMw1, | |
mwAtTrigLvlTop, | |
mwAtTrigLvlBot, | |
mwAtAnchLvlTop, | |
mwAtAnchLvlBot, | |
mwRedDotB, | |
mwGreenDotB, | |
mwDot, | |
mwDotB, | |
mwCrossOverZero, | |
mwCrossOverZeroB, | |
mwCrossUnderZero, | |
mwCrossUnderZeroB, | |
mwCrossZero, | |
mwCrossZeroB, | |
mwCrossOverTrigLvl, | |
mwCrossOverTrigLvlB, | |
mwCrossUnderTrigLvl, | |
mwCrossUnderTrigLvlB, | |
mwCrossOverTrigLvlTop, | |
mwCrossOverTrigLvlTopB, | |
mwCrossOverTrigLvlBot, | |
mwCrossOverTrigLvlBotB, | |
mwCrossUnderTrigLvlTop, | |
mwCrossUnderTrigLvlTopB, | |
mwCrossUnderTrigLvlBot, | |
mwCrossUnderTrigLvlBotB, | |
mwAnchor, | |
mwTrigger, | |
mwRegTop, | |
mwRegBot, | |
mwTrigTop, | |
mwTrigBot, | |
mwAnchTop, | |
mwAnchTopB, | |
mwAnchBot, | |
mwAnchBotB] | |
[mw1, | |
mw2, | |
mwv, | |
mwRedDot, | |
mwRedDotAnch, | |
mwRedDotTrig, | |
mwGreenDot, | |
mwGreenDotAnch, | |
mwGreenDotTrig, | |
mwIsPositive, | |
mwIsNegative, | |
mwAboveMw1, | |
mwBelowMw1, | |
mwAtTrigLvlTop, | |
mwAtTrigLvlBot, | |
mwAtAnchLvlTop, | |
mwAtAnchLvlBot, | |
mwRedDotB, | |
mwGreenDotB, | |
mwDot, | |
mwDotB, | |
mwCrossOverZero, | |
mwCrossOverZeroB, | |
mwCrossUnderZero, | |
mwCrossUnderZeroB, | |
mwCrossZero, | |
mwCrossZeroB, | |
mwCrossOverTrigLvl, | |
mwCrossOverTrigLvlB, | |
mwCrossUnderTrigLvl, | |
mwCrossUnderTrigLvlB, | |
mwCrossOverTrigLvlTop, | |
mwCrossOverTrigLvlTopB, | |
mwCrossOverTrigLvlBot, | |
mwCrossOverTrigLvlBotB, | |
mwCrossUnderTrigLvlTop, | |
mwCrossUnderTrigLvlTopB, | |
mwCrossUnderTrigLvlBot, | |
mwCrossUnderTrigLvlBotB, | |
mwAnchor, | |
mwTrigger, | |
mwRegTop, | |
mwRegBot, | |
mwTrigTop, | |
mwTrigBot, | |
mwAnchTop, | |
mwAnchTopB, | |
mwAnchBot, | |
mwAnchBotB] = mwe(trigLvl = i_mwTriggerLvl, anchLvl = i_mwAnchorLvl) | |
// MW: PLOT | |
var mwPlotFast = plot( | |
title = "MW Fast", | |
series = mw1, | |
color = color.new(LIGHTBLUE, 21), | |
style = plot.style_area, | |
linewidth = 0) | |
var mwPlotSlow = plot( | |
title = "MW Slow", | |
series = mw2, | |
color = color.new(DARKBLUE, 21), | |
style = plot.style_area, | |
linewidth = 0) | |
var mwPlotCrossDot = plot( | |
title = "MW Cross Dot", | |
series = (mwRedDot or mwGreenDot) ? mw2 : na, | |
color = mw2 - mw1 > 0 ? mwTrigTop ? PINK : color.new(#802860, 10) : mwTrigBot ? TEAL : color.new(#288074, 10), | |
style = plot.style_circles, | |
linewidth = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment