outthislife
Well-Known Member
here's the single line ADX and modified zlag:
adx
zlag
adx
Code:
declare lower;
declare once_per_bar;
input n = 14;
def gd_88 = high - high[1];
def gd_96 = low[1] - low;
def gda_104;
def gda_108;
# If price differences are equal or 0, set 104/108 to 0
if ((gd_88 < 0 and gd_96 < 0) or gd_88 == gd_96) then {
gda_104 = 0;
gda_108 = 0;
}
# Otherwise set 104 to the highs differentiation,
# and 108 to the lows differentiation
else {
gda_104 = if gd_88 > gd_96 then gd_88 else 0;
gda_108 = if gd_88 < gd_96 then gd_96 else 0;
}
# Calculations
# High differentation modification
def gda_112;
gda_112 = gda_112[1] * (n - 1.0) / n + gda_104 / n;
# Low differentation modification
def gda_116;
gda_116 = gda_116[1] * (n - 1.0) / n + gda_108 / n;
# Do some crazy calculations.
def gda_120;
gda_120 = Max(
Max(AbsValue(high - low), AbsValue(high - close[1])),
AbsValue(close[1] - low)
);
# No idea what this does.
def gda_124 = gda_124[1] * (n - 1.0) / n + gda_120 / n;
# Conditional work of some sort..?
def gda_128;
def gda_132;
def gda_136;
if (gda_124 > 0) then {
# Low and high %?
gda_128 = 100.0 * (gda_112 / gda_124);
gda_132 = 100.0 * (gda_116 / gda_124);
# Crazy calculations again...
gda_136 = if (gda_128 + gda_132) > 0 then 100.0 * (AbsValue(gda_128 - gda_132) / (gda_128 + gda_132)) else double.nan;
}
# Set to null if not applicable.
else {
gda_128 = double.nan;
gda_132 = double.nan;
gda_136 = double.nan;
}
def res = res[1] * (n - 1.0) / n + gda_136 / n;
def last = res[1];
# Plot it all
input high_point = 30;
input low_point = 15;
plot dx = res;
dx.setDefaultColor(color.green);
dx.assignValueColor(if dx <= 15 then color.dark_green else color.green);
addLabel(yes, "ADX="+dx);
def uhook = !(uhook[1] within n bars) and dx[1] >= high_point and dx < dx[1];
def dhook = !(dhook[1] within n bars) and dx[1] crosses above low_point and dx > low_point;
plot u_hook = if uhook then dx else double.nan;
#u_hook.setStyle(curve.points);
u_hook.setPaintingStrategy(paintingStrategy.HISTOGRAM);
u_hook.setDefaultColor(color.WHITE);
plot d_hook = if dhook then dx else double.nan;
#d_hook.setStyle(curve.points);
d_hook.setPaintingStrategy(paintingStrategy.HISTOGRAM);
d_hook.setDefaultColor(color.WHITE);
zlag
Code:
#TFP Zero Lag Moving Average Convergence Divergence (MACD)
input price = close;
input fastLength = 12;
input slowLength = 24;
input MACDLength = 9;
input BarsBack = 30;
input PlotLines = {default "NO", "YES"};
def EMAf = ExpAverage(price, fastLength);
def EMAs = ExpAverage(price, slowLength);
def EMAEMAf = ExpAverage(EMAf, fastLength);
def EMAEMAs = ExpAverage(EMAs, slowLength);
def ZLEMAf = EMAf + EMAf - EMAEMAf;
def ZLEMAs = EMAs + EMAs - EMAEMAs;
def TR = TRIX(9, 14, close, 3);
plot MACDValue = if PlotLines then (EMAf - EMAs) else Double.NaN;
plot SignalAvg = if PlotLines then ExpAverage(MACDValue, MACDLength) else Double.NaN;
plot Diff = ZLEMAf - ZLEMAs;
def ChartPeriod = GetAggregationPeriod() / 1000 / 60;
plot ZeroLine = 0;
ZeroLine.AssignValueColor(Color.GRAY);
plot DivergeTop = if
Diff > 0
and Diff < Diff[1]
and Diff[1] > Diff[2]
#and Diff[2]>Diff[3]
and Diff < Highest(Diff, BarsBack)
and Highest(price, 5) > Highest(price[6], BarsBack)
then Highest(Diff, BarsBack) else Double.NaN;
plot DivergeBottom = if
Diff < 0
and Diff > Diff[1]
and Diff[1] < Diff[2]
#and Diff[2]<Diff[3]
and Diff > Lowest(Diff, BarsBack)
and Lowest(price, 5) < Lowest(price[6], BarsBack)
then Lowest(Diff, BarsBack) else Double.NaN;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.GREEN);
Diff.DefineColor("Negative and Up", Color.DARK_GREEN);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));
DivergeTop.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DivergeTop.SetLineWeight(5);
DivergeTop.SetDefaultColor(Color.red);
DivergeBottom.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DivergeBottom.SetLineWeight(5);
DivergeBottom.SetDefaultColor(Color.red);
# Visual signals
AddLabel(yes, "MACD="+Diff);
def isSignal = !(isSignal[1] within MACDLength bars) and Diff crosses 0;
AddVerticalLine(isSignal, "", color.dark_green);
AssignPriceColor(if isSignal then color.red else color.current);