Fisher Transform For ThinkOrSwim

megazord

New member
Fisher Transform For ThinkOrSwim
Hey! So this is a two part question.
I have found this indicator "Fisher Transform" to be very useful in certain circumstances.

Code:
declare lower;


input price = hl2;
input length = 10;


def maxHigh = Highest(price, length);
def minLow = Lowest(price, length);
def range = maxHigh - minLow;
rec value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
rec fish = 0.5 * (Log((1 + truncValue) / (1 - truncValue)) + fish[1]);


#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#


plot FTOneBarBack = fish[1];
plot FT = fish;
plot ZeroLine = 0;


FTOneBarBack.SetDefaultColor(color.yellow);
FT.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));


input emalength = 50;
plot ema2 = ExpAverage(fish, emalength);


def bullish = if FT > ema2 then 1 else 0;
def bearish = if FT < ema2 then 1 else 0;






#####
#
# FisherTransformer Trend Up Indicator (Big Pink)
#


#
# TD Ameritrade IP Company, Inc. (c) 2017-2019
#


##### (2) Fisher Transformer setup for "FS17x5"(Big Pink) Up or Down
#Fisher_Transform_FW_Code().Scan for "FS17x5"
#The FT Code:
# Fisher Transform With First Wave (David Elliott) Signal Additions
# V01.04.2015


#
### START: FisherTransformer Initialization: Stochastic and SOAP
#
def FisherLen = 5;
def ObOs = 1.2;
def hideSoap = yes;


def h = high;
def l = low;
def c = close;
def CountChg;
def SOAPCount;
def BPmaxHigh = Highest(h, FisherLen);
def BPminLow = Lowest(l, FisherLen);
def k1v = Max(-100, Min(100, (StochasticFull(KPeriod = 5, slowing_period = 3))) - 50) / 50.01;
def k2v = Max(-100, Min(100, (StochasticFull(KPeriod = 8, slowing_period = 5))) - 50) / 50.01;
def k3v = Max(-100, Min(100, (StochasticFull(KPeriod = 17, slowing_period = 5))) - 50) / 50.01;
def R1v = Max(-100, Min(100, reference RSI(2)) - 50) / 50.01;
if k2v > 0
{
    CountChg = if k1v <= k2v and k1v[1] > k2v[1] and k2v[1] > 0 then -1 else 0;
    SOAPCount = CompoundValue(1,  Min (0, SOAPCount[1]) + CountChg, 0);
}
else
{
    CountChg = if k1v >= k2v and k1v[1] < k2v[1] and k2v[1] <= 0 then 1 else 0;
    SOAPCount = CompoundValue (1,  Max (0, SOAPCount[1]) + CountChg, 0);
}


def fish1 = CompoundValue(1, 0.5 * (Log((1 + k1v) / (1 - k1v)) + fish1[1]), 0);
def fish2 = CompoundValue(1,   0.5 * (Log((1 + k2v) / (1 - k2v)) + fish2[1]), 0);
def fish3 = CompoundValue(1, 0.5 * (Log((1 + k3v) / (1 - k3v)) + fish3[1]), 0);
def fish4 = CompoundValue(1, 0.5 * (Log((1 + R1v) / (1 - R1v)) + fish4[1]), 0);
def BPvalue = if BPmaxHigh - BPminLow == 0
   then 0
   else 0.66 * ((close - minLow) / (maxHigh - minLow) - 0.5) + 0.67 * value[1];
def BPtruncValue = if BPvalue > 0.99
                 then 0.999
                 else if BPvalue < -0.99
                 then -0.999
                 else BPvalue;
def BPfish = 0.5 * (Log((1 + BPtruncValue) / (1 - BPtruncValue)) + fish[1]);
#
### END: FisherTransformer Initialization: Stochastic and SOAP
#


### START:(2a) Fisher Transformer  "FS17x5u" (Big Pink Up)is true for trade entry
#


Plot BigPinkup = if Sign (fish3 - fish3[1]) > Sign (fish3[1] - fish3[2]) then FT else Double.NaN;
BigPinkup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BigPinkup.AssignValueColor(Color.pink);


Def BuySignal = if Sign (fish3 - fish3[1]) > Sign (fish3[1] - fish3[2])then 1 else 0;




#
# FisherTransform Trend Up Indicator
#


plot FSTrendIndicatorUp = if FT[-1] > FT and FT < FT[1] then FT else Double.NaN;
FSTrendIndicatorUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
FSTrendIndicatorUp.AssignValueColor(Color.Green);





#
# FisherTransform Trend Down Indicator
#


plot FSTrendIndicatorDown = if FT[-1] < FT and FT > FT[1] then FT else Double.NaN;
FSTrendIndicatorDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
FSTrendIndicatorDown.AssignValueColor(Color.RED);








#END CODE

