[blackcat] L1 Chop Zones for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
HNiT2WN.png


Author Message:
Background

Inspired by NILX's "Tool: Chop & Trade Zones". This can used as an element for trading system control.

Function

I use my own customized algorithm to replace that core of NILX one, which is targeting to provide smoother and trend for chop and trend judgement.
Since it is quite different now but an oscillator within range of 0~100. The pro is it can use the constant threshold values for all time frames and all trading pairs now.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L1 Chop Zones","L1 Chop Zones", overlay=false, max_bars_back=5000, max_labels_count =500)
# Converted and modifiedTrueRange by Sam4@Cok@samer800 - 02/2023

declare lower;
input BarColor = yes;
input ShowLabel = yes;
input len = 500;                   # "Length"
input src = close;                 # "Source"
input dist_limit_long_h = 60.0;    # "% Distance Threshold Center (Long)"
input dist_limit_long_l = 20.0;    # "% Distance Threshold Lower (Long)"
input dist_limit_short_l = 40.0;   # "% Distance Threshold Center (Short)"
input dist_limit_short_h = 80.0;   # "% Distance Threshold Upper (Short)"

#//functions

def na = Double.NaN;
def last = isNaN(close);
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 0;
    def r_val;
    r_val = if length >= 1 then
            fold i = 0 to length with p do
            if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else r_val[1] else Double.NaN;
    plot return =  r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 0;
    input wei = 0;
    def sumf;
    def ma;
    def out;
    sumf =  if(sumf[1]==0, Double.NaN,sumf[1]) - nz(src[len]) + src;
    ma   =  if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  =  if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
    
#//risk assessment algorithm
def rsva1 = (close-lowest(low,9))/(highest(high,9)-lowest(low,9))*100;
def rsva2 = 100*(highest(high,9)-close)/(highest(high,9)-lowest(low,9));
def var21 = xsa(rsva2,9,1)+100;
def var11 = xsa(rsva1,3,1);
def var51 = xsa(var11,3,1)+100;
def poleline = var51-var21+50;
def var2 = lowest(low,33);
def var3 = highest(high,21);
def var4 = ExpAverage((close-var2)/(var3-var2)*100,10)*-1+100;
def trendstrength = 100 - ExpAverage(0.191*xrf(var4,1) + 0.809*var4,1);

plot trendRange = trendstrength;
trendRange.SetDefaultColor(Color.WHITE);
trendRange.SetLineWeight(2);

def p1 = if last then na else dist_limit_long_h;
def p2 = if last then na else dist_limit_short_l;
def p3 = if last then na else dist_limit_long_l;
def p4 = if last then na else dist_limit_short_h;

AddCloud(p4, p1, Color.DARK_GREEN); # "Long Only"
AddCloud(p1, p2, Color.GRAY, Color.DARK_GRAY, yes);   # "Chop Zone"
AddCloud(p2, p3, Color.DARK_RED, Color.DARK_RED);     # "Short Only"

#--- LAbel and Br Color
def LongOB = trendstrength> p4;
def ShortOS = trendstrength< p3;
def LongOnly = trendstrength> p1 and trendstrength < p4;
def ShortOnly = trendstrength>p3 and trendstrength< p2;
def NoTrade = trendstrength>p2 and trendstrength < p1;

    AddLabel(ShowLabel and (LongOB or ShortOS), "Long & Short", color.white);
    Addlabel(ShowLabel and LongOnly, "Long Only" , color.green);
    AddLabel(ShowLabel and ShortOnly,  "Short Only" , color.red);
    AddLabel(ShowLabel and NoTrade,  "No Trade" , color.GRAY);

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if LongOB then Color.LIGHT_GREEN else
                 if ShortOS then Color.PINK else
                 if LongOnly and trendstrength>trendstrength[1] then Color.GREEN else
                 if LongOnly then Color.DARK_GREEN else
                 if NoTrade then Color.GRAY else
                 if ShortOnly and  trendstrength<trendstrength[1] then Color.RED else Color.DARK_RED);
                

#--- END CODE
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hi @samer800
The white line, would you be able to color code it as follows:
Above 60 is green, however as value of line is going down, it turn in yellow
Between 60-40- as value is increaseing..it turn white and as value is decreasing..it turns blue)
Below 40 is red, however as price increase...it's green.

Also, if you are able to add option of having on/off label for value of white line.

Thank you!
 
