Good day, I have been trying to build a strategy around the fishertransformationsignal. However, the buy signal must only be taken IF the price is above the 55 period moving average and the price of VIX is below the mean for the last 55 periods. I have been working this for the last few days and its not working. Can someone assist?
Code:
## Archive Name: TrueMomentumOscilWithFisher_v04_JQ
## Archive Section:
## Suggested Tos Name: TrueMomentumOscilWithFisher_v04_JQ
## Archive Date: 10.6.2018
## Archive Notes:
# v02 JQ added FE code to generate points
# v03 JQ added FisherTransform crossover arrows to confirm TMO
# v04 JQ Remoed all Fractal Energy code
## "##" indicates an addition by the Archivist
# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
#hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input displayFisherLabels = no;
def o = open;
def c = close;
def data = fold i = 0 to length
with s
do s + (if c > GetValue(o, i)
then 1
else if c < GetValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
#Main.AssignValueColor(if Main > Signal
#then Color.GREEN
#else Color.RED);
#Signal.AssignValueColor(if Main > Signal
#then Color.GREEN
#else Color.RED);
#Signal.HideBubble();
#Signal.HideTitle();
#AddCloud(Main, Signal, Color.GREEN, Color.RED);
#plot zero = if IsNaN(c) then Double.NaN else 0;
#zero.SetDefaultColor(Color.GRAY);
#zero.HideBubble();
#zero.HideTitle();
def ob = if IsNaN(o) then Double.NaN else Round(length * .5);
#ob.SetDefaultColor(Color.GRAY);
#ob.HideBubble();
#ob.HideTitle();
def os = if IsNaN(c) then Double.NaN else -Round(length * .5);
#os.SetDefaultColor(Color.GRAY);
#os.HideBubble();
#os.HideTitle();
#AddCloud(ob, length, Color.LIGHT_RED, Color.LIGHT_RED, no);
#AddCloud(-length, os, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
# End Code TMO
# JQ_FisherTransform_wLabels v02
# assistance provided by AlphaInvestor, amalia, randyr and nube
# v02 9.23.2018 JQ added arrows
input Fisherprice = hl2;
input FisherLength = 10;
input TriggerLineOffset = 1; # Ehler's value of choice is 1
input TriggerLine_Color_Choice = {"magenta", "cyan", "pink", default "gray", "Mustard", "red", "green", "dark_gray", "Pale Yellow", "white"};
input deBug = no;
input BuyLabelText = " TMO Buy ";
input SellLebelText = " TMO Sell ";
def maxHigh = Highest(Fisherprice, FisherLength);
def minLow = Lowest(Fisherprice, FisherLength);
def range = maxHigh - minLow;
def value = if IsNaN(Fisherprice)
then Double.NaN
else if IsNaN(range)
then value[1]
else if range == 0
then 0
else 0.66 * ((Fisherprice - 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]);
def FTOneBarBack = fish[TriggerLineOffset];
def FT = fish;
def FisherBullCross = if FT crosses above FTOneBarBack then LowestAll(Main) else Double.NaN;
#FisherBullCross.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#FisherBullCross.SetDefaultColor(Color.UPTICK);
def FisherBearCross = if FT crosses below FTOneBarBack then HighestAll(Main) else Double.NaN;
#FisherBearCross.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#FisherBearCross.SetDefaultColor(Color.DOWNTICK);
def 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);
def 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);
#AddLabel (displayFisherLabels, "" + if FT >= FTOneBarBack then #BuyLabelText else SellLebelText + " ",
# (if FT > FTOneBarBack
# then Color.LIGHT_GREEN
# else if FT < FTOneBarBack
# then Color.LIGHT_RED
# else Color.GRAY));
Alert(FisherBullCross, " ", Alert.BAR, Sound.Ring);
Alert(FisherBearCross, " ", Alert.BAR, Sound.Ring);
#------vix-------
input price = FundamentalType.LOW;
input smaLength = 20;
def priceVix = Fundamental(price, "VIX");
def smaVix = Average(priceVix, smaLength);
input n = 55;
def WVF = (Highest (Close, n) - Low) / (Highest(Close, n)) * 100;
def mean = inertiaAll(WVF);
#----------------------
input length1 = 55;
input displace = 0;
input showBreakoutSignals = no;
def SMA = Average(close[-displace], length1);
def UpSignal = price crosses above SMA;
def DownSignal = price crosses below SMA;
#-----------------------------------
AddOrder(OrderType.BUY_AUTO, condition = signal < os and main < os and fisherbullcross, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Fisher_LE");
Addorder(ordertype.sell_to_close, condition = signal > ob and main > ob and fisherbearcross, name = "Fisher_SE");
AddOrder(OrderType.SELL_AUTO, condition = signal > ob and main > ob and fisherbearcross, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Fisher_SE");
addorder(ordertype.buy_to_close, condition = signal < os and main < os and fisherbullcross,name = "Fisher_LE");
Last edited by a moderator: