# Indicator for TOS
#//Massive thank you to LEGION, LazyBear, xSilas, Ni6HTH4wK, sco77m4r7and, SNOW_CITY, oh92,
#//... alexgrover, cI8DH, DonovanWall and shtcoinr for doing the initial builds, building
#//... indicators that I incorporated into this script or just generally giving me a hand
#//... when needed.
#tag0 = "Godmode"
#study(tag0 + " 4.0.2", tag0 + " Supply/Demand", true)
# Converted by Sam4Cok@Samer800 - 10/2024
input Benchmark = "SPY"; #("CRYPTOCAP:BTC", "Benchmark", string)
input Source = FundamentalType.HLC3; #, "Source")
input ChannelLength = 9; #, "Channel Length")
input AverageLength = 26; #, "Average Length")
input ShortLength = 13; #, "Short length")
input Count = 5; #, "Count")
input Smoothing = no; #(false, "Smoothing")
def na = Double.NaN;
def last = IsNaN(close);
def cond = Benchmark == GetSymbol();
def len0 = ChannelLength;
def len1 = AverageLength;
def len2 = ShortLength;
#//Engine
def src1 = Fundamental(FundamentalType = Source, Symbol = Benchmark);
script csi {
input _src = hlc3;
input len0 = 9;
input len1 = 26;
input len2 = 13;
def nRSI = RSI(Price = _src, Length = len2);
def avg = (_src + _src[1]) / 2;
def change = _src - _src[1];
def pc = change / avg;
def ma0 = ExpAverage(pc, len0);
def ma1 = ExpAverage(ma0, len1);
def apc = AbsValue(_src - _src[1]);
def ma2 = ExpAverage(apc, len0);
def ma3 = ExpAverage(ma2, len1);
def ttsi = 100 * (ma1 / ma3) * 50 + 50;
def csi = (nRSI + ttsi) / 2;
plot out = csi;
}
script tci {
input _src = hlc3;
input len0 = 9;
input len1 = 26;
def ema1 = ExpAverage(_src, len0);
def diff = _src - ema1;
def ema2 = ExpAverage(AbsValue(diff), len0);
def tci1 = (diff) / (0.025 * ema2);
def tci = ExpAverage(tci1, len1) + 50;
plot out = tci;
}
script mf {
input _src = hlc3;
input len2 = 13;
def change = _src - _src[1];
def sum1 = Sum(volume * (if change <= 0 then 0 else _src), len2);
def sum2 = sum(volume * (if change >= 0 then 0 else _src), len2);
def diff = sum1 - sum2;
def mf = RSI(Price = diff, Length = len2);
plot out = mf;
}
script willy {
input _src = hlc3;
input len1 = 26;
def hh = Highest(_src, len1);
def ll = Lowest(_src, len1);
def willy = 60 * (_src - hh) / (hh - ll) + 80;
plot out = willy;
}
def nRSI = RSI(Price = src1, Length = len2);
def tci = tci(src1, len0, len1);
def csi = CSI(src1, len0, len1, len2);
def mf = mf(src1, len2);
def willy = willy(src1, len1);
def tradition = (tci + nRSI + mf) / 3;
def godmode = (tci + csi + mf + willy) / 4;
def wt0 = if !cond then godmode else tradition;
def swt0 = Average(wt0, len0);
def gm = if Smoothing then swt0 else wt0;
def incrementer_up = if gm > 70 then 1 else 0;
def incrementer_both = if gm > 70 or gm < 30 then 1 else 0;
def incrementer_down = if gm < 30 then 1 else 0;
def gr = if incrementer_up then gr[1] + incrementer_up else 0;
def grH1 = if (gr >= Count) then high else grH1[1];
def grL1 = if (gr >= Count) then low else grL1[1];
def grh = if grH1 then grH1 else grH[1];
def grl = if grL1 then grL1 else grL[1];
def gs = if incrementer_down then gs[1] + incrementer_down else 0;
def gsH1 = if (gs >= Count) then high else gsH1[1];
def gsL1 = if (gs >= Count) then low else gsL1[1];
def gsh = if gsH1 then gsH1 else gsH[1];
def gsl = if gsL1 then gsL1 else gsL[1];
def gsdx = if incrementer_both then gsdx[1] + incrementer_both else 0;
def gsdH1 = if (gsdx >= Count) then high else gsdH1[1];
def gsdL1 = if (gsdx >= Count) then low else gsdL1[1];
def gsdh = if gsdH1 then gsdH1 else gsdH[1];
def gsdl = if gsdL1 then gsdL1 else gsdL[1];
#/Chassis
plot p1 = if gsh and gsh==gsh[1] then gsh else na; #, "High Support", lime, 1, circles)
plot p2 = if gsl and gsl==gsl[1] then gsl else na; #, "Low Support", green, 1, circles)
plot p3 = if grh and grh==grh[1] then grh else na; #, "High Resistance", red, 1, circles)
plot p4 = if grl and grl==grl[1] then grl else na ;#, "Low Resistance", fuchsia, 1, circles)
def p5 = if gsdh and gsdh==gsdh[1] then gsdh else na; #, "High Supply Above/Demand Below", orange, 1, circles)
def p6 = if gsdl and gsdl== gsdl[1] then gsdl else na; #, "Low Supply Above/Demand Below", yellow, 1, circles)
p1.SetDefaultColor(Color.DARK_GREEN);
p2.SetDefaultColor(Color.GREEN);
p3.SetDefaultColor(Color.RED);
p4.SetDefaultColor(Color.DARK_RED);
p1.SetPaintingStrategy(PaintingStrategy.HoRIZONTAL);
p2.SetPaintingStrategy(PaintingStrategy.HoRIZONTAL);
p3.SetPaintingStrategy(PaintingStrategy.HoRIZONTAL);
p4.SetPaintingStrategy(PaintingStrategy.HoRIZONTAL);
AddCloud(p1, p2, Color.DARK_GREEN);
AddCloud(p3, p4, Color.DARK_RED);
AddCloud(p5, p6, Color.GRAY);
# End of CODE