Last edited:
Hi @samer800
The white line, would you be able to color code it as follows:
Above 60 is green, however as value of line is going down, it turn in yellow
Between 60-40- as value is increaseing..it turn white and as value is decreasing..it turns blue)
Below 40 is red, however as price increase...it's green.

Also, if you are able to add option of having on/off label for value of white line.

Thank you!
try the below

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L1 Chop Zones","L1 Chop Zones", overlay=false, max_bars_back=5000, max_labels_count =500)
# Converted and modifiedTrueRange by Sam4@Cok@samer800 - 02/2023
#--- Updated Colors and added smooting option

declare lower;
input BarColor = yes;
input ShowLabel = yes;
input len = 500;                   # "Length"
input src = close;                 # "Source"
input gradientColor = yes;
input Smoothing = yes;
input SmoothingLength = 5;
input dist_limit_short_h = 80.0;   # "% Distance Threshold Upper (Short)"
input dist_limit_long_h  = 60.0;   # "% Distance Threshold Center (Long)"
input dist_limit_short_l = 40.0;   # "% Distance Threshold Center (Short)"
input dist_limit_long_l  = 20.0;   # "% Distance Threshold Lower (Long)"

#//functions

def na = Double.NaN;
def last = isNaN(close);
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 0;
    def r_val;
    r_val = if length >= 1 then
            fold i = 0 to length with p do
            if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else r_val[1] else Double.NaN;
    plot return =  r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 0;
    input wei = 0;
    def sumf;
    def ma;
    def out;
    sumf =  if(sumf[1]==0, Double.NaN,sumf[1]) - nz(src[len]) + src;
    ma   =  if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  =  if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
    
#//risk assessment algorithm
def rsva1 = (close-lowest(low,9))/(highest(high,9)-lowest(low,9))*100;
def rsva2 = 100*(highest(high,9)-close)/(highest(high,9)-lowest(low,9));
def var21 = xsa(rsva2,9,1)+100;
def var11 = xsa(rsva1,3,1);
def var51 = xsa(var11,3,1)+100;
def poleline = var51-var21+50;
def var2 = lowest(low,33);
def var3 = highest(high,21);
def var4 = ExpAverage((close-var2)/(var3-var2)*100,10)*-1+100;
def trendstrength1 = 100 - ExpAverage(0.191*xrf(var4,1) + 0.809*var4,1);

def trendstrength = if Smoothing then ExpAverage(trendstrength1, SmoothingLength) else trendstrength1;
#-- Levels
def lev0  = trendstrength>dist_limit_short_h and trendstrength<trendstrength[1];
def Lev1  = trendstrength>dist_limit_long_h and trendstrength>trendstrength[1];
def Lev11 = trendstrength>dist_limit_long_h and trendstrength<trendstrength[1];
def Lev2  = trendstrength>dist_limit_short_l and trendstrength<dist_limit_long_h and trendstrength>trendstrength[1];
def Lev22 = trendstrength>dist_limit_short_l and trendstrength<dist_limit_long_h and trendstrength<trendstrength[1];
def Lev3  = trendstrength<dist_limit_short_l and trendstrength<trendstrength[1];
def Lev33 = trendstrength<dist_limit_short_l and trendstrength>trendstrength[1];
def lev5  = trendstrength<dist_limit_long_l and trendstrength>trendstrength[1];


plot trendRange = trendstrength;
trendRange.AssignValueColor(if gradientColor then
                            CreateColor(255-trendstrength*2.55,trendstrength*2.55,0) else
                            if lev0 then Color.MAGENTA else
                            if lev1 then Color.GREEN else
                            if lev11 then Color.DARK_GREEN else
                            if lev2 then Color.WHITE else
                            if lev22 then Color.GRAY else
                            if lev5 then Color.CYAN else
                            if lev3 then Color.RED else
                            if lev33 then Color.DARK_RED else Color.YELLOW);
trendRange.SetLineWeight(2);

def p1 = if last then na else dist_limit_long_h;
def p2 = if last then na else dist_limit_short_l;
def p3 = if last then na else dist_limit_long_l;
def p4 = if last then na else dist_limit_short_h;

AddCloud(p4, p1, Color.DARK_GREEN); # "Long Only"
AddCloud(p1, p2, Color.GRAY, Color.DARK_GRAY, yes);   # "Chop Zone"
AddCloud(p2, p3, Color.DARK_RED, Color.DARK_RED);     # "Short Only"

#--- LAbel and Br Color
def TS = Round(trendstrength,2);
def LongOB = trendstrength> p4;
def ShortOS = trendstrength< p3;
def LongOnly = trendstrength> p1 and trendstrength < p4;
def ShortOnly = trendstrength>p3 and trendstrength< p2;
def NoTrade = trendstrength>p2 and trendstrength < p1;


    AddLabel(ShowLabel and gradientColor, (if ShortOS then "Over Sold (" else
                        if LongOB then "Over Bought (" else
                        if LongOnly then "Long (" else
                        if ShortOnly then "Short (" else
                        if NoTrade then "No Trade (" else "N/A") + TS + ")",
                           CreateColor(255-trendstrength*2.55, trendstrength*2.55,0));
    AddLabel(ShowLabel and !gradientColor and ShortOS , "Over Sold (" + TS + ")", Color.CYAN);
    AddLabel(ShowLabel and !gradientColor and LongOB ,  "Over Bought (" + TS + ")", Color.MAGENTA);
    Addlabel(ShowLabel and !gradientColor and LongOnly, "Long (" + TS + ")", Color.GREEN);
    AddLabel(ShowLabel and !gradientColor and ShortOnly,"Short (" + TS + ")", Color.RED);
    AddLabel(ShowLabel and !gradientColor and NoTrade,  "No Trade (" + TS + ")", color.GRAY);

AssignPriceColor(if !BarColor then Color.CURRENT else CreateColor(255-trendstrength*2.55, trendstrength*2.55,0));

#--- END CODE
 
HNiT2WN.png


Author Message:
Background

Inspired by NILX's "Tool: Chop & Trade Zones". This can used as an element for trading system control.

Function

I use my own customized algorithm to replace that core of NILX one, which is targeting to provide smoother and trend for chop and trend judgement.
Since it is quite different now but an oscillator within range of 0~100. The pro is it can use the constant threshold values for all time frames and all trading pairs now.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L1 Chop Zones","L1 Chop Zones", overlay=false, max_bars_back=5000, max_labels_count =500)
# Converted and modifiedTrueRange by Sam4@Cok@samer800 - 02/2023

declare lower;
input BarColor = yes;
input ShowLabel = yes;
input len = 500;                   # "Length"
input src = close;                 # "Source"
input dist_limit_long_h = 60.0;    # "% Distance Threshold Center (Long)"
input dist_limit_long_l = 20.0;    # "% Distance Threshold Lower (Long)"
input dist_limit_short_l = 40.0;   # "% Distance Threshold Center (Short)"
input dist_limit_short_h = 80.0;   # "% Distance Threshold Upper (Short)"

#//functions

def na = Double.NaN;
def last = isNaN(close);
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 0;
    def r_val;
    r_val = if length >= 1 then
            fold i = 0 to length with p do
            if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else r_val[1] else Double.NaN;
    plot return =  r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 0;
    input wei = 0;
    def sumf;
    def ma;
    def out;
    sumf =  if(sumf[1]==0, Double.NaN,sumf[1]) - nz(src[len]) + src;
    ma   =  if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  =  if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
  
#//risk assessment algorithm
def rsva1 = (close-lowest(low,9))/(highest(high,9)-lowest(low,9))*100;
def rsva2 = 100*(highest(high,9)-close)/(highest(high,9)-lowest(low,9));
def var21 = xsa(rsva2,9,1)+100;
def var11 = xsa(rsva1,3,1);
def var51 = xsa(var11,3,1)+100;
def poleline = var51-var21+50;
def var2 = lowest(low,33);
def var3 = highest(high,21);
def var4 = ExpAverage((close-var2)/(var3-var2)*100,10)*-1+100;
def trendstrength = 100 - ExpAverage(0.191*xrf(var4,1) + 0.809*var4,1);

plot trendRange = trendstrength;
trendRange.SetDefaultColor(Color.WHITE);
trendRange.SetLineWeight(2);

def p1 = if last then na else dist_limit_long_h;
def p2 = if last then na else dist_limit_short_l;
def p3 = if last then na else dist_limit_long_l;
def p4 = if last then na else dist_limit_short_h;

AddCloud(p4, p1, Color.DARK_GREEN); # "Long Only"
AddCloud(p1, p2, Color.GRAY, Color.DARK_GRAY, yes);   # "Chop Zone"
AddCloud(p2, p3, Color.DARK_RED, Color.DARK_RED);     # "Short Only"

