MagicBlueBalls
New member
Hello traders. I managed to get this code from a friend. He is a little weird, but he makes money consistently trading /es. That's all he does.
So... here it is the Trading Divergence Monster Laguerre + Inertia.
If anyone here can improve on this indicator please contribute. As it is... the code is pretty consistent and works really well on 5 tick Renko charts for /es. I haven't tested it on any other stonks.
HINT - IMPORTANT!
"#Turn off the original inertia, Mobius Laguerre [RSI], CTTC, SumSum. You can mess around with the mimic and the STDs deviations... The STDs can give some good signals between 1 and 1.3. "
@mashume
Quick edit:
I love it when the Renko bricks are bottom or top flat and you can see the divergence on the indicator. This is in my opinion the best type of divergence this indicator offers. Today, this indicator offered around 8 to 10 good signals. I know my friend has made some tweaks that give fewer signals but it is more accurate... like 80% to 90% ... but he is not giving me that part of the code.
Here is a comparison with common indicators... MACD, RSI, Full Stoch, Inertia... The code is similar to MACD for divergences but in some instances, the monster does a better job identifying them.
So... here it is the Trading Divergence Monster Laguerre + Inertia.
If anyone here can improve on this indicator please contribute. As it is... the code is pretty consistent and works really well on 5 tick Renko charts for /es. I haven't tested it on any other stonks.
HINT - IMPORTANT!
"#Turn off the original inertia, Mobius Laguerre [RSI], CTTC, SumSum. You can mess around with the mimic and the STDs deviations... The STDs can give some good signals between 1 and 1.3. "
@mashume
Quick edit:
I love it when the Renko bricks are bottom or top flat and you can see the divergence on the indicator. This is in my opinion the best type of divergence this indicator offers. Today, this indicator offered around 8 to 10 good signals. I know my friend has made some tweaks that give fewer signals but it is more accurate... like 80% to 90% ... but he is not giving me that part of the code.
Here is a comparison with common indicators... MACD, RSI, Full Stoch, Inertia... The code is similar to MACD for divergences but in some instances, the monster does a better job identifying them.
Ruby:
#Sup Magic. Here is the code you wanted. I compiled a bunch into this. It is intended to be used in Renko charts, but it works just fine in time charts. Stick to 5 and 15 mins ... any lower and it is a mess.
#Let's begin:
#Turn off the original inertia, Mobius Laguerre [RSI], CTTC, SumSum. You can mess around with the mimic and the STDs deviations... The STDs can give some good signals between 1 and 1.3.
#This is the Trading Divergence Monster Laguerre + Inertia For ThinkOrSwim
#This works because I am using Volume . Mashume's code is probably not necessary but I'm leaving it there. He is good. Maybe he can improve on this.
declare lower;
#Mashume created this one. You may find it at https://usethinkscript.com/threads/renko-wave-volume.10005/#post-89852
input lengthTRQ = 10;
def trend_change = if (open[1] < close[1] and open > close) or (open[1] > close[1] and open < close) then 1 else 0;
def direction = if (open[1] < close[1] and open > close) then -1 else if (open[1] > close[1] and open < close) then 1 else direction[1];
def cumulative_trend_tick_count = if trend_change == 1 then direction * tick_count() else cumulative_trend_tick_count[1] + (direction * tick_count());
plot CTTC = cumulative_trend_tick_count;
CTTC.AssignValueColor(if CTTC <= 0 then color.dark_red else color.dark_green);
CTTC.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot sumsum = sum(CTTC, lengthTRQ) / lengthTRQ;
sumsum.SetDefaultColor(color.black);
sumSum.AssignValueColor(if sumsum <= 0 then color.light_red else color.light_green);
SumSum.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
########################################################################
######################################################
############################
#############
######
#
#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#
input lengthFGH = 20;
input rviLength = 14;
plot Inertia = Inertia(RelativeVolatilityIndex(rviLength), lengthFGH);
Inertia.SetDefaultColor(GetColor(1));
########################################################################
######################################################
############################
#############
######
#
# Mobius©: ## RSI in Laguerre Time auto-adjusted with fractal dimensions algorithm
# Mobius
# V03.08.2014
# Added Squeeze Points color coded by RSI position (for no particular reason other than I could)
# Dilbert/Thomas - Here's a compendium of Mobius comments regarding interpretation of the his RSI Laguerre/FE study. Since some of the info was duplicated across several days I have attempted to re-order it in some logical fashion.
#DISCLAIMER: Mobius mentioned that it was not his habit to give trading advice or even advice on how to use indicators. However, there's been such a proliferation of bad, inaccurate, false info regarding so many of them recently he felt compelled to give some accurate information.
#Mobius©: I use a very simple method – RSI Laguerre and Fractal Energy on a list of very liquid stocks. I look for polarity change and trade when both RSI and FE are in “confluence”. If volatility is high enough I sell spreads if not I buy them. Other than hedging (which I do a lot of) that's it. I like it simple.
#The typical base setting I like to use for the FE is a length of 8. If I'm trading options I like to look at it about the length of time I'm buying or selling the option for. I want to know if it's reverting and where the energy is so I'll use a longer length for reversion and a shorter length to see if energy is building or waning.
##If RSI Laguerre is descending and FE over .6, that tells me something is changing and I'm already looking at an equity I've determined is about to make a polarity change. So the worse case that happens is that the security grinds sideways for a few days.
#A reading of the FE over .6 is an indication that energy has been built up. If the FE is high (over .6) and RSI LaGuerre is breaking lower FE will follow suit. If RSI reverses and goes above .8 I'm outa there, with the assumption I have a short position.
#FE is a gauge of both mean reverting and linearity. Descending readings indicate a trend is on. A reading below .3 indicates exhaustion in trend or near exhaustion. A reading above .6 indicates moving sideways with rapid reversion and energy building for a move again.
#Above .6 - Think price compression or squeeze Below .3 - Think running out of gas
#Here's an example:
#FE at 60 periods is oscillating around .5 tightly while FE at 8 periods is over .6. Zscore is over 2 and is starting to roll over. That is a good short to the mean.
#Short trade setup I look for with RSI Laguerre adjusted with FE.
#1) Polarity Change - Equity has gone from making higher highs and higher lows to making a lower high and lower low and is now putting in another lower high
#2) RSI Laguerrer is above .8 and descending from 1
#3) Fractal Energy is below .38 and nose down or above .6 and rolling over. In the first case, below .38, FE is indicating trend exahustion and RSI is likely showing as a peak and not running across pegged at 1. In the second case price has risen to a lower resistance and has been rolling slowly over building energy.
#Inputs:
input n = 3; #hint n: Periods for fractal dimensions calculations
input AscaleLow = .0381; #hint AscaleLow: Typical range from .1 to .5
input AscaleHigh = .0619; #hint AscaleHigh: Typical range from .5 to .9
input timeFrame = {default DAY, WEEK, MONTH};
input PriceTW = {default HeikenAshi, VWAP};
# Variables:
def v = volume;
def cap = GetAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
case MONTH:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = v;
volumeVwapSum = v * vwap;
volumeVwap2Sum = v * Sqr(vwap);
} else {
volumeSum = CompoundValue(1, volumeSum[1] + v, v);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + v * vwap, v * vwap);
volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + v * Sqr(vwap), v * Sqr(vwap));
}
def p = volumeVwapSum / volumeSum;
def o;
def h;
def l;
def c;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
def B;
def Ascaled;
def TR;
def data;
def L0;
def L1V;
def L2V;
def L3V;
plot RSI;
#plot OS;
#plot OB;
#plot MID;
# Internal Script
script Scale {
input c = close;
input Min = .01;
input Max = 1;
def hh = HighestAll(c);
def ll = LowestAll(c);
plot Range = (((Max - Min) * (c - ll)) / (hh - ll)) + Min;
}
# Calculations
o = open;
h = high;
l = low;
c = close;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
HAhigh = Max(Max(h, HAopen), HAclose[1]);
HAlow = Min(Min(l, HAopen), HAclose[1]);
HAclose = (HAopen + HAhigh + HAlow + HAclose[1]) / 4;
def PriceData;
switch (PriceTW) {
case VWAP:
PriceData = p;
case HeikenAshi:
PriceData = HAclose;
}
TR = Max(HAhigh, HAclose[1]) - Min(HAlow, HAclose[1]);
B = (Log(Sum(TR, n) / (Highest(HAhigh, n) - Lowest(HAlow, n)))
/ Log(10)) / (Log(n) / Log(10));
Ascaled = Round(Scale(c = B, min = AscaleLow, max = AscaleHigh), 2);
data = if IsNaN(Ascaled) then data[1] else Ascaled;
L0 = (1 – data) * PriceData + data * L0[1];
L1V = -data * L0 + L0[1] + data * L1V[1];
L2V = -data * L1V + L1V[1] + data * L2V[1];
L3V = -data * L2V + L2V[1] + data * L3V[1];
if L0 >= L1V
then {
CU1 = L0 - L1V;
CD1 = 0;
} else {
CD1 = L1V - L0;
CU1 = 0;
}
if L1V >= L2V
then {
CU2 = CU1 + L1V - L2V;
CD2 = CD1;
} else {
CD2 = CD1 + L2V - L1V;
CU2 = CU1;
}
if L2V >= L3V
then {
CU = CU2 + L2V - L3V;
CD = CD2;
} else {
CU = CU2;
CD = CD2 + L3V - L2V;
}
RSI = if CU + CD <> 0
then if CU / (CU + CD) < .09
then 0
else if CU / (CU + CD) > .9
then 100
else CU / (CU + CD)
else 0;
#OS = if IsNaN(close) then Double.NaN else 20;
#OB = if IsNaN(close) then Double.NaN else 80;
#MID = if IsNaN(close) then Double.NaN else 50;
RSI.SetDefaultColor(Color.CYAN);
RSI.SetLineWeight(1);
#OS.SetDefaultColor(Color.GRAY);
#OB.SetDefaultColor(Color.GRAY);
#MID.SetDefaultColor(Color.DARK_GRAY);
#MID.SetStyle(Curve.Short_Dash);
#AddCloud(100, OB, Color.GREEN);
#AddCloud(0, OS, Color.RED);
#Alert(RSI crosses below 90, "", Alert.BAR, Sound.Bell);
#Alert(RSI crosses above 10, "", Alert.BAR, Sound.Bell);
# Price Compression (Squeeze)
#def Avg;
#def ATR;
#def SD;
#def Squeeze;
#plot SqLoc;
#Avg = Average(close, 20);
#ATR = Average(TrueRange(high, close, low), 20);
#SD = StDev(close, 20);
#Squeeze = if Avg + (2 * SD) < Avg + (1.5 * ATR)
# then 100
# else Double.NaN;
#SqLoc = if !IsNaN(Squeeze) and RSI >= 80
# then 90
# else if !IsNaN(Squeeze) and RSI <= 20
# then 10
# else if !IsNaN(Squeeze) and Between(RSI, 20, 80)
# then 50
# else Double.NaN;
#SqLoc.SetPaintingStrategy(PaintingStrategy.POINTS);
#SqLoc.SetLineWeight(3);
#SqLoc.AssignValueColor(if SqLoc == 90
# then Color.WHITE
# else if SqLoc == 10
# then Color.YELLOW
# else if SqLoc == 50
# then Color.CYAN
# else Color.CURRENT);
#AddLabel(!IsNaN(Squeeze), "Squeeze", if SqLoc == 90
# then Color.WHITE
# else if SqLoc == 10
# then Color.YELLOW
# else if SqLoc == 50
# then Color.BLUE
# else Color.CURRENT);
# Scan Plots
#plot LongScan = if (RSI > RSI[1]) or (RSI > 80) then 1 else 0;
#LongScan.Hide();
#plot ShortScan = if (RSI < 20) then 1 else 0;
#ShortScan.Hide();
#def target = if RSI crosses above 20
# then Round((close + (1.5 * ATR)) / TickSize(), 0) * TickSize()
# else if RSI crosses below 80
# then Round((close - (1.5 * ATR)) / TickSize(), 0) * TickSize()
# else target[1];
#AddLabel(1, "Target " + AsDollars(Round(target)),
# if RSI > 20 and RSI > RSI[1]
# then Color.Green
# else if RSI < 80 and RSI < RSI[1]
# then Color.Red
# else Color.White);
# End Code
########################################################################
######################################################
############################
#############
######
#PercentileQ Calculations
def vol = reference VolumeZoneOscillator();
def volY = reference OnBalanceVolume();
def volX = reference MoneyFlowIndex();
def volA = reference ADX();
def volB = reference VolumeAvg();
def volJ = reference ChaikinMoneyFlow();
def volU = reference PercentChg();
def volT = reference KlingerOscillator();
def volM = reference RSI();
def volC = reference SlowVSI();
def volW = reference NegativeVolumeIndex();
def volS = reference ForceIndex();
def volH = reference PolarizedFractalEfficiency();
def volD = reference PositiveVolumeIndex();
def volN = reference ATR ();
def volR = reference ForceIndex ();
def volK = tick_count;
DEF volL = CTTC;
def volZ = volume;
input TimePeriod = 21;
#input SmoothLen = 21;
#input SmoothLenX = 21;
#input SmoothLenH = 21;
#def data = if !IsNaN((vol+volA+volx)*volume) then ((vol+volA+volx)*volume) else ((vol+volA+volx)*volume);
#def data = if !IsNaN((vol+volA+volx)) then ((vol+volA+volx)) else ((vol+volA+volx));
#def data = if !IsNaN((vol+volx)) then ((vol+volx)) else ((vol+volx));
#def data = if !IsNaN((vol+volj)*volume) then ((vol+volj)*volume) else ((vol+volj)*volume);
#def data = if !IsNaN((vol+volj)) then ((vol+volj)) else ((vol+volj));
#def data = if !IsNaN((vol+volu)) then ((vol+volu)) else ((vol+volu));
#def data = if !IsNaN((vol+volt)) then ((vol+volt)) else ((vol+volt));
#def data = if !IsNaN((vol+voly+volm)) then ((vol+voly+volm)) else ((vol+voly+volm));
#def data = if !IsNaN((volw+vol+voly)) then ((volw+vol+voly)) else ((volw+vol+voly));
#def data = if !IsNaN((volw+voly)) then ((volw+voly)) else ((volw+voly)); #Good
#def data = if !IsNaN((volw+vols)) then ((volw+vols)) else ((volw+vols));
#def data = if !IsNaN((volw+vols)) then ((volw+vols)) else ((volw+vols));
#def data = if !IsNaN((vol+volr)) then ((vol+volr)) else ((vol+volr));
#def data = if !IsNaN((vol+volr+volh)) then ((vol+volr+volh)) else ((vol+volr+volh));
#def data = if !IsNaN((vol+volh)) then ((vol+volh)) else ((vol+volh));
#def dataX = if !IsNaN((vol+voly+volj+volr+rsi)) then ((vol+voly+volj+volr+rsi)) else ((vol+voly+volj+volr+rsi));
#def dataX = if !IsNaN((vol+voly+volw+vold)) then ((vol+voly+volw+vold)) else ((vol+voly+volw+vold));
#def dataX = if !IsNaN((vol+volw+vold)) then ((vol+volw+vold)) else ((vol+volw+vold));
#def dataX = if !IsNaN((volw+vold)) then ((volw+vold)) else ((volw+vold)); #Good
#def data = if !IsNaN((vol+voly+volr)) then ((vol+voly+volr)) else ((vol+voly+volr));
#def data = if !IsNaN((voly+volr)) then ((voly+volr)) else ((voly+volr));
#def data = if !IsNaN((volr)) then ((volr)) else ((volr));
#def dataX = if !IsNaN((volw+vold+voly)) then ((volw+vold+voly)) else ((volw+vold+voly)); #good
#def dataX = if !IsNaN(WMA(volw+vold+voly)) then (WMA(volw+vold+voly)) else (WMA(volw+vold+voly));
#def dataX = if !IsNaN(TEMA(vol+voly+voln)) then (TEMA(vol+voly+voln)) else (TEMA(vol+voly+voln));
#def dataX = if !IsNaN(WMA(vol+voly+voln)) then (TEMA(vol+voly+voln)) else (TEMA(vol+voly+voln));
#def dataX = if !IsNaN((vol+voly)) then ((vol+voly)) else ((vol+voly));
#def dataX = if !IsNaN(HullMovingAvg(volw+vold+voly)) then (HullMovingAvg(volw+vold+voly)) else (HullMovingAvg(volw+vold+voly));
#def dataX = if !IsNaN(ExpAverage(volw+vold+voly)) then (ExpAverage(volw+vold+voly)) else (ExpAverage(volw+vold+voly));
#def dataX = if !IsNaN(TEMA(vol+voly+volk+voln)) then (TEMA(vol+voly+volk+voln)) else (TEMA(vol+voly+volk+voln));
#def dataX = if !IsNaN(TEMA(vol+voly+volz+volw+vold)) then (TEMA(vol+voly+volz+volw+vold)) else (TEMA(vol+voly+volz+volw+vold)); #INTERESTING
#def dataX = if !IsNaN(TEMA(vol+voly+volw+vold)) then (TEMA(vol+voly+volw+vold)) else (TEMA(vol+voly+volw+vold));
#def dataX = if !IsNaN(TEMA(vol+voly+volw+vold)) then (TEMA(vol+voly+volw+vold)) else (TEMA(vol+voly+volw+vold));
#def dataX = if !IsNaN(WMA(vol + volY + volZ + volW + volD + volL + volR)) then (WMA(vol + volY + volZ + volW + volD + volL + volR)) else (WMA(vol + volY + volZ + volW + volD + volL + volR)); #INTERESTING
def dataX = if !IsNaN(TEMA(vol + volY + volZ + volW + volD + volL + volR)) then (TEMA(vol + volY + volZ + volW + volD + volL + volR)) else (TEMA(vol + volY + volZ + volW + volD + volL + volR)); #INTERESTING
def hi = Highest(dataX, TimePeriod);
def lo = Lowest(dataX, TimePeriod);
#plot Percentile = (HullMovingAvg((datax - lo) / (hi - lo)) * 100);
#plot PercentileR = ((TEMA((datax - lo) / (hi - lo)) * voln) * 100);
#plot PercentileR = ((TEMA((datax - lo) / (hi - lo))* voln) * 100);
#plot PercentileQ = TEMA(((datax - lo) / (hi - lo)) * 100) + RSI;
plot PercentileQ = TEMA((((dataX - lo) / (hi - lo)) * 100) + (RSI + Inertia));#Interesting
#plot PercentileQ = TEMA(((datax - lo) / (hi - lo)) * 100);
#plot PercentileQ = ((WMA((datax - lo) / (hi - lo))) * 100) + RSI;
#plot PercentileQ = ((((datax - lo) / (hi - lo))) * 100);
#plot PercentileQ = ((TEMA((datax - lo) / (hi - lo)) * vola) * 100);
#plot PercentileQ = TEMA(((datax - lo) / (hi - lo)) * 100);
#plot PercentileQ = WMA(((dataX - lo) / (hi - lo))) * 100;
#plot PercentileQ = ExpAverage(((datax - lo) / (hi - lo)) * 100);
plot Mimic = PercentileQ [1];
input Dynlength = 21;
input Regulator = 1.130504;
#Plot DynUp = Average(PercentileQ,Dynlenght) + (1*StDev(PercentileQ,Dynlenght));
#Plot DynBot = Average(PercentileQ,Dynlenght) - (1*StDev(PercentileQ,Dynlenght));
plot DynUp = WMA(PercentileQ, Dynlength) + (Regulator * StDev(PercentileQ, Dynlength));
plot DynBot = WMA(PercentileQ, Dynlength) - (Regulator * StDev(PercentileQ, Dynlength));
input PerR = 31;
plot RSignal = WMA(PercentileQ, PerR);
#plot RSignal = TEMA(percentileQ, PerR);
#plot RSignal = ExpAverage(percentileQ, PerR);
#plot Cero = 0;
plot Fity = 50;
plot Cien = 100;
plot OneFity = 150;
Last edited by a moderator: