Trampoline Dots
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// @version=5
//
// Trampoline Dots (Price Divergence Dots)
//
// Trampoline Dots serve as a "quick bounce" tool. These little dots will trigger whenever the higher aggregation MACD is above / below zero and the price 
// is below / above the 50 period simple moving average. When these criteria are met, the price is usually under pressure & reverse within the next few bars..
//
// Created by L&L Capital
// 

indicator("Trampoline Dots", shorttitle = "Trampoline Dots", overlay=false) 

// Inputs

length = input(defval= 50, title="MA Length")

// Trampoline Dots Calculations

funcM() =>
	price = close
	v1 = ta.ema(price , 12) - ta.ema(price , 26)
	v2 = ta.ema(v1, 9)
	data = (v1 - v2) * 3

currentPeriod = timeframe.period
CurrentAggPeriod = currentPeriod == '1' or currentPeriod == '2' ? request.security(syminfo.tickerid, '5', funcM())
  : currentPeriod == '3' ? request.security(syminfo.tickerid, '10', funcM())
  : currentPeriod == '5' ? request.security(syminfo.tickerid, '15', funcM())
  : currentPeriod == '10' ? request.security(syminfo.tickerid, '30', funcM())
  : currentPeriod == '15' ? request.security(syminfo.tickerid, '60', funcM())
  : currentPeriod == '30' ? request.security(syminfo.tickerid, '120', funcM())
  : currentPeriod == '45' ? request.security(syminfo.tickerid, '120', funcM())
  : currentPeriod == '60' ? request.security(syminfo.tickerid, 'D', funcM())
  : currentPeriod == '120' ? request.security(syminfo.tickerid, 'D', funcM())
  : currentPeriod == '180' ? request.security(syminfo.tickerid, 'D', funcM())
  : currentPeriod == '240' ? request.security(syminfo.tickerid, '2D', funcM())
  : currentPeriod == 'D' ? request.security(syminfo.tickerid, 'W', funcM())
  : currentPeriod == 'W' ? request.security(syminfo.tickerid, 'M', funcM())
  : currentPeriod == 'M' ? request.security(syminfo.tickerid, '3M', funcM())
  : na

price = CurrentAggPeriod
ema = ta.sma(close,50)
M = funcM()

// Plots

trampoline = if ((CurrentAggPeriod < 0 and close > ema) or (CurrentAggPeriod > 0 and close < ema))
	0
color1 = close < ema ? #27c22e : #ff0000

plotshape(trampoline, title="Trampoline Dots", style=shape.circle, location=location.absolute, color = color1)