LastKnightofHonor
New member
could you provide the URL, i guess thinkscript just needs that nowCan we get this supply and demand indicator? Like the one in the video I just posted below. Thanks
could you provide the URL, i guess thinkscript just needs that nowCan we get this supply and demand indicator? Like the one in the video I just posted below. Thanks
https://usethinkscript.com/threads/supply-and-demand-for-thinkorswim.376/#post-2342could you provide the URL, i guess thinkscript just needs that now
# Supply and Demand Zones Support and Resistance
# Mobius
# V01.01.2020
# Study plots Demand Zone Support area (cyan), Supply Zone Area (pink) and Over Head Resistance (orange)
input n = 5;
input DemandIndexValue = 0.35;
def h = high;
def l = low;
def c = close;
def v = volume;
def x = barNumber();
def nan = double.nan;
def wC = (h + l + 2 * c) * 0.25;
def wCR = (wC - wC[1]) / Min(wC, wC[1]);
def cR = 3 * wC / Average(Highest(h, 2) - Lowest(l, 2), n) * AbsValue(wCR);
def vR = V / Average(V, n);
def vPerC = vR / exp(Min(88, cR));
def atr = average(trueRange(h,c,l),n)*1.5;
def buyP;
def sellP;
if (wCR > 0) {
buyP = vR;
sellP = vPerC;
} else {
buyP = vPerC;
sellP = vR;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (n - 1)) + buyP) / n;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (n - 1)) + sellP) / n;
def DI;
if ((((sellPres[1] * (n - 1)) + sellP) / n - ((buyPres[1] * (n - 1)) + buyP) / n) > 0)
{
DI = - if (sellPres != 0) then buyPres / sellPres else 1;
}
else
{
DI = if (buyPres != 0) then sellPres / buyPres else 1;
}
def DMI = if IsNaN(c) then nan else if DI < 0 then -1 - DI else 1 - DI;
def DemandL = if DMI crosses below -DemandIndexValue
then l
else if DMI < -.2 and l < DemandL[1]
then l
else DemandL[1];
def DemandH = if l == DemandL
then h
else DemandH[1];
def DemandX = if l == DemandL
then x
else DemandX[1];
plot DL = if x >= highestAll(DemandX)
then highestAll(if isNaN(c[-1])
then DemandL
else nan)
else nan;
DL.SetStyle(Curve.Firm);
DL.SetLineWeight(2);
DL.SetDefaultColor(Color.Cyan);
plot DH = if x >= highestAll(DemandX)
then highestAll(if isNaN(c[-1])
then DemandH
else nan)
else nan;
DH.SetStyle(Curve.Firm);
DH.SetLineWeight(2);
DH.SetDefaultColor(Color.Cyan);
addCloud(DH, DL, Color.Cyan);
def SupplyH = if DMI crosses above DemandIndexValue
then h
else if DMI > .5 and h > SupplyH[1]
then H
else SupplyH[1];
def SupplyL = if H == SupplyH
then l
else SupplyL[1];
def SupplyX = if h == SupplyH
then x
else SupplyX[1];
plot SH = if x >= highestAll(SupplyX)
then highestAll(if isNaN(c[-1])
then SupplyH
else nan)
else nan;
SH.SetStyle(Curve.Firm);
SH.SetLineWeight(2);
SH.SetDefaultColor(Color.Pink);
plot SL = if x >= highestAll(SupplyX)
then highestAll(if isNaN(c[-1])
then SupplyL
else nan)
else nan;
SL.SetStyle(Curve.Firm);
SL.SetLineWeight(2);
SL.SetDefaultColor(Color.Pink);
addCloud(SH, SL, Color.Pink);
def res = if c crosses above SH
then atr
else res[1];
plot RL = if x >= highestAll(SupplyX)
then highestAll(if isNaN(c[-1])
then SH + res
else nan)
else nan;
RL.SetStyle(Curve.Firm);
RL.SetLineWeight(1);
RL.SetDefaultColor(Color.Orange);
plot RH = if x >= highestAll(SupplyX)
then highestAll(if isNaN(c[-1])
then RL + res
else nan)
else nan;
RH.SetStyle(Curve.Firm);
RH.SetLineWeight(1);
RH.SetDefaultColor(Color.Orange);
addCloud(RH, RL, Color.Light_Orange);
# End Code
Mobius's Supply & Demand is NOT Supply & Demand. Supply & Demand uses volume.Hey guys, I found this thinkscript created by Mobius on Reddit for a supply and demand zone. When I uploaded it, it only shows me the demand zones and I wondering if it can also show the support zones. The link is http://tos.mx/ZBJQ2Ln
## SupplyDemandCompositeVer2_2
## START CODE
## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from
## Thinkorswim ZigZagSign Script
##8.24.13 Mod by Lar to add Supply/Demand Levels (Red Zones are Supply, Green are Demand), ability to enter percentage, amount or atr for reversalAmount (using the greater of the three at any reversal)
##2.20.14 Mod by Linus to hide non-active Supply/Demand Levels.
##2.20.14 Mods by Linus to remove everything but Supply/Demand levels and arrows.
##3.04.14 Mods by Linus to change Supply/Demand levels to start at arrows. (Ver2.1)
##3.12.14 Mods by Linus to fix first Supply/Demand levels to not start at Zero. (Ver2.2)
##6.4.14 Mods by Lar using some of Linus changes to allow showing just today's fibs and to show only a user selectable number of fib extension changes within the chart, along with their applicable bubbles (and b = number of spaces to move bubbles in expansion)
def price = close;
def priceH = high; # swing high
def priceL = low; # swing low
input ATRreversalfactor = 3.0;#Hint ATRreversalfactor: 3 is standard, adjust to whatever instrument/timeframe you are trading.
input ATRlength = 5;#Hint ATRlength: 5 is standard, adjust to whatever instrument/timeframe you are trading
input zigzagpercent = 3.0;#LAR original is 0.2, but modified in testing for 4h charting (may modify further later)
input zigzagamount = .15;
def ATR = reference ATR(length = ATRlength);
def reversalAmount = if (close * zigzagpercent / 100) > Max
(zigzagamount < ATRreversalfactor * ATR, zigzagamount) then
(close * zigzagpercent / 100) else if zigzagamount < ATRreversalfactor * ATR then
ATRreversalfactor * ATR else zigzagamount;
input showSupplyDemand = {Off, default Arrow, Pivot};
input showArrows = no; #orignal by LAR was no
input useAlerts = no; #orignal by LAR was no
#Original TOS ZigZag code Modified by Linus
def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));
rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;
if (GetValue(state, 1) == GetValue(state.init, 0)) {
minMaxPrice = price;
state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
state = state.downtrend;
minMaxPrice = priceL;
} else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
state = state.uptrend;
minMaxPrice = priceH;
} else {
state = state.undefined;
minMaxPrice = GetValue(minMaxPrice, 1);
}
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
state = state.downtrend;
minMaxPrice = priceL;
} else {
state = state.uptrend;
minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
}
} else {
if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
state = state.uptrend;
minMaxPrice = priceH;
} else {
state = state.downtrend;
minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
}
}
def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth = barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with
lastPeriodBarAcc = 1
while lastPeriodBarAcc > 0
do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
then -lastPeriodBarAcc
else lastPeriodBarAcc + 1;
} else {
tmpLastPeriodBar = 0;
}
} else {
tmpLastPeriodBar = Double.NaN;
}
def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue
(tmpLastPeriodBar) else -futureDepth;
rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
currentPriceLevel =
fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc
= minMaxPrice
do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice,
barWithMaxOnPeriodI));
currentPoints =
fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc =
Double.NaN
while IsNaN(maxPointOnPeriodAcc)
do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
then maxPointOnPeriodI
else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
currentPriceLevel =
fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc
= minMaxPrice
do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice,
barWithMinOnPeriodI));
currentPoints =
fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc =
Double.NaN
while IsNaN(minPointOnPeriodAcc)
do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
then minPointOnPeriodI
else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state ==
state.downtrend)) {
currentPriceLevel = GetValue(currentPriceLevel, 1);
currentPoints = GetValue(currentPoints, 1) + 1;
} else {
currentPoints = 1;
currentPriceLevel = GetValue(price, currentPoints);
}
plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state ==
state.uptrend then priceH else priceL else if (currentPoints == 0) then
currentPriceLevel else Double.NaN;
rec zzSave = if !IsNaN("ZZ$") then if (barNumber == barCount or barNumber == 1)
then if IsNaN(barNumber[-1]) and state == state.uptrend then priceH else priceL
else currentPriceLevel else GetValue(zzSave, 1);
def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if
barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel)
- GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and
GetValue(isConf, 1));
"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.GREEN);
"ZZ$".DefineColor("Down Trend", Color.RED);
"ZZ$".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined") else if isUp
then "ZZ$".Color("Up Trend") else "ZZ$".Color("Down Trend"));
"ZZ$".SetLineWeight(2);
DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
#Showlabel for Confirmed/Unconfirmed Status of Current Zigzag
input show_unconfirmed_label = no;
AddLabel(show_unconfirmed_label and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
#Arrows
def zzL = if !IsNaN("ZZ$") and state == state.downtrend then priceL else
GetValue(zzL, 1);
def zzH = if !IsNaN("ZZ$") and state == state.uptrend then priceH else GetValue
(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] then 1 else if zzH != zzH[1] then -1
else dir[1], 0);
def signal = CompoundValue(1,
if dir > 0 and low > zzL then
if signal[1] <= 0 then 1 else signal[1]
else if dir < 0 and high < zzH then
if signal[1] >= 0 then -1 else signal[1]
else signal[1]
, 0);
plot U1 = showArrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showArrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);
Alert(useAlerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(useAlerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;
if BarNumber() == 1 {
rLow = Double.NaN;
rHigh = Double.NaN;
} else if signal crosses 0 {
rLow = low[idx];
rHigh = high[idx];
} else {
rLow = rLow[1];
rHigh = rHigh[1];
}
plot HighLine = if showSupplyDemand and !IsNaN(close) then rHigh else
Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);
HighLine.HideBubble();
plot LowLine = if showSupplyDemand and !IsNaN(close) then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);
LowLine.HideBubble();
def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;
AddCloud(hlUp, LowLine, Color.GREEN, Color.GREEN);
AddCloud(hlDn, LowLine, Color.RED, Color.RED);
#Store Previous Data
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
rec priorzz1 = if zzsave2 != zzsave2[1] then zzsave2[1] else priorzz1[1];
rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];
rec priorzz4 = if priorzz3 != priorzz3[1] then priorzz3[1] else priorzz4[1];
rec priorzz5 = if priorzz4 != priorzz4[1] then priorzz4[1] else priorzz5[1];
rec priorzz6 = if priorzz5 != priorzz5[1] then priorzz5[1] else priorzz6[1];
rec data = CompoundValue(1, if (zzSave == priceH or zzSave == priceL) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
input numberextfibstoshow = 2;
input showFibExtLines = yes;
input showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 1
else extfib1[1];
plot extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib1) and dir < 0 then extfib1[1] else Double.NaN;
extfib100.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100.SetDefaultColor(Color.RED);
extfib100.SetLineWeight(1);
extfib100.HideBubble();
def extfib2 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2[1];
plot extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib2) and dir < 0 then extfib2[1] else Double.NaN;
extfib618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618.SetDefaultColor(Color.RED);
extfib618.SetLineWeight(1);
extfib618.HideBubble();
def extfib3 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3[1];
plot extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib3) and dir < 0 then extfib3[1] else Double.NaN;
extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618.SetDefaultColor(Color.RED);
extfib1618.SetLineWeight(1);
extfib1618.HideBubble();
def extfib4 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4[1];
plot extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib4) and dir < 0 then extfib4[1] else Double.NaN;
extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618.SetDefaultColor(Color.RED);
extfib2618.SetLineWeight(1);
extfib2618.HideBubble();
def extfib1_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 1
else extfib1_[1];
plot extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib1_) and dir > 0 then extfib1_[1] else Double.NaN;
extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100_.SetDefaultColor(Color.GREEN);
extfib100_.SetLineWeight(1);
extfib100_.HideBubble();
def extfib2_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2_[1];
plot extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib2_) and dir > 0 then extfib2_[1] else Double.NaN;
extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618_.SetDefaultColor(Color.GREEN);
extfib618_.SetLineWeight(1);
extfib618_.HideBubble();
def extfib3_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3_[1];
plot extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib3_) and dir > 0 then extfib3_[1] else Double.NaN;
extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618_.SetDefaultColor(Color.GREEN);
extfib1618_.SetLineWeight(1);
extfib1618_.HideBubble();
def extfib4_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4_[1];
plot extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib4_) and dir > 0 then extfib4_[1] else Double.NaN;
extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618_.SetDefaultColor(Color.GREEN);
extfib2618_.SetLineWeight(1);
extfib2618_.HideBubble();
input b = 2;
def direction = if !isUp then 1 else 0;
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1[b + 2], "100%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2[b + 2], "61.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3[b + 2], "161.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4[b + 2], "261.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1_[b + 2], "100%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2_[b + 2], "61.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3_[b + 2], "161.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4_[b + 2], "261.8%", Color.GREEN, yes);
input showlabel_fibext = yes;
AddLabel(showlabel_fibext, "Fib Ext ", Color.YELLOW);
AddLabel( direction == 1 and showlabel_fibext , "0% " + AsText(priorzz1), Color.RED);
AddLabel( direction == 1 and showlabel_fibext , "61.8% " + AsText(extfib2), Color.RED);
AddLabel( direction == 1 and showlabel_fibext , "100% " + AsText(extfib1), Color.RED);
AddLabel( direction == 1 and showlabel_fibext , "161.8% " + AsText(extfib3) , Color.RED);
AddLabel( direction == 1 and showlabel_fibext , "261.8% " + AsText(extfib4), Color.RED);
AddLabel( direction == 0 and showlabel_fibext , "0% " + AsText(priorzz1), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibext , "61.8% " + AsText(extfib2_[1]), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibext , "100% " + AsText(extfib1_[1]), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibext , "161.8% " + AsText(extfib3_[1]) , Color.GREEN);
AddLabel( direction == 0 and showlabel_fibext , "261.8% " + AsText(extfib4_[1]), Color.GREEN);
def fib_range = AbsValue(priorzz2 - priorzz1) ;
def fib1_0 = priorzz1 + fib_range * .236;
def fib2_0 = priorzz1 + fib_range * .382;
def fib3_0 = priorzz1 + fib_range * .500;
def fib4_0 = priorzz1 + fib_range * .618;
def fib5_0 = priorzz1 + fib_range * .764;
def fib6_0 = priorzz1;
def fib1_1 = priorzz1 - fib_range * .236;
def fib2_1 = priorzz1 - fib_range * .382;
def fib3_1 = priorzz1 - fib_range * .500;
def fib4_1 = priorzz1 - fib_range * .618;
def fib5_1 = priorzz1 - fib_range * .764;
def fib6_1 = priorzz1;
input showlabel_fibretrace = yes;
AddLabel(showlabel_fibretrace, "Fib Retrace ", Color.YELLOW);
AddLabel( direction == 0 and showlabel_fibretrace , "0% " + AsText(fib6_0), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibretrace , "23.6% " + AsText(fib1_0), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibretrace , "38.2% " + AsText(fib2_0), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibretrace , "50% " + AsText(fib3_0), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibretrace , "61.8% " + AsText(fib4_0), Color.GREEN);
AddLabel( direction == 0 and showlabel_fibretrace , "76.4 " + AsText(fib5_0), Color.GREEN);
AddLabel( direction == 1 and showlabel_fibretrace , "0% " + AsText(fib6_1), Color.RED);
AddLabel( direction == 1 and showlabel_fibretrace , "23.6% " + AsText(fib1_1), Color.RED);
AddLabel( direction == 1 and showlabel_fibretrace , "38.2% " + AsText(fib2_1), Color.RED);
AddLabel( direction == 1 and showlabel_fibretrace , "50% " + AsText(fib3_1), Color.RED);
AddLabel( direction == 1 and showlabel_fibretrace , "61.8% " + AsText(fib4_1), Color.RED);
AddLabel( direction == 1 and showlabel_fibretrace , "76.4 " + AsText(fib5_1), Color.RED);
No that is not possible. There is no way to get the historic plots with the above indicators. Besides almost all Supply / Demand indicators repaint.Your right it does work...I asked the wrong question...it is possible I can change the dates that it shows the zones on? Right now, I only see it on the most recent dates...but I was trying to do backtesting with it so I can see the accuracy..
How to scan the arrows? Does this indicator repaint? Thank you@mini What's wrong with the once we have here though?
there are plenty on that topic, try our the existing once and see what matches close to what's described in the video.
Ruby:## SupplyDemandCompositeVer2_2 ## START CODE ## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from ## Thinkorswim ZigZagSign Script ##8.24.13 Mod by Lar to add Supply/Demand Levels (Red Zones are Supply, Green are Demand), ability to enter percentage, amount or atr for reversalAmount (using the greater of the three at any reversal) ##2.20.14 Mod by Linus to hide non-active Supply/Demand Levels. ##2.20.14 Mods by Linus to remove everything but Supply/Demand levels and arrows. ##3.04.14 Mods by Linus to change Supply/Demand levels to start at arrows. (Ver2.1) ##3.12.14 Mods by Linus to fix first Supply/Demand levels to not start at Zero. (Ver2.2) ##6.4.14 Mods by Lar using some of Linus changes to allow showing just today's fibs and to show only a user selectable number of fib extension changes within the chart, along with their applicable bubbles (and b = number of spaces to move bubbles in expansion) def price = close; def priceH = high; # swing high def priceL = low; # swing low input ATRreversalfactor = 3.0;#Hint ATRreversalfactor: 3 is standard, adjust to whatever instrument/timeframe you are trading. input ATRlength = 5;#Hint ATRlength: 5 is standard, adjust to whatever instrument/timeframe you are trading input zigzagpercent = 3.0;#LAR original is 0.2, but modified in testing for 4h charting (may modify further later) input zigzagamount = .15; def ATR = reference ATR(length = ATRlength); def reversalAmount = if (close * zigzagpercent / 100) > Max (zigzagamount < ATRreversalfactor * ATR, zigzagamount) then (close * zigzagpercent / 100) else if zigzagamount < ATRreversalfactor * ATR then ATRreversalfactor * ATR else zigzagamount; input showSupplyDemand = {Off, default Arrow, Pivot}; input showArrows = no; #orignal by LAR was no input useAlerts = no; #orignal by LAR was no #Original TOS ZigZag code Modified by Linus def barNumber = BarNumber(); def barCount = HighestAll(If(IsNaN(price), 0, barNumber)); rec state = {default init, undefined, uptrend, downtrend}; rec minMaxPrice; if (GetValue(state, 1) == GetValue(state.init, 0)) { minMaxPrice = price; state = state.undefined; } else if (GetValue(state, 1) == GetValue(state.undefined, 0)) { if (price <= GetValue(minMaxPrice, 1) - reversalAmount) { state = state.downtrend; minMaxPrice = priceL; } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) { state = state.uptrend; minMaxPrice = priceH; } else { state = state.undefined; minMaxPrice = GetValue(minMaxPrice, 1); } } else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) { if (price <= GetValue(minMaxPrice, 1) - reversalAmount) { state = state.downtrend; minMaxPrice = priceL; } else { state = state.uptrend; minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1)); } } else { if (price >= GetValue(minMaxPrice, 1) + reversalAmount) { state = state.uptrend; minMaxPrice = priceH; } else { state = state.downtrend; minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1)); } } def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1; def futureDepth = barCount - barNumber; def tmpLastPeriodBar; if (isCalculated) { if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) { tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1 while lastPeriodBarAcc > 0 do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI)) then -lastPeriodBarAcc else lastPeriodBarAcc + 1; } else { tmpLastPeriodBar = 0; } } else { tmpLastPeriodBar = Double.NaN; } def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue (tmpLastPeriodBar) else -futureDepth; rec currentPriceLevel; rec currentPoints; if (state == state.uptrend and isCalculated) { currentPriceLevel = fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI)); currentPoints = fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN while IsNaN(maxPointOnPeriodAcc) do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel) then maxPointOnPeriodI else maxPointOnPeriodAcc; } else if (state == state.downtrend and isCalculated) { currentPriceLevel = fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI)); currentPoints = fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN while IsNaN(minPointOnPeriodAcc) do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel) then minPointOnPeriodI else minPointOnPeriodAcc; } else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) { currentPriceLevel = GetValue(currentPriceLevel, 1); currentPoints = GetValue(currentPoints, 1) + 1; } else { currentPoints = 1; currentPriceLevel = GetValue(price, currentPoints); } plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN; rec zzSave = if !IsNaN("ZZ$") then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1); def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1); def isUp = chg >= 0; rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1)); "ZZ$".EnableApproximation(); "ZZ$".DefineColor("Up Trend", Color.GREEN); "ZZ$".DefineColor("Down Trend", Color.RED); "ZZ$".DefineColor("Undefined", Color.DARK_ORANGE); "ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined") else if isUp then "ZZ$".Color("Up Trend") else "ZZ$".Color("Down Trend")); "ZZ$".SetLineWeight(2); DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE); DefineGlobalColor("Up", Color.GREEN); DefineGlobalColor("Down", Color.RED); #Showlabel for Confirmed/Unconfirmed Status of Current Zigzag input show_unconfirmed_label = no; AddLabel(show_unconfirmed_label and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down")); #Arrows def zzL = if !IsNaN("ZZ$") and state == state.downtrend then priceL else GetValue(zzL, 1); def zzH = if !IsNaN("ZZ$") and state == state.uptrend then priceH else GetValue (zzH, 1); def dir = CompoundValue(1, if zzL != zzL[1] then 1 else if zzH != zzH[1] then -1 else dir[1], 0); def signal = CompoundValue(1, if dir > 0 and low > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and high < zzH then if signal[1] >= 0 then -1 else signal[1] else signal[1] , 0); plot U1 = showArrows and signal > 0 and signal[1] <= 0; U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); U1.SetDefaultColor(Color.GREEN); U1.SetLineWeight(4); plot D1 = showArrows and signal < 0 and signal[1] >= 0; D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); D1.SetDefaultColor(Color.RED); D1.SetLineWeight(4); Alert(useAlerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell); Alert(useAlerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes); #Supply Demand Areas def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0; def rLow; def rHigh; if BarNumber() == 1 { rLow = Double.NaN; rHigh = Double.NaN; } else if signal crosses 0 { rLow = low[idx]; rHigh = high[idx]; } else { rLow = rLow[1]; rHigh = rHigh[1]; } plot HighLine = if showSupplyDemand and !IsNaN(close) then rHigh else Double.NaN; HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED); HighLine.HideBubble(); plot LowLine = if showSupplyDemand and !IsNaN(close) then rLow else Double.NaN; LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED); LowLine.HideBubble(); def hlUp = if signal > 0 then HighLine else Double.NaN; def hlDn = if signal < 0 then HighLine else Double.NaN; AddCloud(hlUp, LowLine, Color.GREEN, Color.GREEN); AddCloud(hlDn, LowLine, Color.RED, Color.RED); #Store Previous Data def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1]; def zzsave2 = zzsave1; rec priorzz1 = if zzsave2 != zzsave2[1] then zzsave2[1] else priorzz1[1]; rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1]; rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1]; rec priorzz4 = if priorzz3 != priorzz3[1] then priorzz3[1] else priorzz4[1]; rec priorzz5 = if priorzz4 != priorzz4[1] then priorzz4[1] else priorzz5[1]; rec priorzz6 = if priorzz5 != priorzz5[1] then priorzz5[1] else priorzz6[1]; rec data = CompoundValue(1, if (zzSave == priceH or zzSave == priceL) then data[1] + 1 else data[1], 0); def datacount = (HighestAll(data) - data[1]); input numberextfibstoshow = 2; input showFibExtLines = yes; input showtodayonly = no; def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay(); def extfib1 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 1 else extfib1[1]; plot extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib1) and dir < 0 then extfib1[1] else Double.NaN; extfib100.SetPaintingStrategy(PaintingStrategy.DASHES); extfib100.SetDefaultColor(Color.RED); extfib100.SetLineWeight(1); extfib100.HideBubble(); def extfib2 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 0.618 else extfib2[1]; plot extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib2) and dir < 0 then extfib2[1] else Double.NaN; extfib618.SetPaintingStrategy(PaintingStrategy.DASHES); extfib618.SetDefaultColor(Color.RED); extfib618.SetLineWeight(1); extfib618.HideBubble(); def extfib3 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 1.618 else extfib3[1]; plot extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib3) and dir < 0 then extfib3[1] else Double.NaN; extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES); extfib1618.SetDefaultColor(Color.RED); extfib1618.SetLineWeight(1); extfib1618.HideBubble(); def extfib4 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 2.618 else extfib4[1]; plot extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib4) and dir < 0 then extfib4[1] else Double.NaN; extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES); extfib2618.SetDefaultColor(Color.RED); extfib2618.SetLineWeight(1); extfib2618.HideBubble(); def extfib1_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 1 else extfib1_[1]; plot extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib1_) and dir > 0 then extfib1_[1] else Double.NaN; extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES); extfib100_.SetDefaultColor(Color.GREEN); extfib100_.SetLineWeight(1); extfib100_.HideBubble(); def extfib2_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 0.618 else extfib2_[1]; plot extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib2_) and dir > 0 then extfib2_[1] else Double.NaN; extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES); extfib618_.SetDefaultColor(Color.GREEN); extfib618_.SetLineWeight(1); extfib618_.HideBubble(); def extfib3_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 1.618 else extfib3_[1]; plot extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib3_) and dir > 0 then extfib3_[1] else Double.NaN; extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES); extfib1618_.SetDefaultColor(Color.GREEN); extfib1618_.SetLineWeight(1); extfib1618_.HideBubble(); def extfib4_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 2.618 else extfib4_[1]; plot extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib4_) and dir > 0 then extfib4_[1] else Double.NaN; extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES); extfib2618_.SetDefaultColor(Color.GREEN); extfib2618_.SetLineWeight(1); extfib2618_.HideBubble(); input b = 2; def direction = if !isUp then 1 else 0; AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1[b + 2], "100%", Color.RED, no); AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2[b + 2], "61.8%", Color.RED, no); AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3[b + 2], "161.8%", Color.RED, no); AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4[b + 2], "261.8%", Color.RED, no); AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1_[b + 2], "100%", Color.GREEN, yes); AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2_[b + 2], "61.8%", Color.GREEN, yes); AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3_[b + 2], "161.8%", Color.GREEN, yes); AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4_[b + 2], "261.8%", Color.GREEN, yes); input showlabel_fibext = yes; AddLabel(showlabel_fibext, "Fib Ext ", Color.YELLOW); AddLabel( direction == 1 and showlabel_fibext , "0% " + AsText(priorzz1), Color.RED); AddLabel( direction == 1 and showlabel_fibext , "61.8% " + AsText(extfib2), Color.RED); AddLabel( direction == 1 and showlabel_fibext , "100% " + AsText(extfib1), Color.RED); AddLabel( direction == 1 and showlabel_fibext , "161.8% " + AsText(extfib3) , Color.RED); AddLabel( direction == 1 and showlabel_fibext , "261.8% " + AsText(extfib4), Color.RED); AddLabel( direction == 0 and showlabel_fibext , "0% " + AsText(priorzz1), Color.GREEN); AddLabel( direction == 0 and showlabel_fibext , "61.8% " + AsText(extfib2_[1]), Color.GREEN); AddLabel( direction == 0 and showlabel_fibext , "100% " + AsText(extfib1_[1]), Color.GREEN); AddLabel( direction == 0 and showlabel_fibext , "161.8% " + AsText(extfib3_[1]) , Color.GREEN); AddLabel( direction == 0 and showlabel_fibext , "261.8% " + AsText(extfib4_[1]), Color.GREEN); def fib_range = AbsValue(priorzz2 - priorzz1) ; def fib1_0 = priorzz1 + fib_range * .236; def fib2_0 = priorzz1 + fib_range * .382; def fib3_0 = priorzz1 + fib_range * .500; def fib4_0 = priorzz1 + fib_range * .618; def fib5_0 = priorzz1 + fib_range * .764; def fib6_0 = priorzz1; def fib1_1 = priorzz1 - fib_range * .236; def fib2_1 = priorzz1 - fib_range * .382; def fib3_1 = priorzz1 - fib_range * .500; def fib4_1 = priorzz1 - fib_range * .618; def fib5_1 = priorzz1 - fib_range * .764; def fib6_1 = priorzz1; input showlabel_fibretrace = yes; AddLabel(showlabel_fibretrace, "Fib Retrace ", Color.YELLOW); AddLabel( direction == 0 and showlabel_fibretrace , "0% " + AsText(fib6_0), Color.GREEN); AddLabel( direction == 0 and showlabel_fibretrace , "23.6% " + AsText(fib1_0), Color.GREEN); AddLabel( direction == 0 and showlabel_fibretrace , "38.2% " + AsText(fib2_0), Color.GREEN); AddLabel( direction == 0 and showlabel_fibretrace , "50% " + AsText(fib3_0), Color.GREEN); AddLabel( direction == 0 and showlabel_fibretrace , "61.8% " + AsText(fib4_0), Color.GREEN); AddLabel( direction == 0 and showlabel_fibretrace , "76.4 " + AsText(fib5_0), Color.GREEN); AddLabel( direction == 1 and showlabel_fibretrace , "0% " + AsText(fib6_1), Color.RED); AddLabel( direction == 1 and showlabel_fibretrace , "23.6% " + AsText(fib1_1), Color.RED); AddLabel( direction == 1 and showlabel_fibretrace , "38.2% " + AsText(fib2_1), Color.RED); AddLabel( direction == 1 and showlabel_fibretrace , "50% " + AsText(fib3_1), Color.RED); AddLabel( direction == 1 and showlabel_fibretrace , "61.8% " + AsText(fib4_1), Color.RED); AddLabel( direction == 1 and showlabel_fibretrace , "76.4 " + AsText(fib5_1), Color.RED);
There is one posed by @MerryDay
https://usethinkscript.com/threads/...port-and-resistance-by-mobius.9988/post-89553
I am sure you will find many more if you search for supply/demand in this forum.
No that is not possible. There is no way to get the historic plots with the above indicators. Besides almost all Supply / Demand indicators repaint.
Even if you had history. It would only be the repainted history.
They backtest with 100% perfection as all the false signals are erased.
They display where the support is at that moment. The price could fall through that support or it could bounce.
What support & resistance has going for it is: herd belief. As long as the institutional trading believes in the S&R, we are more likely to get the bounce precluding extrinsic factors.
Mobius this is great...I see that in start to create during consolidation...and today there was huge volume spike within the consolidation and later it became a resistance price. So can I ask if it possible for for it to plot a line within that zone when volume accumulates above the average volume at a certain price or place a chart bubble to indicate which price did the volume increase above normal.?Works fine for me. Here is the script from the top post:
![]()
I personally like our beloved Trend Pivot Indicator by Mobius For ThinkOrSwim better
https://usethinkscript.com/threads/trend-pivot-indicator-by-mobius-for-thinkorswim.1631/
![]()
There are no volume calculations in Mobius Trend Pivots. What you are looking for would be a new custom script. You would need to write out the very specific logic map. You need to quantify your variables, ie: spike is not a mathematical term. When you have all that:Mobius this is great...I see that in start to create during consolidation...and today there was huge volume spike within the consolidation and later it became a resistance price. So can I ask if it possible for for it to plot a line within that zone when volume accumulates above the average volume at a certain price or place a chart bubble to indicate which price did the volume increase above normal.?
@Mobius, can I assume correctly when I see that the color is green....that its a Demand Zone and when the color is red that its a Supply Zone?Works fine for me. Here is the script from the top post:
![]()
I personally like our beloved Trend Pivot Indicator by Mobius For ThinkOrSwim better
https://usethinkscript.com/threads/trend-pivot-indicator-by-mobius-for-thinkorswim.1631/
![]()
yes Green is support., look for a bounce. Red is resistance.@Mobius, can I assume correctly when I see that the color is green....that its a Demand Zone and when the color is red that its a Supply Zone?
Great...thank youyes Green is support., look for a bounce. Red is resistance.
Not really@Mobius, is there a way that I can have it not create a zone from the premarket numbers?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.