declare lower;
input showVerticalLines = yes;
input showTrampolines = yes;
input showSqueezeDots = no;
plot ZeroLine = if !IsNaN(open) and !showSqueezeDots then 0 else Double.NaN;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetLineWeight(2);
ZeroLine.HideBubble();
ZeroLine.HideTitle();
def currentAggPeriod = GetAggregationPeriod();
def higherAggPeriod =
if currentAggPeriod <= AggregationPeriod.TWO_MIN then AggregationPeriod.FIVE_MIN
else if currentAggPeriod <= AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN
else if currentAggPeriod <= AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN
else if currentAggPeriod <= AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN
else if currentAggPeriod <= AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR
else if currentAggPeriod <= AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS
else if currentAggPeriod <= AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY
else if currentAggPeriod <= AggregationPeriod.FOUR_HOURS then AggregationPeriod.TWO_DAYS
else if currentAggPeriod <= AggregationPeriod.DAY then AggregationPeriod.WEEK
else if currentAggPeriod <= AggregationPeriod.WEEK then AggregationPeriod.MONTH
else AggregationPeriod.QUARTER
;
script MoxieFunc {
input price = close;
def vc1 = ExpAverage(price, 12) - ExpAverage(price , 26);
def va1 = ExpAverage(vc1, 9);
plot data = (vc1 - va1) * 3;
}
plot Moxie = MoxieFunc(close(period = higherAggPeriod));
Moxie.SetLineWeight(2);
Moxie.DefineColor("Up", Color.GREEN);
Moxie.DefineColor("Down", Color.RED);
def lastChange = if Moxie < Moxie[1] then 1 else 0;
Moxie.AssignValueColor(
if lastChange == 1 then Moxie.Color("Down")
else Moxie.Color("Up")
);
# Watkins uses a different setup for Moxie on his 15 minute charts.
# He uses two lines derived from two higher timeframes.
# For timeframes other than 15 minutes we'll use the same data as
# first Moxie line to reduce data requested from the server and
# improve performance.
def secondAggPeriod =
if currentAggPeriod == AggregationPeriod.FIFTEEN_MIN
then AggregationPeriod.TWO_HOURS
else currentAggPeriod
;
plot MoxieSecondLine =
if currentAggPeriod == AggregationPeriod.FIFTEEN_MIN
then MoxieFunc(close(period = secondAggPeriod))
else Double.NaN
;
MoxieSecondLine.SetLineWeight(2);
MoxieSecondLine.DefineColor("Up", Color.GREEN);
MoxieSecondLine.DefineColor("Down", Color.RED);
def lastChangeSecondLine = if MoxieSecondLine < MoxieSecondLine[1] then 1 else 0;
MoxieSecondLine.AssignValueColor(
if lastChangeSecondLine == 1 then MoxieSecondLine.Color("Down")
else MoxieSecondLine.Color("Up")
);
MoxieSecondLine.SetHiding(currentAggPeriod != AggregationPeriod.FIFTEEN_MIN);
# Show vertical lines at crossovers
AddVerticalLine(showVerticalLines and Moxie[1] crosses above 0, "", CreateColor(0,150,0), Curve.SHORT_DASH);
AddVerticalLine(showVerticalLines and Moxie[1] crosses below 0, "", CreateColor(200,0,0), Curve.SHORT_DASH);
# Indicate the Trampoline setup
def sma50 = Average(close, 50);
plot Trampoline =
if showTrampolines and ((Moxie < -.01 and close > sma50) or (Moxie > .01 and close < sma50))
then 0
else Double.NaN
;
Trampoline.SetPaintingStrategy(PaintingStrategy.SQUARES);
Trampoline.DefineColor("Bullish", Color.LIGHT_GREEN);
Trampoline.DefineColor("Bearish", Color.PINK);
Trampoline.AssignValueColor(if close > sma50 then Trampoline.Color("Bearish") else Trampoline.Color("Bullish"));
Trampoline.HideBubble();
Trampoline.HideTitle();
# show squeeze dots on zero line
def bb = reference BollingerBands.LowerBand;
def squeezeLevel =
if bb > KeltnerChannels(factor = 1.0).Lower_Band then 3
else if bb > KeltnerChannels(factor = 1.5).Lower_Band then 2
else if bb > KeltnerChannels(factor = 2.0).Lower_Band then 1
else 0
;
plot Squeeze = if !showSqueezeDots then Double.NaN else if !IsNaN(open) then 0 else Double.NaN;
Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetDefaultColor(Color.GRAY);
Squeeze.DefineColor("Loose Squeeze", Color.UPTICK);
Squeeze.DefineColor("Squeeze", Color.RED);
Squeeze.DefineColor("Tight Squeeze", Color.YELLOW);
Squeeze.DefineColor("No Squeeze", Color.GRAY);
Squeeze.AssignValueColor(
if squeezeLevel == 3 then Squeeze.Color("Tight Squeeze")
else if squeezeLevel == 2 then Squeeze.Color("Squeeze")
else if squeezeLevel == 1 then Squeeze.Color("Loose Squeeze")
else Squeeze.Color("No Squeeze")
);
Squeeze.SetLineWeight(2);
Squeeze.HideTitle();
Squeeze.HideBubble();
AddLabel(
yes,
if currentAggPeriod == AggregationPeriod.WEEK then " W "
else if currentAggPeriod == AggregationPeriod.Day then " D "
else if currentAggPeriod == AggregationPeriod.HOUR then " H "
else if currentAggPeriod == AggregationPeriod.FIFTEEN_MIN then " 15 "
else if currentAggPeriod == AggregationPeriod.FIVE_MIN then " 5 "
else if currentAggPeriod == AggregationPeriod.TWO_MIN then " 2 "
else " ",
if Moxie < 0 then Color.RED else Color.GREEN
);