Limited Fisher Transform for ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
TDbHu3a.png


Creator Message: https://www.tradingview.com/script/izxFcflv-Limited-Fisher-Transform/

CODE:
CSS:
#https://www.tradingview.com/script/izxFcflv-Limited-Fisher-Transform/
#//@faytterro
#indicator(title="Limited Fisher Transform", shorttitle="LFish",
# converted and mod by Sam4Cok@Samer800     - 03/2023
declare lower;
input alerts   = yes;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input colorBars = yes;
input Source = hl2;
input Length = 9;         # "Length"
input NoOfConfirmationBar = 2;
input lag = 1;
input UpperLimit = 80;    # "Upper limit"
input LowerLimit = 20;    # "Lower limit"
input LookBackRight  = 5; # "Pivot Lookback Right"
input LookBackLeft  = 5;  # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"
input DivBull = no;      # "Plot Bullish"
input DivBear = no;      # "Plot Bearish"
input DivHiddenBull = no; # "Plot Hidden Bullish"
input DivHiddenBear = no; # "Plot Hidden Bearish"

def na = Double.NaN;
def last = isNaN(close);
def confirm = max(NoOfConfirmationBar, 1);
#pine_wma(source, length) =>
script pine_wma {
    input source = close;
    input length = 9;
    def norm;# = 0.0
    def sum;# = 0.0
    norm = fold i = 0 to length with p do
              p + (length - i) * length;
    sum = fold j = 0 to length  with q do
             q + GetValue(source, j) * ( (length - j) * length);
    def wma = sum / norm;
    plot out = wma;
}
def high_ = Highest(Source, Length);
def low_  = Lowest(Source, Length);
#round_(val) =>
script round_ {
    input val = 0;
    def round_ = if val > .99 then .999 else if val < -.99 then -.999 else val;
    plot out = round_;
}
def value_ = round_(.66 * ((Source - low_) / (high_ - low_) - .5) + 0.67 * 0.67);
def value;# = 0.0
    value = CompoundValue(1, round_(.66 * ((Source - low_) / (high_ - low_) - .5) + .67 * (value[1])), value_);
def fish_ =  0.5 * Log((1 + value) / (1 - value)) + 0.5 * 0.5;
def fish1;# = 0.0
    fish1 = CompoundValue(1, 0.5 * Log((1 + value) / (1 - value)) + .5 * (fish1[1]), fish_);
def y = AbsValue(fish1);
def n = CompoundValue(1, BarNumber(), 0);
def m = if n < Length then 1 else Min(n - Length + 1, 500);

def t = Pine_wma(y, m);#//ta.cum(y)/n
def f = 100 - 100 / (Power(1 + 1 / t, fish1) + 1);
def fish2 = f[lag];

def buyCross = if (f-f[1]) > 0 then buyCross[1]+1 else 0;
def sellCross = if (f-f[1]) < 0 then sellCross[1]+1 else 0;

plot fishLag = if last then na else fish2;
plot fish = if last then na else f;
fish.SetDefaultColor(CreateColor(41,98,255));
fishLag.SetDefaultColor(Color.DARK_ORANGE);

plot topLine = if last then na else UpperLimit;
plot botLine = if last then na else LowerLimit;
plot midLine = if last then na else 50;
topLine.SetPaintingStrategy(PaintingStrategy.DASHES);
botLine.SetPaintingStrategy(PaintingStrategy.DASHES);
midLine.SetStyle(Curve.SHORT_DASH);
topLine.SetDefaultColor(Color.GRAY);
botLine.SetDefaultColor(Color.GRAY);
midLine.SetDefaultColor(CreateColor(233,30,99));

AddCloud(topLine, botLine, CreateColor(54, 5, 22));
AddCloud(fish, fishLag, CreateColor(41,98,255), Color.DARK_ORANGE);

def buy  = buyCross==confirm and f < LowerLimit;
def sell = sellCross==confirm and f > UpperLimit;

AddChartBubble(buy, f, "Buy", color.green, no);
AddChartBubble(sell, fish2, "Sell", color.red, yes);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if fish>fishLag and fish>50 then Color.GREEN else
                 if fish>50 then Color.DARK_GREEN else
                 if fish<fishLag and fish<50 then Color.RED else
                 if fish<50 then Color.DARK_RED else Color.GRAY);
#----Div-----------
def divSrc = f;

def h = high;
def l = low;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
   if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL+1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL+1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
  input cond = 0;
  input src = close;
  input MinLookback = 5;
  input MaxLookback = 60;
  input occurrence = 0;
  def n = occurrence + 1;
  def offset = fold j = MinLookback to MaxLookback + 1 with p=1 while p < n + 1
    do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
  plot price = GetValue(src, offset-1);
}
#_inRange(cond) =>
script _inRange {
    input cond = yes;
    input rangeUpper = 60;
    input rangeLower = 5;
        def bars = if cond then 0 else bars[1] + 1;
        def inrange =  (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph = findpivots(divSrc, 1, LookBackLeft, LookBackRight);

def plFound = if !isNaN(pl) then 1 else 0;
def phFound = if !isNaN(ph) then 1 else 0;

def vlFound = valuewhen(plFound, divSrc, MinLookback, MaxLookback, 1);
def vhFound = valuewhen(phFound, divSrc, MinLookback, MaxLookback, 1);

def plPrice = valuewhen(plFound, l, MinLookback, MaxLookback, 1);
def phPrice = valuewhen(phFound, h, MinLookback, MaxLookback, 1);

#// Regular Bullish
def oscHL = divSrc > vlFound and  _inRange(plFound[1],MaxLookback,MinLookback);
def priceLL = l < plPrice;
def bullCond = DivBull and plFound and oscHL and priceLL;
#// Hidden Bullish
def oscLL = divSrc < vlFound and  _inRange(plFound[1],MaxLookback,MinLookback);
def priceHL = l > plPrice;
def hiddenBullCond = DivHiddenBull and plFound and oscLL and priceHL;

#// Regular Bearish
def oscLH   = divSrc < vhFound and  _inRange(phFound[1],MaxLookback,MinLookback);
def priceHH = h > phPrice;
def bearCond = DivBear and phFound and oscLH and priceHH;
#// Hidden Bearish
def oscHH = divSrc > vhFound and  _inRange(phFound[1],MaxLookback,MinLookback);
def priceLH = h < phPrice;
def hiddenBearCond = DivHiddenBear and phFound and oscHH and priceLH;

#------ Bubbles
addchartbubble(bullCond, divSrc, "R", color.CYAN, no);
addchartbubble(bearCond, divSrc, "R", CreateColor(156,39,176), yes);
addchartbubble(hiddenBullCond, divSrc, "H", color.DARK_green, no);
addchartbubble(hiddenBearCond, divSrc, "H", color.DARK_red, yes);

#---- Alerts
Alert(alerts and buy, "Over Sold - Buy", Alert.BAR, sound);
Alert(alerts and sell, "Over Bought - Sell", Alert.BAR, sound);

#-- END of CODE
 
Last edited by a moderator:
Hi. Would anyone know how to modify this so instead of 80/20 the upper limits become 100 and 0? I tried with no success. Thank you.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
534 Online
Create Post

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