Per several member requests from here:
https://usethinkscript.com/threads/convert-tradingview-support-resistance-scripts.12101/
try this. - Updated
https://usethinkscript.com/threads/convert-tradingview-support-resistance-scripts.12101/
try this. - Updated
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © BarsStallone
#// Code update provided by @christofferka
#indicator("Support/Resistance", shorttitle="S/R", overlay=true, max_lines_count = 500)
#//Converted by Sam4Cok@Samer800 - 01/2023
# update by Sam4Cok@Samer800 - 02/2024
input timeframe = {Default "Chart", "Custom TF"};
input customeTimeframe = AggregationPeriod.FIFTEEN_MIN;
input showTfLabel = yes;
input showLastLines = yes;
input pivotLength = 2;
input rsiLength = 9;
input cmoLength = 1;
def na = Double.NaN;
def bar = BarNumber();
def chart = GetAggregationPeriod();
script tfLabel {
input chart = 300000;
def tf = if chart < AggregationPeriod.HOUR then chart / AggregationPeriod.MIN else
if chart < AggregationPeriod.DAY then chart / AggregationPeriod.HOUR else
if chart < AggregationPeriod.MONTH then chart / AggregationPeriod.DAY else chart / AggregationPeriod.MONTH;
def tfLab = if chart < AggregationPeriod.HOUR then 1 else
if chart < AggregationPeriod.DAY then 2 else
if chart < AggregationPeriod.MONTH then 3 else 4;
plot val = tf;
plot lab = tfLab;
}
def tf = tfLabel(chart).val;
def tfLab = tfLabel(chart).lab;
def htf = tfLabel(customeTimeframe).val;
def htfLab = tfLabel(customeTimeframe).lab;
script nz {
input data = close;
input repl = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
script fixnan {
input source = close;
def fix = if !IsNaN(source) then source else nz(fix[1],source);
plot result = fix;
}
def hi; def lo; def op; def cl;def val; def lab;
Switch (timeframe) {
Case "Custom TF" :
hi = high(period= customeTimeframe);
lo = low(period= customeTimeframe);
op = open(period= customeTimeframe);
cl = close(period= customeTimeframe);
val = htf;
lab = htfLab;
Default :
hi = high;
lo = low;
op = open;
cl = close;
val = tf;
lab = tfLab;
}
AddLabel(showTfLabel, val + if lab==1 then " m" else
if lab==2 then " H" else
if lab==3 then " D" else " M", Color.WHITE);
#//Legacy RSI calc
def rsi_new = rsi(Price = cl, Length = rsiLength);
#//CMO based on HMA
def length1 = cmoLength;
def src1 = HullMovingAvg(op, 5)[1];
def src2 = HullMovingAvg(cl, 12);
def momm1 = src1 - src1[1];
def momm2 = src2 - src2[1];
def m1 = if momm1 >= momm2 then momm1 else 0;
def m2 = if momm1 >= momm2 then 0 else -momm1;
def sm1 = Sum(m1, length1);
def sm2 = Sum(m2, length1);
def cmo1 = sm1 - sm2;
def cmo2 = sm1 + sm2;
def cmo_new = 100 * cmo1 / cmo2;
#//Legacy Close Pivots calcs.
def len5 = pivotLength;
def hh = Highest(hi, len5);
def h1 = if stdev(hh, len5) then na else hh;
def hpivot = fixnan(h1);
def ll = Lowest(lo , len5);
def l1 = if stdev(ll, len5) then na else ll;
def lpivot = fixnan(l1);
#//Calc Values
def hpivot_new = hpivot;
def lpivot_new = lpivot;
def res = rsi_new > 75 and cmo_new <-50 and !isNaN(hpivot_new);
def sup = rsi_new < 25 and cmo_new > 50 and !isNaN(lpivot_new);
def calcXupH = if sup then high else calcXupH[1];
def calcXupL = if sup then low else calcXupL[1];
def calcXdnH = if res then high else calcXdnH[1];
def calcXdnL = if res then low else calcXdnL[1];
def calcXupIdx = if sup then bar else calcXupIdx[1];
def calcXdnIdx = if res then bar else calcXdnIdx[1];
def condUp = if showLastLines then bar >= highestAll(calcXupIdx) else 1;
def condDn = if showLastLines then bar >= highestAll(calcXdnIdx) else 1;
#//Lines drawing variables
def tf1H = if calcXupH and condUp then calcXupH else na;
def tf1L = if calcXupL and condUp then calcXupL else na;
def tf2H = if calcXdnH and condDn then calcXdnH else na;
def tf2L = if calcXdnL and condDn then calcXdnL else na;
AddCloud(if tf1H==tf1H[1] then tf1H else na, tf1L, Color.DARK_GREEN, Color.DARK_GREEN, yes);
AddCloud(if tf2H==tf2H[1] then tf2H else na, tf2L, Color.DARK_RED, Color.DARK_RED, yes);
#---- END of Code
Last edited: