Indicators Not Working in ThinkorSwim Mobile App

BhNM8b0.png

Author Message:
LNL Trend System is an ATR based day trading system specifically designed for intra-day traders and scalpers. The System works on any chart time frame & can be applied to any market. The study consist of two components - the Trend Line and the Stop Line. Trend System is based on a special ATR calculation that is achieved by combining the previous values of the 13 EMA in relation to the ATR which creates a line of deviations that visually look similar to the basic moving average but actually produce very different results ESPECIALLY in sideways market.
More Details: https://www.tradingview.com/v/m0G2Xv7r/

CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// https://www.tradingview.com/v/m0G2Xv7r/
#// Created by © L&L Capital
# indicator("LNL Trend System", shorttitle = "LNL Trend System", overlay=true)
# Converted by Sam4Cok@Samer800    - 08/2023
#// Inputs

input TrendMode     = {"Tight", default "Normal", "Loose", "FOMC", "Net"};    # "Trend Mode"
input HtfMode       = {default "Auto", "Manual"};  # "HTF Mode"
input ManualTimeframe = AggregationPeriod.HOUR;    # "HTF Aggregation"
input ShowTrendBars = yes;        # "Show Trend Bars"
input ShowTrend     = yes;        # "Show Trend Line"
input ShowStopLine  = yes;        # "Show Stop Line"
input ShowHtfTrendLine = no;      # "Show HTF Trend Line"
input ShowHtfStopLine = no;       # "Show HTF Stop Line"
input ShowCloud = yes;            # "Show Cloud"
input ShowHtfCloud = no;          # "Show HTF Cloud"

def na = Double.NaN;
def last = isNaN(close);
def net = TrendMode == TrendMode."Net";
#fixnan(data)
script fixnan {
 input src = close;
     def data2;
     def bar = barnumber();
     if bar == 1 then {data2 = 0;} else
     if IsNaN(src) then {data2 = data2[1];} else
      {data2 = src;}
plot valid = data2;
}

#vwma(source, length)
script VWMA {
    input src = close;
    input len = 15;
    input v_ = volume;
    def v = if IsNaN(v_) then 1 else v_;
    def srcV = src * v;
    def srcVol = if IsNaN(srcV) then src else srcV;
    def VWMA = Average(srcVol, len) / Average(v, len);
    plot result = VWMA;
}
DefineGlobalColor("Bullish", CreateColor(39, 194, 46));
DefineGlobalColor("Bearish", CreateColor(255, 82, 82));
DefineGlobalColor("Neutral", CreateColor(67, 70, 81));
#// Trend Bars (DMI Colored Candles)
def tr_ = TrueRange(high, close, low);
def tr  = if IsNaN(tr_) then 0 else tr_;
def nATR = WildersAverage(tr, 14);
def hi = ((high - high[1]) > (low[1] - low)) and ((high - high[1]) > 0);
def lo = ((low[1] - low) > (high - high[1])) and ((low[1] - low) > 0);
def BullishDMI = if hi then (high - high[1]) else 0;
def BearishDMI = if lo then (low[1] - low) else 0;
def DMIUp = 100 * WildersAverage(BullishDMI, 14) / nATR;
def DMIDown = 100 * WildersAverage(BearishDMI, 14) / nATR;
def ADXx = if (DMIUp + DMIDown) > 0 then 100 * AbsValue(DMIUp - DMIDown) / (DMIUp + DMIDown) else na;
def ADX = WildersAverage(ADXx, 14);
def ColorBars = if (DMIUp > DMIDown and ADX > 20) then 1 else
                if (DMIUp < DMIDown and ADX > 20) then -1 else 0;
#ShowTrendBars
AssignPriceColor(if !ShowTrendBars then Color.CURRENT else
                 if ColorBars > 0 then GlobalColor("Bullish") else
                 if ColorBars < 0 then GlobalColor("Bearish") else GlobalColor("Neutral"));
#// Trend System (First Time Frame)
def ema8 =  vwma(close, 8);
def ema13 = vwma(close, 13);
def ema21 = vwma(close, 21);
def ema34 = vwma(close, 34);
def emaup = ema8 > ema13  and ema13 > ema21 and ema21 > ema34;
def emadn = ema8 < ema13  and ema13 < ema21 and ema21 < ema34;
def Trend = ExpAverage(close, 13);
def TrendColor = if emadn and close <= Trend then -1 else
                 if emaup and close >= Trend then 1 else 0;
plot TrendLine = if !ShowTrend then na else Trend; # "Trend", color = TrendColor
TrendLine.SetLineWeight(2);
TrendLine.AssignValueColor(if TrendColor > 0 then GlobalColor("Bullish") else
                           if TrendColor < 0 then GlobalColor("Bearish") else GlobalColor("Neutral"));
def ATRLength;
switch (TrendMode) {
case "Tight" :
    ATRLength = 60;
case "Normal":
    ATRLength = 80;
case "Loose" :
    ATRLength = 100;
case "FOMC"  :
    ATRLength = 120;
case "Net"   :
    ATRLength = 140;
}
def emaTr8 = ExpAverage(tr , 8);
def ATR = (ATRLength / 100) * emaTr8;
def Up = close > (Trend + ATR);
def Down = close < (Trend - ATR);
def T = if Up then 1 else if Down then -1 else T[1];
def StopLineColor =  T == 1;
plot StopLine = if !ShowStopLine then na else
                 if T == 1  then (Trend - ATR) else
                 if T == -1 then (Trend + ATR) else T[1];     # "StopLine"
StopLine.AssignValueColor(if StopLineColor then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLine.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRA = (ATRLength - 20) / 100 * emaTr8;
def Up11 = close > (Trend + ATRA);
def Down11 = close < (Trend - ATRA);
def T11 = if Up11 then 1 else if Down11 then -1 else T11[1];
def StopLineColor1 = T11 == 1;

plot StopLine2 = if !ShowStopLine then na else
                if T11 == 1 then (Trend - ATRA) else
                if T11 == -1 then (Trend + ATRA) else T11[1]; # "StopLine2"
StopLine2.AssignValueColor(if StopLineColor1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLine2.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRNET = if net then (ATRLength - 40) / 100 * emaTr8 else na;
def UpNET = close > (Trend + ATRNET);
def DownNET = close < (Trend - ATRNET);
def TNET = if UpNET then 1 else if DownNET then -1 else TNET[1];
def StopLineColorNET = TNET == 1;

plot StopLineNET = if !ShowStopLine then na else
                   if TNET == 1 then (Trend - ATRNET) else
                   if TNET == -1 then (Trend + ATRNET) else TNET[1];    # "StopLineNET"
StopLineNET.AssignValueColor(if StopLineColorNET then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNET.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRNET1 = if net then (ATRLength - 60) / 100 * emaTr8 else na;
def UpNET1 = close > (Trend + ATRNET1);
def DownNET1 = close < (Trend - ATRNET1);
def TNET1 = if UpNET1 then 1 else if DownNET1 then -1 else TNET1[1];
def StopLineColorNET1 = TNET1 == 1;

plot StopLineNET1 = if !ShowStopLine then na else
                    if TNET1 == 1 then (Trend - ATRNET1) else
                    if TNET1 == -1 then (Trend + ATRNET1) else TNET1[1]; # "StopLineNET1"
StopLineNET1.AssignValueColor(if StopLineColorNET1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNET1.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRNET2 = if net then (ATRLength - 80) / 100 * emaTr8 else na;
def UpNET2 = close > (Trend + ATRNET2);
def DownNET2 = close < (Trend - ATRNET2);
def TNET2 = if UpNET2 then 1 else if DownNET2 then -1 else TNET2[1];
def StopLineColorNET2 = TNET2 == 1;

plot StopLineNET2 = if !ShowStopLine then na else
                    if TNET2 == 1 then (Trend - ATRNET2) else
                    if TNET2 == -1 then (Trend + ATRNET2) else TNET2[1]; # "StopLineNET2"
StopLineNET2.AssignValueColor(if StopLineColorNET2 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNET2.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Higher Time Frame Aggregations

def current = GetAggregationPeriod();
def TimeFrameA =
      if current < AggregationPeriod.FIVE_MIN then AggregationPeriod.FIVE_MIN else
      if current < AggregationPeriod.THIRTY_MIN then AggregationPeriod.THIRTY_MIN else
      if current < AggregationPeriod.FOUR_HOURS then AggregationPeriod.FOUR_HOURS else
      if current < AggregationPeriod.DAY then AggregationPeriod.DAY else
      if current < AggregationPeriod.WEEK then AggregationPeriod.WEEK else
      if current < AggregationPeriod.MONTH then AggregationPeriod.MONTH else
      if current < AggregationPeriod.QUARTER then AggregationPeriod.QUARTER else current;
def TimeFrame;
switch (HTFMode) {
case "Auto" :
    TimeFrame = TimeFrameA;
case "Manual" :
    TimeFrame = ManualTimeframe;
}
def HighTf = high(Period = TimeFrame);
def LowTf  = low(Period = TimeFrame);
def CloseTf = close(Period = TimeFrame);
def volTf   = volume(Period = TimeFrame);
def trTf_   = TrueRange(HighTf, CloseTf, LowTf);
def trTf     = if IsNaN(trTf_) then (HighTf-LowTf) else trTf_;
def ematrTf8 = fixnan(ExpAverage(trTf, 8));
def ATRLength2 = ATRLength;

def ema82  = vwma(CloseTf, 8, volTf);
def ema132 = vwma(CloseTf, 13, volTf);
def ema212 = vwma(CloseTf, 21, volTf);
def ema342 = vwma(CloseTf, 34, volTf);
def emaup2 = ema82 > ema132  and ema132 > ema212 and ema212 > ema342;
def emadn2 = ema82 < ema132  and ema132 < ema212 and ema212 < ema342;

def Trend2 = ExpAverage(CloseTf, 13);
def TrendColor2 = if emadn2 and CloseTf <= Trend2 then -1 else
                  if emaup2 and CloseTf >= Trend2 then 1 else 0;

plot Trend2Line = if !ShowHtfTrendLine then na else Trend2;    # "Trend2"
Trend2Line.SetLineWeight(2);
Trend2Line.AssignValueColor(if TrendColor2 > 0 then GlobalColor("Bullish") else
                            if TrendColor2 < 0 then GlobalColor("Bearish") else GlobalColor("Neutral"));

def ATR2 = (ATRLength2 / 100) * ematrTf8;
def Up2 = CloseTf > (Trend2 + ATR2);
def Down2 = CloseTf < (Trend2 - ATR2);
def T2 = if Up2 then 1 else if Down2 then -1 else T2[1];
def StopLineColor2 = T2 == 1;

plot StopLineTf = if !ShowHtfStopLine then na else
                 if T2 == 1 then (Trend2 - ATR2) else
                 if T2 == -1 then (Trend2 + ATR2) else T2[1];    # "StopLine2"
StopLineTf.AssignValueColor(if StopLineColor2 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineTf.SetPaintingStrategy(PaintingStrategy.DASHES);
#ShowStop2

def ATR2A = (ATRLength2 - 20) / 100 * ematrTf8;
def Up2A = CloseTf > (Trend2 + ATR2A);
def Down2A = CloseTf < (Trend2 - ATR2A);
def T2A = if Up2A then 1 else if Down2A[1] then -1 else T2A[1];
def StopLineColor2A = T2A == 1;

plot StopLine2Tf = if !ShowHtfStopLine then na else
                   if T2A == 1 then (Trend2 - ATR2A) else
                   if T2A == -1 then (Trend2 + ATR2A) else T2A[1];    #  "StopLine2"
StopLine2Tf.AssignValueColor(if StopLineColor2A then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLine2Tf.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATR2ANET = if net then (ATRLength2 - 40) / 100 * ematrTf8 else na;
def Up2ANET = CloseTf > (Trend2 + ATR2ANET);
def Down2ANET = CloseTf < (Trend2 - ATR2ANET);
def T2ANET = if Up2ANET then 1 else if Down2ANET[1] then -1 else T2ANET[1];
def StopLineColor2ANET = T2ANET == 1;

plot StopLineNETtf = if !ShowHtfStopLine then na else
                     if T2ANET == 1 then (Trend2 - ATR2ANET) else
                     if T2ANET == -1 then (Trend2 + ATR2ANET) else T2ANET[1];    # StopLineColor2ANET
StopLineNETtf.AssignValueColor(if StopLineColor2ANET then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNETtf.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATR2ANET1 = if Net then (ATRLength2 - 60) /100 * ematrTf8 else na;
def Up2ANET1 = CloseTf > (Trend2 + ATR2ANET1);
def Down2ANET1 = CloseTf < (Trend2 - ATR2ANET1);
def T2ANET1 = if Up2ANET1 then 1 else if Down2ANET1[1] then -1 else T2ANET1[1];
def StopLineColor2ANET1 = T2ANET1 == 1;

plot StopLineNETtf1 = if !ShowHtfStopLine then na else
                      if T2ANET1 == 1 then (Trend2-ATR2ANET1) else
                      if T2ANET1 == -1 then (Trend2+ATR2ANET1) else T2ANET1[1];
StopLineNETtf1.AssignValueColor(if StopLineColor2ANET1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNETtf1.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATR2ANET2 = if Net then (ATRLength2 - 80) /100 * ematrTf8 else na;
def Up2ANET2 = CloseTf > (Trend2 + ATR2ANET2);
def Down2ANET2 = CloseTf < (Trend2 - ATR2ANET2);
def T2ANET2 = if Up2ANET2 then 1 else if Down2ANET2[1] then -1 else T2ANET2[1];
def StopLineColor2ANET2 = T2ANET2 == 1;

plot StopLineNETtf2 = if !ShowHtfStopLine then na else
                      if T2ANET2 == 1 then (Trend2-ATR2ANET2) else
                      if T2ANET2 == -1 then (Trend2+ATR2ANET2) else T2ANET2[1];
StopLineNETtf2.AssignValueColor(if StopLineColor2ANET1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNETtf2.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Trend Clouds

def p1 = Trend;
def p2 = if T == 1 then (Trend-ATR) else if T == -1 then (Trend+ATR) else T[1];
AddCloud(if !ShowCloud then na else p1, p2, Color.DARK_GREEN, Color.DARK_RED);

def p3 = Trend2;
def p4 = if T2 == 1 then (Trend2-ATR2) else if T2 == -1 then (Trend2+ATR2) else T2[1];

AddCloud(if !ShowHTFCloud then na else p3 ,p4, Color.DARK_GREEN, Color.DARK_RED);

#--- END of CODE

Samer, nice job on the conversion. Can you adjust it to work on the mobile app? I heard that AssignValueColor does not work on mobile so the code needs to be changed to assign the color based on if/then statements.

Ruby:
y chart time frame & can be applied to any market. The study consist of two components - the Trend Line and the Stop Line. Trend System is based on a special ATR calculation that is achieved by combining the previous values of the 13 EMA in relation to the ATR which creates a line of deviations that visually look similar to the basic moving average but actually produce very different results ESPECIALLY in sideways market.
More Details: https://www.tradingview.com/v/m0G2Xv7r/

CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// https://www.tradingview.com/v/m0G2Xv7r/
#// Created by © L&L Capital
# indicator("LNL Trend System", shorttitle = "LNL Trend System", overlay=true)
# Converted by Sam4Cok@Samer800    - 08/2023
#// Inputs

input TrendMode     = {"Tight", default "Normal", "Loose", "FOMC", "Net"};    # "Trend Mode"
input HtfMode       = {default "Auto", "Manual"};  # "HTF Mode"
input ManualTimeframe = AggregationPeriod.HOUR;    # "HTF Aggregation"
input ShowTrendBars = yes;        # "Show Trend Bars"
input ShowTrend     = yes;        # "Show Trend Line"
input ShowStopLine  = yes;        # "Show Stop Line"
input ShowHtfTrendLine = no;      # "Show HTF Trend Line"
input ShowHtfStopLine = no;       # "Show HTF Stop Line"
input ShowCloud = yes;            # "Show Cloud"
input ShowHtfCloud = no;          # "Show HTF Cloud"

def na = Double.NaN;
def last = isNaN(close);
def net = TrendMode == TrendMode."Net";
#fixnan(data)
script fixnan {
 input src = close;
     def data2;
     def bar = barnumber();
     if bar == 1 then {data2 = 0;} else
     if IsNaN(src) then {data2 = data2[1];} else
      {data2 = src;}
plot valid = data2;
}

#vwma(source, length)
script VWMA {
    input src = close;
    input len = 15;
    input v_ = volume;
    def v = if IsNaN(v_) then 1 else v_;
    def srcV = src * v;
    def srcVol = if IsNaN(srcV) then src else srcV;
    def VWMA = Average(srcVol, len) / Average(v, len);
    plot result = VWMA;
}
DefineGlobalColor("Bullish", CreateColor(39, 194, 46));
DefineGlobalColor("Bearish", CreateColor(255, 82, 82));
DefineGlobalColor("Neutral", CreateColor(67, 70, 81));
#// Trend Bars (DMI Colored Candles)
def tr_ = TrueRange(high, close, low);
def tr  = if IsNaN(tr_) then 0 else tr_;
def nATR = WildersAverage(tr, 14);
def hi = ((high - high[1]) > (low[1] - low)) and ((high - high[1]) > 0);
def lo = ((low[1] - low) > (high - high[1])) and ((low[1] - low) > 0);
def BullishDMI = if hi then (high - high[1]) else 0;
def BearishDMI = if lo then (low[1] - low) else 0;
def DMIUp = 100 * WildersAverage(BullishDMI, 14) / nATR;
def DMIDown = 100 * WildersAverage(BearishDMI, 14) / nATR;
def ADXx = if (DMIUp + DMIDown) > 0 then 100 * AbsValue(DMIUp - DMIDown) / (DMIUp + DMIDown) else na;
def ADX = WildersAverage(ADXx, 14);
def ColorBars = if (DMIUp > DMIDown and ADX > 20) then 1 else
                if (DMIUp < DMIDown and ADX > 20) then -1 else 0;
#ShowTrendBars
AssignPriceColor(if !ShowTrendBars then Color.CURRENT else
                 if ColorBars > 0 then GlobalColor("Bullish") else
                 if ColorBars < 0 then GlobalColor("Bearish") else GlobalColor("Neutral"));
#// Trend System (First Time Frame)
def ema8 =  vwma(close, 8);
def ema13 = vwma(close, 13);
def ema21 = vwma(close, 21);
def ema34 = vwma(close, 34);
def emaup = ema8 > ema13  and ema13 > ema21 and ema21 > ema34;
def emadn = ema8 < ema13  and ema13 < ema21 and ema21 < ema34;
def Trend = ExpAverage(close, 13);
def TrendColor = if emadn and close <= Trend then -1 else
                 if emaup and close >= Trend then 1 else 0;
plot TrendLine = if !ShowTrend then na else Trend; # "Trend", color = TrendColor
TrendLine.SetLineWeight(2);
TrendLine.AssignValueColor(if TrendColor > 0 then GlobalColor("Bullish") else
                           if TrendColor < 0 then GlobalColor("Bearish") else GlobalColor("Neutral"));
def ATRLength;
switch (TrendMode) {
case "Tight" :
    ATRLength = 60;
case "Normal":
    ATRLength = 80;
case "Loose" :
    ATRLength = 100;
case "FOMC"  :
    ATRLength = 120;
case "Net"   :
    ATRLength = 140;
}
def emaTr8 = ExpAverage(tr , 8);
def ATR = (ATRLength / 100) * emaTr8;
def Up = close > (Trend + ATR);
def Down = close < (Trend - ATR);
def T = if Up then 1 else if Down then -1 else T[1];
def StopLineColor =  T == 1;
plot StopLine = if !ShowStopLine then na else
                 if T == 1  then (Trend - ATR) else
                 if T == -1 then (Trend + ATR) else T[1];     # "StopLine"
StopLine.AssignValueColor(if StopLineColor then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLine.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRA = (ATRLength - 20) / 100 * emaTr8;
def Up11 = close > (Trend + ATRA);
def Down11 = close < (Trend - ATRA);
def T11 = if Up11 then 1 else if Down11 then -1 else T11[1];
def StopLineColor1 = T11 == 1;

plot StopLine2 = if !ShowStopLine then na else
                if T11 == 1 then (Trend - ATRA) else
                if T11 == -1 then (Trend + ATRA) else T11[1]; # "StopLine2"
StopLine2.AssignValueColor(if StopLineColor1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLine2.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRNET = if net then (ATRLength - 40) / 100 * emaTr8 else na;
def UpNET = close > (Trend + ATRNET);
def DownNET = close < (Trend - ATRNET);
def TNET = if UpNET then 1 else if DownNET then -1 else TNET[1];
def StopLineColorNET = TNET == 1;

plot StopLineNET = if !ShowStopLine then na else
                   if TNET == 1 then (Trend - ATRNET) else
                   if TNET == -1 then (Trend + ATRNET) else TNET[1];    # "StopLineNET"
StopLineNET.AssignValueColor(if StopLineColorNET then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNET.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRNET1 = if net then (ATRLength - 60) / 100 * emaTr8 else na;
def UpNET1 = close > (Trend + ATRNET1);
def DownNET1 = close < (Trend - ATRNET1);
def TNET1 = if UpNET1 then 1 else if DownNET1 then -1 else TNET1[1];
def StopLineColorNET1 = TNET1 == 1;

plot StopLineNET1 = if !ShowStopLine then na else
                    if TNET1 == 1 then (Trend - ATRNET1) else
                    if TNET1 == -1 then (Trend + ATRNET1) else TNET1[1]; # "StopLineNET1"
StopLineNET1.AssignValueColor(if StopLineColorNET1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNET1.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATRNET2 = if net then (ATRLength - 80) / 100 * emaTr8 else na;
def UpNET2 = close > (Trend + ATRNET2);
def DownNET2 = close < (Trend - ATRNET2);
def TNET2 = if UpNET2 then 1 else if DownNET2 then -1 else TNET2[1];
def StopLineColorNET2 = TNET2 == 1;

plot StopLineNET2 = if !ShowStopLine then na else
                    if TNET2 == 1 then (Trend - ATRNET2) else
                    if TNET2 == -1 then (Trend + ATRNET2) else TNET2[1]; # "StopLineNET2"
StopLineNET2.AssignValueColor(if StopLineColorNET2 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNET2.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Higher Time Frame Aggregations

def current = GetAggregationPeriod();
def TimeFrameA =
      if current < AggregationPeriod.FIVE_MIN then AggregationPeriod.FIVE_MIN else
      if current < AggregationPeriod.THIRTY_MIN then AggregationPeriod.THIRTY_MIN else
      if current < AggregationPeriod.FOUR_HOURS then AggregationPeriod.FOUR_HOURS else
      if current < AggregationPeriod.DAY then AggregationPeriod.DAY else
      if current < AggregationPeriod.WEEK then AggregationPeriod.WEEK else
      if current < AggregationPeriod.MONTH then AggregationPeriod.MONTH else
      if current < AggregationPeriod.QUARTER then AggregationPeriod.QUARTER else current;
def TimeFrame;
switch (HTFMode) {
case "Auto" :
    TimeFrame = TimeFrameA;
case "Manual" :
    TimeFrame = ManualTimeframe;
}
def HighTf = high(Period = TimeFrame);
def LowTf  = low(Period = TimeFrame);
def CloseTf = close(Period = TimeFrame);
def volTf   = volume(Period = TimeFrame);
def trTf_   = TrueRange(HighTf, CloseTf, LowTf);
def trTf     = if IsNaN(trTf_) then (HighTf-LowTf) else trTf_;
def ematrTf8 = fixnan(ExpAverage(trTf, 8));
def ATRLength2 = ATRLength;

def ema82  = vwma(CloseTf, 8, volTf);
def ema132 = vwma(CloseTf, 13, volTf);
def ema212 = vwma(CloseTf, 21, volTf);
def ema342 = vwma(CloseTf, 34, volTf);
def emaup2 = ema82 > ema132  and ema132 > ema212 and ema212 > ema342;
def emadn2 = ema82 < ema132  and ema132 < ema212 and ema212 < ema342;

def Trend2 = ExpAverage(CloseTf, 13);
def TrendColor2 = if emadn2 and CloseTf <= Trend2 then -1 else
                  if emaup2 and CloseTf >= Trend2 then 1 else 0;

plot Trend2Line = if !ShowHtfTrendLine then na else Trend2;    # "Trend2"
Trend2Line.SetLineWeight(2);
Trend2Line.AssignValueColor(if TrendColor2 > 0 then GlobalColor("Bullish") else
                            if TrendColor2 < 0 then GlobalColor("Bearish") else GlobalColor("Neutral"));

def ATR2 = (ATRLength2 / 100) * ematrTf8;
def Up2 = CloseTf > (Trend2 + ATR2);
def Down2 = CloseTf < (Trend2 - ATR2);
def T2 = if Up2 then 1 else if Down2 then -1 else T2[1];
def StopLineColor2 = T2 == 1;

plot StopLineTf = if !ShowHtfStopLine then na else
                 if T2 == 1 then (Trend2 - ATR2) else
                 if T2 == -1 then (Trend2 + ATR2) else T2[1];    # "StopLine2"
StopLineTf.AssignValueColor(if StopLineColor2 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineTf.SetPaintingStrategy(PaintingStrategy.DASHES);
#ShowStop2

def ATR2A = (ATRLength2 - 20) / 100 * ematrTf8;
def Up2A = CloseTf > (Trend2 + ATR2A);
def Down2A = CloseTf < (Trend2 - ATR2A);
def T2A = if Up2A then 1 else if Down2A[1] then -1 else T2A[1];
def StopLineColor2A = T2A == 1;

plot StopLine2Tf = if !ShowHtfStopLine then na else
                   if T2A == 1 then (Trend2 - ATR2A) else
                   if T2A == -1 then (Trend2 + ATR2A) else T2A[1];    #  "StopLine2"
StopLine2Tf.AssignValueColor(if StopLineColor2A then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLine2Tf.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATR2ANET = if net then (ATRLength2 - 40) / 100 * ematrTf8 else na;
def Up2ANET = CloseTf > (Trend2 + ATR2ANET);
def Down2ANET = CloseTf < (Trend2 - ATR2ANET);
def T2ANET = if Up2ANET then 1 else if Down2ANET[1] then -1 else T2ANET[1];
def StopLineColor2ANET = T2ANET == 1;

plot StopLineNETtf = if !ShowHtfStopLine then na else
                     if T2ANET == 1 then (Trend2 - ATR2ANET) else
                     if T2ANET == -1 then (Trend2 + ATR2ANET) else T2ANET[1];    # StopLineColor2ANET
StopLineNETtf.AssignValueColor(if StopLineColor2ANET then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNETtf.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATR2ANET1 = if Net then (ATRLength2 - 60) /100 * ematrTf8 else na;
def Up2ANET1 = CloseTf > (Trend2 + ATR2ANET1);
def Down2ANET1 = CloseTf < (Trend2 - ATR2ANET1);
def T2ANET1 = if Up2ANET1 then 1 else if Down2ANET1[1] then -1 else T2ANET1[1];
def StopLineColor2ANET1 = T2ANET1 == 1;

plot StopLineNETtf1 = if !ShowHtfStopLine then na else
                      if T2ANET1 == 1 then (Trend2-ATR2ANET1) else
                      if T2ANET1 == -1 then (Trend2+ATR2ANET1) else T2ANET1[1];
StopLineNETtf1.AssignValueColor(if StopLineColor2ANET1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNETtf1.SetPaintingStrategy(PaintingStrategy.DASHES);

def ATR2ANET2 = if Net then (ATRLength2 - 80) /100 * ematrTf8 else na;
def Up2ANET2 = CloseTf > (Trend2 + ATR2ANET2);
def Down2ANET2 = CloseTf < (Trend2 - ATR2ANET2);
def T2ANET2 = if Up2ANET2 then 1 else if Down2ANET2[1] then -1 else T2ANET2[1];
def StopLineColor2ANET2 = T2ANET2 == 1;

plot StopLineNETtf2 = if !ShowHtfStopLine then na else
                      if T2ANET2 == 1 then (Trend2-ATR2ANET2) else
                      if T2ANET2 == -1 then (Trend2+ATR2ANET2) else T2ANET2[1];
StopLineNETtf2.AssignValueColor(if StopLineColor2ANET1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
StopLineNETtf2.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Trend Clouds

def p1 = Trend;
def p2 = if T == 1 then (Trend-ATR) else if T == -1 then (Trend+ATR) else T[1];
AddCloud(if !ShowCloud then na else p1, p2, Color.DARK_GREEN, Color.DARK_RED);

def p3 = Trend2;
def p4 = if T2 == 1 then (Trend2-ATR2) else if T2 == -1 then (Trend2+ATR2) else T2[1];

AddCloud(if !ShowHTFCloud then na else p3 ,p4, Color.DARK_GREEN, Color.DARK_RED);

#--- END of CODE
 
Last edited by a moderator:
Hi, can anyone help me convert the scrip below so that it can be use on the mobile app

# AsGoodAsItGets
#CSR Buy/Sell Arrows with Short/Long Bubbles
#Developed 4-23-23 First Edition 8-23-22 Revised
#Updated 3/16/24 by C. Ricks

declare upper;

input atrreversal = 3.0;

def priceh = MovingAverage(AverageType.EXPONENTIAL, high, 5);
def pricel = MovingAverage(AverageType.EXPONENTIAL, low, 5);

def EIL = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastL;
def EIH = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = .01, "absolute reversal" = .05, "atr length" = 5, "atr reversal" = atrreversal).lastH;

DEF signaldown = !isNAN(EIH);

AddVerticalLine(signaldown, "EXT UP +3.0 SD", Color.white);
Alert(signaldown, "Price crossing above +3.0 SD", Alert.Bar, Sound.Ring);


DEF signalrevBot = !isNaN(EIL);

AddVerticalLine(signalrevBot, "EXT DOWN -3.0 SD", Color.white);
Alert(signalrevbot, "Price crossing below -3.0 SD", Alert.Bar, Sound.Ring);
 
Last edited by a moderator:
Can RSI Trail [UAlgo]
https://usethinkscript.com/threads/rsi-trail-ualgo-for-thinkorswim.19202/
be modified to use on cellphone?

Ruby:
#// Indicator for TOS
#// © UAlgo
#indicator("RSI Trail [UAlgo]", shorttitle="RSI Trail [UAlgo]", overlay=true)
# Converted by Sam4Cok@Samer800    - 07/2024

input ColorCandles = no; #='Color Candles', inline="display"
input showBubbles = yes;
input timeframe = {Default "Chart", "Manual"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input MovingAverageType = {"SMA", "EMA", "WMA", "RMA", "HMA",default "T3", "McGinley", "KAMA"}; # "Mov Avg Type"
input MovAvgSrc  = FundamentalType.OHLC4;
input lookbackPeriod = 27;
input atrLength = 27;
input atrMultiplier = 1.5;
input rsiLowerThreshold = 40;   # "RSI Lower Bound"
input rsiUpperThreshold = 60;   # "RSI Upper Bound"
input showMidline = no;         # "Show Midline"

def na = Double.NaN;
def last = isNaN(close);
def src; def c; def h; def l; def ohlc;
Switch (timeframe) {
Case "Manual" :
    src = if !last then Fundamental(FundamentalType = MovAvgsrc, Period = manualTimeframe) else src[1];
    c = if !last then close(Period = manualTimeframe) else c[1];
    h = if !last then high(Period = manualTimeframe) else h[1];
    l = if !last then low(Period = manualTimeframe) else l[1];
    ohlc = if !last then ohlc4(Period = manualTimeframe) else ohlc[1];
Default :
    src = Fundamental(FundamentalType = FundamentalType.OHLC4);
    c = close;
    h = high;
    l = low;
    ohlc = ohlc4;
}
Script t3 {
    input source = close;
    input length = 21;
    input vf = 0.7;
    def ema1 = ExpAverage(source, length);
    def ema2 = ExpAverage(ema1, length);
    def gd1 = ema1 * (1 + vf) - ema2 * vf;
    def ema11 = ExpAverage(gd1, length);
    def ema22 = ExpAverage(ema11, length);
    def gd2 = ema11 * (1 + vf) - ema22 * vf;
    def ema111 = ExpAverage(gd2, length);
    def ema222 = ExpAverage(ema111, length);
    def gd3 = ema111 * (1 + vf) - ema222 * vf;
    plot out = gd3;
}
script kama {
    input source = close;
    input length = 28;
    def fast = 0.666;
    def slow = 0.064;
    def noisex = AbsValue(source - source[1]);
    def signal = AbsValue(source - source[length]);
    def noise = Sum(noisex, length);
    def ratio = if noise != 0 then signal / noise else 0;
    def smooth = Power(ratio * (fast - slow) + slow, 2);
    def KAMA = CompoundValue(1, KAMA[1] + smooth * (source - KAMA[1]), source);
    plot out = KAMA;
}
#// Function to select Moving Average
script f_get_ma {
    input _type = "EMA";
    input _src = ohlc4;
    input _length = 27;
    def sma = Average(_src, _length);
    def ema = ExpAverage(_src, _length);
    def wma = WMA(_src, _length);
    def rma = WildersAverage(_src, _length);
    def hma = HullMovingAvg(_src, _length);
    def kama = KAMA(_src, _length);
    def t3 = T3(_src, _length);
    def mcg = CompoundValue(1, if !mcg[1] then _src else
              (mcg[1] + (_src - mcg[1]) / (0.6 * _length * Power((_src / mcg[1]), 4))), _src);
    def ma = if _type == "SMA" then sma else
             if _type == "EMA" then ema else
             if _type == "WMA" then wma else
             if _type == "RMA" then rma else
             if _type == "HMA" then hma else
             if _type == "T3" then t3 else
             if _type == "KAMA" then kama else
             if _type == "McGinley" then mcg else ema;
    plot out = ma;
}
#// Calculate indicator values
script f_calculate_bounds {
    input _ma = ohlc4;
    input _range = 1;
    input _upper = 60;
    input _lower = 40;
    def upper_bound = _ma + (_upper - 50) / 10 * _range;
    def lower_bound = _ma - (50 - _lower) / 10 * _range;
    plot upper = upper_bound;
    plot lower = lower_bound;
}
def tr = TrueRange(h, c, l);
def nzTR = if isNaN(tr) then (h-l) else tr;
def f_volatility = WildersAverage(nzTR, atrLength) * atrMultiplier;
def f_ma_base = f_get_ma(MovingAverageType, src, lookbackPeriod);
def f_upper_bound = f_calculate_bounds(f_ma_base, f_volatility, rsiUpperThreshold, rsiLowerThreshold).upper;
def f_lower_bound = f_calculate_bounds(f_ma_base, f_volatility, rsiUpperThreshold, rsiLowerThreshold).lower;

#// Determine market state
def is_bullish;
def is_bearish;
def bull_signal;
def bear_signal;
def crossUp = (ohlc > f_upper_bound) and (ohlc[1] <= f_upper_bound[1]);
def crossDn = (c < f_lower_bound) and (c[1] >= f_lower_bound[1]);
if crossUp {
    bull_signal = !is_bullish[1];
    bear_signal = no;
    is_bullish = yes;
    is_bearish = no;
} else if crossDn {
    bull_signal = no;
    bear_signal = !is_bearish[1];
    is_bullish = no;
    is_bearish = yes;
} else {
    bull_signal = no;
    bear_signal = no;
    is_bullish = is_bullish[1];
    is_bearish = is_bearish[1];
}

def retestUp = if is_bullish[1] then
               if low < f_lower_bound then retestUp[1] + 1 else retestUp[1] else 0;
def retestDn = if is_bearish[1] then
               if high > f_upper_bound then retestDn[1] + 1 else retestDn[1] else 0;
def lastRetUp = if retestUp > 0 then if retestUp==retestUp[1] then lastRetUp[1] + 1 else 0 else 0;
def lastRetDn = if retestDn > 0 then if retestDn==retestDn[1] then lastRetDn[1] + 1 else 0 else 0;

plot bullPt  = if bull_signal then f_lower_bound else na;
plot bearPt  = if bear_signal then f_upper_bound else na;
plot bullLine = if is_bullish then f_lower_bound else na;
plot bearLine = if is_bearish then f_upper_bound else na;
plot midLine  = if showMidline then f_ma_base else na;

bullPt.SetLineWeight(2);
bearPt.SetLineWeight(2);
bullPt.SetPaintingStrategy(PaintingStrategy.POINTS);
bearPt.SetPaintingStrategy(PaintingStrategy.POINTS);
bullPt.SetDefaultColor(Color.CYAN);
bearPt.SetDefaultColor(Color.DOWNTICK);
midLine.SetDefaultColor(Color.GRAY);
bullLine.AssignValueColor(if lastRetUp < 5 and retestUp > 0 then Color.YELLOW else Color.CYAN);
bearLine.AssignValueColor(if lastRetDn < 5 and retestDn > 0 then Color.YELLOW else Color.DOWNTICK);

AddChartBubble(showBubbles and bullPt, bullPt, "Bull", Color.CYAN, no);
AddChartBubble(showBubbles and bearPt, bearPt, "Bear", Color.DOWNTICK);

AddCloud(ohlc4, bullLine, Color.DARK_GREEN);
AddCloud(bearLine, ohlc4, Color.DARK_RED);

AssignPriceColor(if !ColorCandles then Color.CURRENT else
                 if is_bullish then Color.GREEN else
                 if is_bearish then Color.RED else Color.GRAY);

#-- end of CODE
 
Last edited by a moderator:
1724348966731.png


Hello, Do you know how to have the a solid color between the signals for the TOS mobile?
Right now is Red or Green by the variation of the chart.
Thanks.
 
Most of the indicators on this forum are created for the desktop app.
The formatting of these studies preclude their use on the mobile ToS version.

If you are asking why some desktop indicators do not work on the mobile app:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58079

TOS Mobile App
The TOS built-in mobile indicators work on the TOS mobile app.
ToS Mobile does not support custom indicators that utilize vertical lines, labels, bubbles, clouds, color changes for slopes and lines, renko, or multiple timeframes.

Here are some workarounds --> https://usethinkscript.com/threads/indicators-not-working-in-thinkorswim-mobile-app.232/
Here are some ToS Mobile Friendly Indicators --> https://usethinkscript.com/threads/tos-mobile-friendly-indicators.1071/

@aravind1403 @drk @Adobe8 @Ahmar824 @dogee @Pietrarie @xasthur
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
223 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