check the below.@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.
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