1. I wanted to know if the code only initiates the green arrow upon the completion of the NEXT bar.
I see the ftonebarback but am not 100% on the situation.

2. How I can get this to work in a scan and in a watchlist. I have been trying for the scan:
Fisher_Transform(). "FSTrendIndicatorUp" is true
but that yields NO results. If I use the bigpinkup instead, it does catch some symbols, but the pink arrow lags much more than the green arrow. By then the move is underway.
I've tried using a Squeeze indicator for the watchlist and substituting the fisher transform information in, but I get an error saying the function is too complex. So I tried removing the buy zone stuff but then it says that I need to have at least one plot...

Code:
def sqz = !TTM_Squeeze().SqueezeAlert;
def direction = TTM_Squeeze()>TTM_Squeeze()[1];
def count = if sqz and !sqz[1] then 1 else count[1]+1;
def isFired = if !sqz and sqz[1] then 1 else 0;
def firedCount = if isFired then 1 else firedCount[1]+1;
def firedDirection = if isFired then direction else firedDirection[1];


def sumIsFired = sum(isFired,5);
def isFiredDir = sumIsFired && firedDirection;


# look for close buy zone
def ema8 = reference movAvgExponential(length=8);
def ema21 = reference movAvgExponential(length=21);
def currPrice = close();
def highVal = Max(ema8, ema21);
def lowVal = Min(ema8, ema21);
def inBuyZone = currPrice >= lowVal && currPrice <= highVal;


def sqzBuy = sqz && inBuyZone;
def sqzNoBuy = sqz && !inBuyZone;


addLabel(yes, Concat(if sqzBuy then "Buy " else "", if sqz then "" + count else if sumIsFired then “” + firedCount + if firedDirection then ” Long” else ” Short” else “ ”), if sqzBuy then color.black else color.black);


AssignBackgroundColor(if sqzNoBuy then color.red else if sqzBuy then color.cyan else if sumIsFired then color.green else color.black);

I'm kind a lost. If anyone could at least steer me in a helpful direction, I would be very grateful!

This is a picture of the Indicator if this helps
jpy7EKC.png
 
Last edited by a moderator:

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

Try this:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

declare lower;

input price = hl2;
input length = 10;

def maxHigh = Highest(price, length);
def minLow = Lowest(price, length);
def range = maxHigh - minLow;
def value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
def fish = 0.5 * (log((1 + truncValue) / (1 - truncValue)) + fish[1]);

plot FTOneBarBack = fish[1];
plot FT = fish;
plot ZeroLine = 0;

FTOneBarBack.SetDefaultColor(GetColor(1));
FT.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

def bull_cross = FT crosses above FTOneBarBack;
def bear_cross = FT crosses below FTOneBarBack;

# Alerts
Alert(bull_cross, " ", Alert.Bar, Sound.Chimes);
Alert(bear_cross, " ", Alert.Bar, Sound.Bell);
 
Thank you. Before posting I figured out Arrows to mark the cross. Here's the entire code:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

declare lower;

input price = hl2;
input length = 10;

def maxHigh = Highest(price, length);
def minLow = Lowest(price, length);
def range = maxHigh - minLow;
def value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
def fish = 0.5 * (log((1 + truncValue) / (1 - truncValue)) + fish[1]);

plot FTOneBarBack = fish[1];
plot FT = fish;
plot ZeroLine = 0;

FTOneBarBack.SetDefaultColor(GetColor(1));
FT.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

def bull_cross = FT crosses above FTOneBarBack;
def bear_cross = FT crosses below FTOneBarBack;


plot arrow = if FT crosses above FTOneBarBack then fish else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrow.SetDefaultColor(Color.GREEN);

plot arrowD = if FT crosses below FTOneBarBack then fish else Double.NaN;
arrowD.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
arrowD.SetPaintingStrategy(PaintingStrategy.ARROW_Down);
arrowD.SetDefaultColor(Color.RED);
# Alerts
Alert(bull_cross, " ", Alert.Bar, Sound.Chimes);
Alert(bear_cross, " ", Alert.Bar, Sound.Bell);
 
Last edited by a moderator:
@megazord
1. The red and green arrows repaint so yes, they initiate on the completion of the next bar. Basically all arrows should be push 1 bar ahead if you're backtesting.

2. Since the arrows repaint you might need to do Fisher_Transform(). "FSTrendIndicatorUp" is true within 2 bars. If a script is too complex then you need to start removing code that isn't necessary for your watchlist.
 
Hi, I'm trying to code this simple idea I had for the Fisher Transform. Here's the code for the Fisher:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

declare lower;

input price = hl2;
input length = 10;

def maxHigh = Highest(price, length);
def minLow = Lowest(price, length);
def range = maxHigh - minLow;
def value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
def fish = 0.5 * (log((1 + truncValue) / (1 - truncValue)) + fish[1]);

plot FTOneBarBack = fish[1];
plot FT = fish;
plot ZeroLine = 0;

FTOneBarBack.SetDefaultColor(GetColor(1));
FT.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

Essentially what I'm trying to do is have an arrow appear whenever FTOneBarBack - FT is greater than or equal to 1. So this was the code I had worked out:

Code:
plot down = FTOneBarBack - FT >= 1;
down.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);

The issue is right now it looks like this:

kVSne2z.png


So there's a few problems with it. Firstly, the extra arrows. The arrows that are elevated are the only ones that met the criteria, the rest are useless. I tried an "else" statement but I couldn't get it to work. Secondly I would prefer the arrows to be above the Fisher, not below it. This is probably super simple for you guys but I've never coded so this was my best effort. Thanks in advance.
 
The Fisher Scalper Color Bars

Code:
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

#The Fisher Scalper Color Bars.  Based on the fisher #transform, this indicator is pretty easy to comprehend.  #The bars are colored Green (bullish), White (transition #from bull to bear), Red (bearish), Violet (bearish #transitioning to bullish)

declare lower;

input price = hl2;
input length = 10;

def maxHigh = Highest(price, length);
def minLow = Lowest(price, length);
def range = maxHigh - minLow;
rec value = if IsNaN(price)
    then Double.NaN
    else if IsNaN(range)
        then value[1]
        else if range == 0
            then 0
            else 0.66 * ((price - minLow) / range - 0.5) + 0.67 * value[1];
def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value;
rec fish = 0.5 * (Log((1 + truncValue) / (1 - truncValue)) + fish[1]);

#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

plot FTOneBarBack = fish[1];
plot FT = fish;
plot ZeroLine = 0;

FTOneBarBack.SetDefaultColor(GetColor(1));
FT.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

input emalength = 50;
plot ema2 = ExpAverage(fish, emalength);

def bullish = if FT > ema2 then 1 else 0;
def bearish = if FT < ema2 then 1 else 0;

AddLabel(yes, "FT Ratio = " + (((FT / FTOneBarBack) * 100) - 100) + "%  " + "FT Delta = " + (AbsValue(FT) - AbsValue(FTOneBarBack)), Color.WHITE);
AddLabel(yes, "FT = " + FT + "; FTOneBarBack = " + FTOneBarBack, Color.WHITE);
#(AbsValue(FT) - AbsValue(FTOneBarBack))
AssignPriceColor(if FT > FTOneBarBack and bullish then Color.GREEN else if FT > FTOneBarBack and bearish then Color.VIOLET else if FT < FTOneBarBack and bearish then Color.RED else if FT < FTOneBarBack and bullish then Color.WHITE else Color.GRAY);

#####
#
# FisherTransformer Trend Up Indicator (Big Pink)
#

#
# TD Ameritrade IP Company, Inc. (c) 2017-2019
#

##### (2) Fisher Transformer setup for "FS17x5"(Big Pink) Up or Down
#Fisher_Transform_FW_Code().Scan for "FS17x5"
#The FT Code:
# Fisher Transform With First Wave (David Elliott) Signal Additions
# V01.04.2015

#
### START: FisherTransformer Initialization: Stochastic and SOAP
#
def FisherLen = 5;
def ObOs = 1.2;
def hideSoap = yes;

def h = high;
def l = low;
def c = close;
def CountChg;
def SOAPCount;
def BPmaxHigh = Highest(h, FisherLen);
def BPminLow = Lowest(l, FisherLen);
def k1v = Max(-100, Min(100, (StochasticFull(KPeriod = 5, slowing_period = 3))) - 50) / 50.01;
def k2v = Max(-100, Min(100, (StochasticFull(KPeriod = 8, slowing_period = 5))) - 50) / 50.01;
def k3v = Max(-100, Min(100, (StochasticFull(KPeriod = 17, slowing_period = 5))) - 50) / 50.01;
def R1v = Max(-100, Min(100, reference RSI(2)) - 50) / 50.01;
if k2v > 0
{
    CountChg = if k1v <= k2v and k1v[1] > k2v[1] and k2v[1] > 0 then -1 else 0;
    SOAPCount = CompoundValue(1,  Min (0, SOAPCount[1]) + CountChg, 0);
}
else
{
    CountChg = if k1v >= k2v and k1v[1] < k2v[1] and k2v[1] <= 0 then 1 else 0;
    SOAPCount = CompoundValue (1,  Max (0, SOAPCount[1]) + CountChg, 0);
}

def fish1 = CompoundValue(1, 0.5 * (Log((1 + k1v) / (1 - k1v)) + fish1[1]), 0);
def fish2 = CompoundValue(1,   0.5 * (Log((1 + k2v) / (1 - k2v)) + fish2[1]), 0);
def fish3 = CompoundValue(1, 0.5 * (Log((1 + k3v) / (1 - k3v)) + fish3[1]), 0);
def fish4 = CompoundValue(1, 0.5 * (Log((1 + R1v) / (1 - R1v)) + fish4[1]), 0);
def BPvalue = if BPmaxHigh - BPminLow == 0
   then 0
   else 0.66 * ((close - minLow) / (maxHigh - minLow) - 0.5) + 0.67 * value[1];
def BPtruncValue = if BPvalue > 0.99
                 then 0.999
                 else if BPvalue < -0.99
                 then -0.999
                 else BPvalue;
def BPfish = 0.5 * (Log((1 + BPtruncValue) / (1 - BPtruncValue)) + fish[1]);
#
### END: FisherTransformer Initialization: Stochastic and SOAP
#

### START:(2a) Fisher Transformer  "FS17x5u" (Big Pink Up)is true for trade entry
#

Plot BigPinkup = if Sign (fish3 - fish3[1]) > Sign (fish3[1] - fish3[2]) then FT else Double.NaN;
BigPinkup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BigPinkup.AssignValueColor(Color.pink);

Def BuySignal = if Sign (fish3 - fish3[1]) > Sign (fish3[1] - fish3[2])then 1 else 0;
AddChartBubble(BuySignal, FT, "Buy Signal! Price= $" + close ,color.LIGHT_GREEN, no);

#
# FisherTransform Trend Up Indicator
#

plot FSTrendIndicatorUp = if FT[-1] > FT and FT < FT[1] then FT else Double.NaN;
FSTrendIndicatorUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
FSTrendIndicatorUp.AssignValueColor(Color.Green);
Alert(FSTrendIndicatorUp, " ", Alert.BAR, Sound.Bell);


#
# FisherTransform Trend Down Indicator
#

plot FSTrendIndicatorDown = if FT[-1] < FT and FT > FT[1] then FT else Double.NaN;
FSTrendIndicatorDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
FSTrendIndicatorDown.AssignValueColor(Color.RED);

AddChartBubble(FT[-1] < FT and FT > FT[1], FT, "Sell Signal! Price= $" + close, Color.CYAN, yes);
Alert(FT[-1] < FT and FT > FT[1], " ", Alert.BAR, Sound.Ding);

#END CODE
 
Last edited by a moderator:
help with script command scan for fisher length instead scan for len = 5 , can I scan for all lengths at once like from 5 to 30 instead changing every thing len=
 
help with script command scan for fisher length instead scan for len = 5 , can I scan for all lengths at once like from 5 to 30 instead changing every thing len=
your post is vague, you don't mention what you are looking for.
do you want to use a fisher transform to find something?
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/E-F/FisherTransform

thinkscript has a fold loop, for sequencing through a series of numbers. it looks at many values and creates 1 output value.
https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/fold

but i don't think a fold count (a variable) can be used as length in a study.

the following is an idea for a chart study,
i'm not sure if this would work in a scan.
instead of using a built in study, it might be possible to put the fisher formulas inside of a fold loop and compare something? , to produce an output.

https://library.tradingtechnologies.com/trade/chrt-ti-ehler-fisher-transformation.html
 
Merry,

If I may indulge you. I tried to make this a strategy but I still haven't been able to code it properly. What am I missing in AddOrder?

def BuyTrigger = = FT > ema2 then 1 else 0;
def SellTrigger = FT < ema2 then 1 else 0;

AddOrder(OrderType.BUY_AUTO, BuyTrigger );
AddOrder(OrderType.Sell_AUTO, SellTrigger );
 
Merry,

If I may indulge you. I tried to make this a strategy but I still haven't been able to code it properly. What am I missing in AddOrder?

def BuyTrigger = = FT > ema2 then 1 else 0;
def SellTrigger = FT < ema2 then 1 else 0;

AddOrder(OrderType.BUY_AUTO, BuyTrigger );
AddOrder(OrderType.Sell_AUTO, SellTrigger );
how do you define ema2?
 
help with script command scan for fisher length instead scan for len = 5 , can I scan for all lengths at once like from 5 to 30 instead changing every thing len=
@donsangha Your post is still here. If any members have further input for you, they will post to this thread.
Multiple threads won't garner more responses than this thread.

Duplicate posts clutter the forum. We remove posts that do not follow our posting guidelines.
 
Last edited:
Merry,

If I may indulge you. I tried to make this a strategy but I still haven't been able to code it properly. What am I missing in AddOrder?

def BuyTrigger = = FT > ema2 then 1 else 0;
def SellTrigger = FT < ema2 then 1 else 0;

AddOrder(OrderType.BUY_AUTO, BuyTrigger );
AddOrder(OrderType.Sell_AUTO, SellTrigger );
Did you try FT crosses above/below ema2?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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