#--- LAbel and Br Color
def LongOB = trendstrength> p4;
def ShortOS = trendstrength< p3;
def LongOnly = trendstrength> p1 and trendstrength < p4;
def ShortOnly = trendstrength>p3 and trendstrength< p2;
def NoTrade = trendstrength>p2 and trendstrength < p1;

    AddLabel(ShowLabel and (LongOB or ShortOS), "Long & Short", color.white);
    Addlabel(ShowLabel and LongOnly, "Long Only" , color.green);
    AddLabel(ShowLabel and ShortOnly,  "Short Only" , color.red);
    AddLabel(ShowLabel and NoTrade,  "No Trade" , color.GRAY);

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if LongOB then Color.LIGHT_GREEN else
                 if ShortOS then Color.PINK else
                 if LongOnly and trendstrength>trendstrength[1] then Color.GREEN else
                 if LongOnly then Color.DARK_GREEN else
                 if NoTrade then Color.GRAY else
                 if ShortOnly and  trendstrength<trendstrength[1] then Color.RED else Color.DARK_RED);
              

#--- END CODE
would you be able to add value of the white line on the label Code 1. Thank you.


Also, noticed code 1 and code 2 values differ because you added Smoothing factor to code 2.

Which code would you recommend to use for day trading?

Thanks 😁
 
Last edited:
would you be able to add value of the white line on the label Code 1. Thank you.


Also, noticed code 1 and code 2 values differ because you added Smoothing factor to code 2.

Which code would you recommend to use for day trading?

Thanks 😁
smoothing is optional where you can disable it from the setting options. for Value, Already included in the label.
 
try the below

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L1 Chop Zones","L1 Chop Zones", overlay=false, max_bars_back=5000, max_labels_count =500)
# Converted and modifiedTrueRange by Sam4@Cok@samer800 - 02/2023
#--- Updated Colors and added smooting option

declare lower;
input BarColor = yes;
input ShowLabel = yes;
input len = 500;                   # "Length"
input src = close;                 # "Source"
input gradientColor = yes;
input Smoothing = yes;
input SmoothingLength = 5;
input dist_limit_short_h = 80.0;   # "% Distance Threshold Upper (Short)"
input dist_limit_long_h  = 60.0;   # "% Distance Threshold Center (Long)"
input dist_limit_short_l = 40.0;   # "% Distance Threshold Center (Short)"
input dist_limit_long_l  = 20.0;   # "% Distance Threshold Lower (Long)"

#//functions

def na = Double.NaN;
def last = isNaN(close);
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 0;
    def r_val;
    r_val = if length >= 1 then
            fold i = 0 to length with p do
            if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else r_val[1] else Double.NaN;
    plot return =  r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 0;
    input wei = 0;
    def sumf;
    def ma;
    def out;
    sumf =  if(sumf[1]==0, Double.NaN,sumf[1]) - nz(src[len]) + src;
    ma   =  if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  =  if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
   
#//risk assessment algorithm
def rsva1 = (close-lowest(low,9))/(highest(high,9)-lowest(low,9))*100;
def rsva2 = 100*(highest(high,9)-close)/(highest(high,9)-lowest(low,9));
def var21 = xsa(rsva2,9,1)+100;
def var11 = xsa(rsva1,3,1);
def var51 = xsa(var11,3,1)+100;
def poleline = var51-var21+50;
def var2 = lowest(low,33);
def var3 = highest(high,21);
def var4 = ExpAverage((close-var2)/(var3-var2)*100,10)*-1+100;
def trendstrength1 = 100 - ExpAverage(0.191*xrf(var4,1) + 0.809*var4,1);

def trendstrength = if Smoothing then ExpAverage(trendstrength1, SmoothingLength) else trendstrength1;
#-- Levels
def lev0  = trendstrength>dist_limit_short_h and trendstrength<trendstrength[1];
def Lev1  = trendstrength>dist_limit_long_h and trendstrength>trendstrength[1];
def Lev11 = trendstrength>dist_limit_long_h and trendstrength<trendstrength[1];
def Lev2  = trendstrength>dist_limit_short_l and trendstrength<dist_limit_long_h and trendstrength>trendstrength[1];
def Lev22 = trendstrength>dist_limit_short_l and trendstrength<dist_limit_long_h and trendstrength<trendstrength[1];
def Lev3  = trendstrength<dist_limit_short_l and trendstrength<trendstrength[1];
def Lev33 = trendstrength<dist_limit_short_l and trendstrength>trendstrength[1];
def lev5  = trendstrength<dist_limit_long_l and trendstrength>trendstrength[1];


plot trendRange = trendstrength;
trendRange.AssignValueColor(if gradientColor then
                            CreateColor(255-trendstrength*2.55,trendstrength*2.55,0) else
                            if lev0 then Color.MAGENTA else
                            if lev1 then Color.GREEN else
                            if lev11 then Color.DARK_GREEN else
                            if lev2 then Color.WHITE else
                            if lev22 then Color.GRAY else
                            if lev5 then Color.CYAN else
                            if lev3 then Color.RED else
                            if lev33 then Color.DARK_RED else Color.YELLOW);
trendRange.SetLineWeight(2);

def p1 = if last then na else dist_limit_long_h;
def p2 = if last then na else dist_limit_short_l;
def p3 = if last then na else dist_limit_long_l;
def p4 = if last then na else dist_limit_short_h;

AddCloud(p4, p1, Color.DARK_GREEN); # "Long Only"
AddCloud(p1, p2, Color.GRAY, Color.DARK_GRAY, yes);   # "Chop Zone"
AddCloud(p2, p3, Color.DARK_RED, Color.DARK_RED);     # "Short Only"

#--- LAbel and Br Color
def TS = Round(trendstrength,2);
def LongOB = trendstrength> p4;
def ShortOS = trendstrength< p3;
def LongOnly = trendstrength> p1 and trendstrength < p4;
def ShortOnly = trendstrength>p3 and trendstrength< p2;
def NoTrade = trendstrength>p2 and trendstrength < p1;


    AddLabel(ShowLabel and gradientColor, (if ShortOS then "Over Sold (" else
                        if LongOB then "Over Bought (" else
                        if LongOnly then "Long (" else
                        if ShortOnly then "Short (" else
                        if NoTrade then "No Trade (" else "N/A") + TS + ")",
                           CreateColor(255-trendstrength*2.55, trendstrength*2.55,0));
    AddLabel(ShowLabel and !gradientColor and ShortOS , "Over Sold (" + TS + ")", Color.CYAN);
    AddLabel(ShowLabel and !gradientColor and LongOB ,  "Over Bought (" + TS + ")", Color.MAGENTA);
    Addlabel(ShowLabel and !gradientColor and LongOnly, "Long (" + TS + ")", Color.GREEN);
    AddLabel(ShowLabel and !gradientColor and ShortOnly,"Short (" + TS + ")", Color.RED);
    AddLabel(ShowLabel and !gradientColor and NoTrade,  "No Trade (" + TS + ")", color.GRAY);

AssignPriceColor(if !BarColor then Color.CURRENT else CreateColor(255-trendstrength*2.55, trendstrength*2.55,0));

#--- END CODE
Would it be possible to add additional MTF trendrange line in the same code, meaning, The TrendRange Line current time frame and another Trendrange line of 2 min or 5 min, etc. ? Thank you!
 
try the below

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L1 Chop Zones","L1 Chop Zones", overlay=false, max_bars_back=5000, max_labels_count =500)
# Converted and modifiedTrueRange by Sam4@Cok@samer800 - 02/2023
#--- Updated Colors and added smooting option

declare lower;
input BarColor = yes;
input ShowLabel = yes;
input len = 500;                   # "Length"
input src = close;                 # "Source"
input gradientColor = yes;
input Smoothing = yes;
input SmoothingLength = 5;
input dist_limit_short_h = 80.0;   # "% Distance Threshold Upper (Short)"
input dist_limit_long_h  = 60.0;   # "% Distance Threshold Center (Long)"
input dist_limit_short_l = 40.0;   # "% Distance Threshold Center (Short)"
input dist_limit_long_l  = 20.0;   # "% Distance Threshold Lower (Long)"

#//functions

def na = Double.NaN;
def last = isNaN(close);
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 0;
    def r_val;
    r_val = if length >= 1 then
            fold i = 0 to length with p do
            if IsNaN(r_val[1]) or !IsNaN(values[i]) then values[i] else r_val[1] else Double.NaN;
    plot return =  r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 0;
    input wei = 0;
    def sumf;
    def ma;
    def out;
    sumf =  if(sumf[1]==0, Double.NaN,sumf[1]) - nz(src[len]) + src;
    ma   =  if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  =  if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
  
#//risk assessment algorithm
def rsva1 = (close-lowest(low,9))/(highest(high,9)-lowest(low,9))*100;
def rsva2 = 100*(highest(high,9)-close)/(highest(high,9)-lowest(low,9));
def var21 = xsa(rsva2,9,1)+100;
def var11 = xsa(rsva1,3,1);
def var51 = xsa(var11,3,1)+100;
def poleline = var51-var21+50;
def var2 = lowest(low,33);
def var3 = highest(high,21);
def var4 = ExpAverage((close-var2)/(var3-var2)*100,10)*-1+100;
def trendstrength1 = 100 - ExpAverage(0.191*xrf(var4,1) + 0.809*var4,1);

def trendstrength = if Smoothing then ExpAverage(trendstrength1, SmoothingLength) else trendstrength1;
#-- Levels
def lev0  = trendstrength>dist_limit_short_h and trendstrength<trendstrength[1];
def Lev1  = trendstrength>dist_limit_long_h and trendstrength>trendstrength[1];
def Lev11 = trendstrength>dist_limit_long_h and trendstrength<trendstrength[1];
def Lev2  = trendstrength>dist_limit_short_l and trendstrength<dist_limit_long_h and trendstrength>trendstrength[1];
def Lev22 = trendstrength>dist_limit_short_l and trendstrength<dist_limit_long_h and trendstrength<trendstrength[1];
def Lev3  = trendstrength<dist_limit_short_l and trendstrength<trendstrength[1];
def Lev33 = trendstrength<dist_limit_short_l and trendstrength>trendstrength[1];
def lev5  = trendstrength<dist_limit_long_l and trendstrength>trendstrength[1];


plot trendRange = trendstrength;
trendRange.AssignValueColor(if gradientColor then
                            CreateColor(255-trendstrength*2.55,trendstrength*2.55,0) else
                            if lev0 then Color.MAGENTA else
                            if lev1 then Color.GREEN else
                            if lev11 then Color.DARK_GREEN else
                            if lev2 then Color.WHITE else
                            if lev22 then Color.GRAY else
                            if lev5 then Color.CYAN else
                            if lev3 then Color.RED else
                            if lev33 then Color.DARK_RED else Color.YELLOW);
trendRange.SetLineWeight(2);

def p1 = if last then na else dist_limit_long_h;
def p2 = if last then na else dist_limit_short_l;
def p3 = if last then na else dist_limit_long_l;
def p4 = if last then na else dist_limit_short_h;

AddCloud(p4, p1, Color.DARK_GREEN); # "Long Only"
AddCloud(p1, p2, Color.GRAY, Color.DARK_GRAY, yes);   # "Chop Zone"
AddCloud(p2, p3, Color.DARK_RED, Color.DARK_RED);     # "Short Only"

#--- LAbel and Br Color
def TS = Round(trendstrength,2);
def LongOB = trendstrength> p4;
def ShortOS = trendstrength< p3;
def LongOnly = trendstrength> p1 and trendstrength < p4;
def ShortOnly = trendstrength>p3 and trendstrength< p2;
def NoTrade = trendstrength>p2 and trendstrength < p1;


    AddLabel(ShowLabel and gradientColor, (if ShortOS then "Over Sold (" else
                        if LongOB then "Over Bought (" else
                        if LongOnly then "Long (" else
                        if ShortOnly then "Short (" else
                        if NoTrade then "No Trade (" else "N/A") + TS + ")",
                           CreateColor(255-trendstrength*2.55, trendstrength*2.55,0));
    AddLabel(ShowLabel and !gradientColor and ShortOS , "Over Sold (" + TS + ")", Color.CYAN);
    AddLabel(ShowLabel and !gradientColor and LongOB ,  "Over Bought (" + TS + ")", Color.MAGENTA);
    Addlabel(ShowLabel and !gradientColor and LongOnly, "Long (" + TS + ")", Color.GREEN);
    AddLabel(ShowLabel and !gradientColor and ShortOnly,"Short (" + TS + ")", Color.RED);
    AddLabel(ShowLabel and !gradientColor and NoTrade,  "No Trade (" + TS + ")", color.GRAY);

AssignPriceColor(if !BarColor then Color.CURRENT else CreateColor(255-trendstrength*2.55, trendstrength*2.55,0));

#--- END CODE
Hi,
Is there a way you can have the trendrange line on the chart....upper chart indicator? trendrange line can be converted into a cloud -> price above (60) is green, price between is white (60-40), and price below (40) is red?? @samer800
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
471 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top