BranDonCMK
New member
Greetings all,
I'm trying to create something similar to the indicator that Taylor Horton uses at Simpler Trading but with my own buy/sell signal criteria. I'm running into an issue at the end of the code where I'm trying to get an arrow under/above the TTM_Squeeze dots when my criteria are met for a buy/sell signal. The arrows appear under and above for every candle on the chart when I only want them under or above the squeeze dots when the buy or sell criteria is met. I'll provide the code and a screenshot below if anyone can help. I circled the areas on the upper chart where my buy/sell arrows are which is where they should be on the lower indicator. Please forgive me if the code is sloppy and poorly written. I can really only do very basic stuff with thinkscript.
# SqueezeSignals and Momentum Indicator - TEST
declare lower;
#Momentum Indicator
input length = 13;
input AvgMomentumLength = 13;
input price = close;
input AverageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
assert(length > 0, "'length' must be positive: " + length);
def Momentum = price - price[length];
plot AvgMomentum = movavgExponential(Momentum, AvgMomentumLength);
def bullishMomentum = AvgMomentum > 0;
def bearishMomentum = AvgMomentum < 0;
AvgMomentum.SetPaintingStrategy(paintingstrategy.LINE);
AvgMomentum.SetLineWeight(3);
AvgMomentum.AssignValueColor(if bullishmomentum then color.blue else if bearishMomentum then color.red else color.black);
# Squeeze Checklist Signals
def EMA8 = movavgExponential(close,8);
def EMA21 = movavgExponential(close,21);
def bullishStack = EMA8 > EMA21;
def bearishStack = EMA8 < EMA21;
#RSI
def RSIlength = 14;
def RSIover_Bought = 70;
def RSIover_Sold = 30;
def RSIprice = close;
def RSIaverageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(RSIaverageType, RSIprice - RSIprice[1], RSIlength);
def TotChgAvg = MovingAverage(RSIaverageType, AbsValue(RSIprice - RSIprice[1]), RSIlength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIOverSold = RSIover_Sold;
def RSIOverBought = RSIover_Bought;
def RSIUpSignal = if RSI crosses above RSIOverSold then RSIOverSold else Double.NaN;
def RSIDownSignal = if RSI crosses below RSIOverBought then RSIOverBought else Double.NaN;
def RSImidline = 50;
def bullishRSI = RSI >= 50;
def bearishRSI = RSI < 50;
#Stochastics
def over_bought = 80;
def over_sold = 20;
def KPeriod = 14;
def DPeriod = 3;
def priceH = high;
def priceL = low;
def priceC = close;
def slowing_period = 3;
def averageTypeStoch = AverageType.SIMPLE;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageTypeStoch, FastK, slowing_period);
def FullD = MovingAverage(averageTypeStoch, FullK, DPeriod);
def OverBought = over_bought;
def OverSold = over_sold;
def MidLine = 50;
def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;
def bullishStoch = FullK > FullD;
def bearishStoch = FullK < FullD;
# SqueezeHistogram
def squeezehistogram = TTM_Squeeze(close, 20, 1.5, 2.0, 1.0).Histogram;
def squeezehistogramUP = squeezehistogram > squeezehistogram[1] and squeezehistogram[1] > squeezehistogram[2];
def squeezehistogramDOWN = squeezehistogram < squeezehistogram[1] and squeezehistogram[1] < squeezehistogram[2];
# Squeeze Signal
def normalSqueeze = if TTM_Squeeze(close, 20, 1.5, 2.0, 1.0).SqueezeAlert == 0 then 1 else 0;
def aggroSqueeze = if TTM_Squeeze(close, 20, 2.0, 2.0, 1.0).SqueezeAlert == 0 then 1 else 0;
plot squeezeSignal = normalSqueeze or aggroSqueeze;
squeezeSignal.setPaintingStrategy(paintingStrategy.POINTS);
squeezeSignal.setLineWeight(3);
squeezeSignal.AssignValueColor(if normalSqueeze then color.yellow else if aggroSqueeze then color.yellow else color.dark_gray);
plot BullishSignal = squeezeSignal and bullishstack and bullishRSI and bullishStoch and squeezehistogramUP;
plot BearishSignal = squeezeSignal and bearishstack and bearishRSI and bearishStoch and squeezehistogramDOWN;
BullishSignal.SetpaintingStrategy(PaintingStrategy.ARROW_UP);
BearishSignal.SetpaintingStrategy(PaintingStrategy.ARROW_DOWN);
BullishSignal.SetLineWeight(2);
BearishSignal.SetlineWeight(2);
BullishSignal.SetdefaultColor(color.green);
BearishSignal.SetdefaultColor(color.red);
# End Code
Thanks in advance if anyone sees this and can tell me what I did wrong.
I'm trying to create something similar to the indicator that Taylor Horton uses at Simpler Trading but with my own buy/sell signal criteria. I'm running into an issue at the end of the code where I'm trying to get an arrow under/above the TTM_Squeeze dots when my criteria are met for a buy/sell signal. The arrows appear under and above for every candle on the chart when I only want them under or above the squeeze dots when the buy or sell criteria is met. I'll provide the code and a screenshot below if anyone can help. I circled the areas on the upper chart where my buy/sell arrows are which is where they should be on the lower indicator. Please forgive me if the code is sloppy and poorly written. I can really only do very basic stuff with thinkscript.
# SqueezeSignals and Momentum Indicator - TEST
declare lower;
#Momentum Indicator
input length = 13;
input AvgMomentumLength = 13;
input price = close;
input AverageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
assert(length > 0, "'length' must be positive: " + length);
def Momentum = price - price[length];
plot AvgMomentum = movavgExponential(Momentum, AvgMomentumLength);
def bullishMomentum = AvgMomentum > 0;
def bearishMomentum = AvgMomentum < 0;
AvgMomentum.SetPaintingStrategy(paintingstrategy.LINE);
AvgMomentum.SetLineWeight(3);
AvgMomentum.AssignValueColor(if bullishmomentum then color.blue else if bearishMomentum then color.red else color.black);
# Squeeze Checklist Signals
def EMA8 = movavgExponential(close,8);
def EMA21 = movavgExponential(close,21);
def bullishStack = EMA8 > EMA21;
def bearishStack = EMA8 < EMA21;
#RSI
def RSIlength = 14;
def RSIover_Bought = 70;
def RSIover_Sold = 30;
def RSIprice = close;
def RSIaverageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(RSIaverageType, RSIprice - RSIprice[1], RSIlength);
def TotChgAvg = MovingAverage(RSIaverageType, AbsValue(RSIprice - RSIprice[1]), RSIlength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIOverSold = RSIover_Sold;
def RSIOverBought = RSIover_Bought;
def RSIUpSignal = if RSI crosses above RSIOverSold then RSIOverSold else Double.NaN;
def RSIDownSignal = if RSI crosses below RSIOverBought then RSIOverBought else Double.NaN;
def RSImidline = 50;
def bullishRSI = RSI >= 50;
def bearishRSI = RSI < 50;
#Stochastics
def over_bought = 80;
def over_sold = 20;
def KPeriod = 14;
def DPeriod = 3;
def priceH = high;
def priceL = low;
def priceC = close;
def slowing_period = 3;
def averageTypeStoch = AverageType.SIMPLE;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageTypeStoch, FastK, slowing_period);
def FullD = MovingAverage(averageTypeStoch, FullK, DPeriod);
def OverBought = over_bought;
def OverSold = over_sold;
def MidLine = 50;
def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;
def bullishStoch = FullK > FullD;
def bearishStoch = FullK < FullD;
# SqueezeHistogram
def squeezehistogram = TTM_Squeeze(close, 20, 1.5, 2.0, 1.0).Histogram;
def squeezehistogramUP = squeezehistogram > squeezehistogram[1] and squeezehistogram[1] > squeezehistogram[2];
def squeezehistogramDOWN = squeezehistogram < squeezehistogram[1] and squeezehistogram[1] < squeezehistogram[2];
# Squeeze Signal
def normalSqueeze = if TTM_Squeeze(close, 20, 1.5, 2.0, 1.0).SqueezeAlert == 0 then 1 else 0;
def aggroSqueeze = if TTM_Squeeze(close, 20, 2.0, 2.0, 1.0).SqueezeAlert == 0 then 1 else 0;
plot squeezeSignal = normalSqueeze or aggroSqueeze;
squeezeSignal.setPaintingStrategy(paintingStrategy.POINTS);
squeezeSignal.setLineWeight(3);
squeezeSignal.AssignValueColor(if normalSqueeze then color.yellow else if aggroSqueeze then color.yellow else color.dark_gray);
plot BullishSignal = squeezeSignal and bullishstack and bullishRSI and bullishStoch and squeezehistogramUP;
plot BearishSignal = squeezeSignal and bearishstack and bearishRSI and bearishStoch and squeezehistogramDOWN;
BullishSignal.SetpaintingStrategy(PaintingStrategy.ARROW_UP);
BearishSignal.SetpaintingStrategy(PaintingStrategy.ARROW_DOWN);
BullishSignal.SetLineWeight(2);
BearishSignal.SetlineWeight(2);
BullishSignal.SetdefaultColor(color.green);
BearishSignal.SetdefaultColor(color.red);
# End Code
Thanks in advance if anyone sees this and can tell me what I did wrong.