Optimized Trend Tracker For ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
@samer800 Thank you for your suggestion, I already gone through this indicator, I could not match this indicator closely with the given, requested one gives me a better signal and i can identify the full trend or if no trend it will change color, its very useful to identify the trend as per my view, Kindly review once and help me to get this indicator as is. Thank you very much.
check 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/
#// © melihtuna
#strategy("Optimized Trend Tracker - Strategy Version", shorttitle="OTT-Strategy",
# Converted by Sam4Cok@Samer800  - 02/2023

input src = close;              # "Source"
input OttPeriod = 1;            # "OTT Period"
input OttPercent = 0.1;         # "OTT Percent"
input condition = {"Price/OTT Crossing Signals",Default "Support Line Crossing Signals"};
input showSupportLine = yes;    # "Show Support Line?"
input OttColorChanges = yes;    # "Show OTT Color Changes?"
input ShowCloud = yes;          # "Highlighter On/Off ?"
input barColoing = yes;         # "Barcolor On/Off ?"
input BUY_SELl_Labels = no;     # "Show OTT BUY/SELl Labels?"

def na = Double.NaN;
def last = isNaN(Close);
def cond = condition==condition."Support Line Crossing Signals";
def alpha = 2 / (OttPeriod + 1);
def ud1   = if src > src[1] then src - src[1] else src;
def dd1   = if src < src[1] then src[1] - src else src;
def UD    = sum(ud1,9);
def DD    = sum(dd1,9);
def CMO   = (UD-DD)/(UD+DD);
def k     = AbsValue(CMO);
def Var;
    Var   = CompoundValue(1, (alpha * k * src)+(1 - alpha * k ) * Var[1], (alpha * k *src)+(1 - alpha * k ) * src);
def fark  = Var * OttPercent * 0.01;
def longStop; #= Var - fark;
def longStop1 = Var - fark;
def longStopPrev = CompoundValue(1,if longStop[1]==0 or isNaN(longStop[1]) then longStop1 else longStop[1], longStop1);
    longStop = if Var > longStopPrev then max(longStop1, longStopPrev) else longStop1;
def shortStop;# =  Var + fark;
def shortStop1 =  Var + fark;
def shortStopPrev = CompoundValue(1,if shortStop[1]==0 or isNaN(shortStop[1]) then shortStop1 else shortStop[1], shortStop1);
    shortStop = if Var < shortStopPrev then min(shortStop1, shortStopPrev) else shortStop1;
def dir;# = 1;
def dir1 = CompoundValue(1, dir[1], 1);
    dir  = if dir1 == -1 and Var > shortStopPrev then 1 else
           if dir1 == 1 and Var < longStopPrev then -1 else dir1;
def MT  = if dir == 1 then longStop else shortStop;
def OTT = if Var>MT then MT * (200+OttPercent)/200 else MT*(200-OttPercent)/200;

def OTTC = if OttColorChanges then if OTT[2] > OTT[3] then 1 else -1 else 0;#? color.green : color.red : #B800D9

plot SupportLine = if showSupportLine then Var else na;  # "Support Line"
SupportLine.SetDefaultColor(CreateColor(5,133,225));

plot pALL = CompoundValue(1, OTT[2], OTT);                # "OTT"
pAll.SetLineWeight(2);
pALL.AssignValueColor(if OTTC>0 then Color.GREEN else if OTTC<0 then Color.RED else Color.MAGENTA);

AddCloud(if ShowCloud then ohlc4 else na, pALL, Color.DARK_GREEN, Color.DARK_RED);

#--- Buy/Sell

def buySignalk   = crosses(Var, OTT[2], CrossingDirection.ABOVE);
def sellSignallk = crosses(Var, OTT[2], CrossingDirection.BELOW);
def buySignalc   = crosses(src, OTT[2], CrossingDirection.ABOVE);
def sellSignallc = crosses(src, OTT[2], CrossingDirection.BELOW);

def sigUp; def SigDn;
if cond {
    sigUp = BUY_SELl_Labels and buySignalk;
    sigDn = BUY_SELl_Labels and sellSignallk;
    } else {
    sigUp = BUY_SELl_Labels and buySignalc;
    sigDn = BUY_SELl_Labels and sellSignallc;
}

AddChartBubble(sigUp, low, "BUY", Color.GREEN, no);
AddChartBubble(sigDn, high, "SELL", Color.RED, yes);

#-- BarColor

AssignPriceColor(if !barcoloing then Color.CURRENT else
                 if OTT[2] > OTT[3] then Color.GREEN else Color.RED);
 

#------ END CODE
 

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

check 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/
#// © melihtuna
#strategy("Optimized Trend Tracker - Strategy Version", shorttitle="OTT-Strategy",
# Converted by Sam4Cok@Samer800  - 02/2023

input src = close;              # "Source"
input OttPeriod = 1;            # "OTT Period"
input OttPercent = 0.1;         # "OTT Percent"
input condition = {"Price/OTT Crossing Signals",Default "Support Line Crossing Signals"};
input showSupportLine = yes;    # "Show Support Line?"
input OttColorChanges = yes;    # "Show OTT Color Changes?"
input ShowCloud = yes;          # "Highlighter On/Off ?"
input barColoing = yes;         # "Barcolor On/Off ?"
input BUY_SELl_Labels = no;     # "Show OTT BUY/SELl Labels?"

def na = Double.NaN;
def last = isNaN(Close);
def cond = condition==condition."Support Line Crossing Signals";
def alpha = 2 / (OttPeriod + 1);
def ud1   = if src > src[1] then src - src[1] else src;
def dd1   = if src < src[1] then src[1] - src else src;
def UD    = sum(ud1,9);
def DD    = sum(dd1,9);
def CMO   = (UD-DD)/(UD+DD);
def k     = AbsValue(CMO);
def Var;
    Var   = CompoundValue(1, (alpha * k * src)+(1 - alpha * k ) * Var[1], (alpha * k *src)+(1 - alpha * k ) * src);
def fark  = Var * OttPercent * 0.01;
def longStop; #= Var - fark;
def longStop1 = Var - fark;
def longStopPrev = CompoundValue(1,if longStop[1]==0 or isNaN(longStop[1]) then longStop1 else longStop[1], longStop1);
    longStop = if Var > longStopPrev then max(longStop1, longStopPrev) else longStop1;
def shortStop;# =  Var + fark;
def shortStop1 =  Var + fark;
def shortStopPrev = CompoundValue(1,if shortStop[1]==0 or isNaN(shortStop[1]) then shortStop1 else shortStop[1], shortStop1);
    shortStop = if Var < shortStopPrev then min(shortStop1, shortStopPrev) else shortStop1;
def dir;# = 1;
def dir1 = CompoundValue(1, dir[1], 1);
    dir  = if dir1 == -1 and Var > shortStopPrev then 1 else
           if dir1 == 1 and Var < longStopPrev then -1 else dir1;
def MT  = if dir == 1 then longStop else shortStop;
def OTT = if Var>MT then MT * (200+OttPercent)/200 else MT*(200-OttPercent)/200;

def OTTC = if OttColorChanges then if OTT[2] > OTT[3] then 1 else -1 else 0;#? color.green : color.red : #B800D9

plot SupportLine = if showSupportLine then Var else na;  # "Support Line"
SupportLine.SetDefaultColor(CreateColor(5,133,225));

plot pALL = CompoundValue(1, OTT[2], OTT);                # "OTT"
pAll.SetLineWeight(2);
pALL.AssignValueColor(if OTTC>0 then Color.GREEN else if OTTC<0 then Color.RED else Color.MAGENTA);

AddCloud(if ShowCloud then ohlc4 else na, pALL, Color.DARK_GREEN, Color.DARK_RED);

#--- Buy/Sell

def buySignalk   = crosses(Var, OTT[2], CrossingDirection.ABOVE);
def sellSignallk = crosses(Var, OTT[2], CrossingDirection.BELOW);
def buySignalc   = crosses(src, OTT[2], CrossingDirection.ABOVE);
def sellSignallc = crosses(src, OTT[2], CrossingDirection.BELOW);

def sigUp; def SigDn;
if cond {
    sigUp = BUY_SELl_Labels and buySignalk;
    sigDn = BUY_SELl_Labels and sellSignallk;
    } else {
    sigUp = BUY_SELl_Labels and buySignalc;
    sigDn = BUY_SELl_Labels and sellSignallc;
}

AddChartBubble(sigUp, low, "BUY", Color.GREEN, no);
AddChartBubble(sigDn, high, "SELL", Color.RED, yes);

#-- BarColor

AssignPriceColor(if !barcoloing then Color.CURRENT else
                 if OTT[2] > OTT[3] then Color.GREEN else Color.RED);
 

#------ END CODE

Thank you very much, really awesome work @samer800. This is exactly i was looking the one. Very much appreciated.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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