TTM Squeeze with Schaff Trend Cycle

confluence905

New member
I trying to combine the TTM Squeeze and Schaff Trend Cycle (STC) as a trading strategy in TOS but having some trouble getting the bullish signal to align with the TTM squeeze and STC.
Ruby:
#Position
input Shares = 5;
input Gain = 0.03;

#TTM Squeeze parameters
input length = 10;
input nk = 1.5;
input nBB = 2.0;

#MACD, TTM, STC Parameters
input fastLength = 5;
input medLength = 20;
input slowLength = 50;

#STC Parameters
input KPeriod = 10;
input DPeriod = 3;

#Studies
def TTM = TTM_Squeeze(close, length, nk, nBB).histogram;
def squeeze = TTM_Squeeze(close, length, nk, nBB).SqueezeAlert;
def STC = schaffTrendCycle(fastLength, slowLength, KPeriod, DPeriod);
#def MAC = MACD(fastLength, medLength, length);

#Bullish Signals
#def MACBullish = if MAC > MAC[1] and MAC[1] < MAC[2] then 1 else 0;
def STCBullish = if STC < 25 and STC > STC[1] and STC[1] < STC[2] then 1 else 0;
def TTMBullish = if TTM < Squeeze and TTM > TTM[1] and TTM[1] < TTM[2] then 1 else 0;
def Bullish = if STCBullish == 1 and TTMBullish ==1 then 1 else 0;

#Bearish Signals
#def MACBearish = if MAC < MAC[1] and MAC[1] > MAC[2] then 1 else 0;
def STCBearish = if STC > 75 and STC < STC[1] and STC[1] > STC[2] then 1 else 0;
def TTMBearish = if TTM > squeeze and TTM < TTM[1] and TTM[1] >= TTM[2] then 1 else 0;
def Bearish = if STCBearish == 1 then 1 else 0;

#Combined
def BullishSignal = Bullish == 1;
def BearishSignal = Bearish == 1;

#Exit Trade
def exitBullishTrade = if Bearish == 1 then 1 else 0;
def exitBearishTrade = if Bullish == 1 then 1 else 0;

#Execute Bullish Buy and Sell
AddOrder(OrderType.BUY_TO_OPEN, BullishSignal, close, Shares);
AddOrder(OrderType.SELL_TO_CLOSE, high >= EntryPrice() + EntryPrice() * Gain, EntryPrice() + EntryPrice() * Gain, Shares);
AddOrder(OrderType.SELL_TO_CLOSE, exitBullishTrade, close, Shares);

#Execute Bearish Buy and Sell
#AddOrder(OrderType.SELL_TO_OPEN, BearishSignal, close, Shares);
#AddOrder(OrderType.BUY_TO_CLOSE, low <= EntryPrice() - (EntryPrice() * Gain), EntryPrice() - (EntryPrice() * Gain), Shares);
#AddOrder(OrderType.BUY_TO_CLOSE, exitBearishTrade, close, Shares);

7kiDnlg.png
 
Last edited by a moderator:
Hey @confluence905 try setting it up like this "def STCBullish = if STC[-1] < 25 and STC[-1] > STC and STC < STC[1] then 1 else 0;". When shifting what was being referenced to the right one bar it was able to trigger the buy at the first green sign from STC and sell at the first red sign. That may work for the TTM portion as well. Also would you mind sharing your STC_DEMA_PWC study? It looks interesting and if you're willing I'd like to be able to see what went into it.
 
Last edited:

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

Hey @confluence905 I am afraid that I don't have enough experience yet to help with that strat, but would you mind sharing your STC_DEMA_PWC study? It looks interesting and if you're willing I'd like to be able to see what went into it.
I've been able to get it to work with both the ttm squeeze and stc code since I posted but it still need a little work as the signals don't exactly align with each other.

Here's the STC DEMA indicator code, which I added DEMA and STC Bullish and Bearish signals to recently. Let me know if you have any improvements to the code.
Code:
#STC = Schaff Trend Cycle
#Schaff Trend Line = Used for quick up/down trend declaration
#Added DEMA, Breakout signals, and clouds 11/10/21 ~Confluence905

declare lower;

#Assign Breakout signals
input STC_BreakoutSignals = {default "No", "Yes"};
input DEMA_BreakoutSignals = {default "No", "Yes"};

#STC inputs
input fastLength = 5;
input slowLength = 50;
input KPeriod = 10;
input DPeriod = 3;
input over_bought = 75;
input over_sold = 25;
input Zero_line = 50;
input averageTypeSTC = AverageType.WEIGHTED;

#DEMA inputs
input sfastLength = 5;
input mfastLength = 10;

#STC Code
def macdTrend = MovingAverage(averageTypeSTC, close, fastLength) - MovingAverage(averageTypeSTC, close, slowLength);
def fastK1Trend = FastKCustom(macdTrend, KPeriod);
def fastD1Trend = MovingAverage(averageTypeSTC, fastK1Trend, DPeriod);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriod);
plot STCTrend = MovingAverage(averageTypeSTC, fastK2Trend, DPeriod);
plot OverBought = over_bought;
plot OverSold = over_sold;
plot ZeroLine = Zero_line;

#STC Plotting
STCTrend.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(Color.BLACK);
OverSold.SetDefaultColor(Color.BLACK);
STCTrend.DefineColor("Positive and Up", Color.UPTICK);
STCTrend.DefineColor("Negative and Down", Color.DOWNTICK);
STCTrend.AssignValueColor(if STCTrend >= STCTrend[1] then STCTrend.Color("Positive and Up") else STCTrend.Color("Negative and Down"));
STCTrend.SetLineWeight(2);

#STC Cloud
AddCloud(STCTrend, OverBought, Color.GREEN, Color.WHITE);
AddCloud(OverSold, STCTrend, Color.RED, Color.WHITE);

#STC BULLISH SIGNALS
def STCb = STCTrend <= over_sold and STCTrend[1] <= over_sold and STCTrend[2] <= over_sold;
def STCBullish = STCb == 1 and STCTrend > STCTrend[1] and STCTrend [1] <= STCTrend[2];
plot UpsignalSTC = if STCBULLISH == 1 then STCTrend else Double.NaN;

UpsignalSTC.SetHiding(STC_BreakoutSignals == STC_BreakoutSignals."No");
UpsignalSTC.SetDefaultColor(Color.GREEN);
UpsignalSTC.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

#STC BEARISH SIGNALS
def STCbr = STCTrend >= over_bought and STCTrend[1] >= over_bought and STCTrend[2] >= over_bought;
def STCBearish = STCbr == 1 and STCTrend < STCTrend[1] and STCTrend[1] >= STCTrend[2];
plot DnSignalSTC = if STCBearish == 1 then STCTrend else Double.NaN;
DnSignalSTC.SetHiding(STC_BreakoutSignals == STC_BreakoutSignals."No");
DnSignalSTC.SetDefaultColor(Color.RED);
DnSignalSTC.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#DEMA CODE
input price = close;
input priceType = PriceType.LAST;
def LP = Round(close(priceType = priceType), 2);
def emaPrice1 = ExpAverage(LP, sfastLength);
def emaEmaPrice1 = ExpAverage(emaPrice1, sfastLength);
def emaPrice2 = ExpAverage(LP, mfastLength);
def emaEmaPrice2 = ExpAverage(emaPrice2, mfastLength);
def DEMAfast = 2 * emaPrice1 - emaEmaPrice1;
def DEMAslow = 2 * emaPrice2 - emaEmaPrice2;
def AVG1 = DEMAfast;
def AVG2 = DEMAslow;
def Diff = DEMAfast - DEMAslow;

#DEMA DOTS Plotting
plot upsignalDEMA = ZeroLine;
upsignalDEMA.SetHiding(DEMA_BreakoutSignals == DEMA_BreakoutSignals."No");
upsignalDEMA.SetPaintingStrategy(PaintingStrategy.POINTS);
upsignalDEMA.DefineColor("Positive and Up", Color.LIGHT_GREEN);
upsignalDEMA.DefineColor("Positive and Down", Color.GREEN);
upsignalDEMA.DefineColor("Negative and Down", Color.LIGHT_RED);
upsignalDEMA.DefineColor("Negative and Up", Color.RED);
upsignalDEMA.SetLineWeight(2);
upsignalDEMA.AssignValueColor(if AVG1 >= AVG2 then upsignalDEMA.Color("Positive and Up") else upsignalDEMA.Color("Negative and Down"));
vghe261.png
 
Last edited by a moderator:
Hey, wanted to check if you were able to use successfully STC together with TTM squeeze to improve reliability of the buy/sell signals? Are you using it to enter and set stop losses?
It would not be possible to reduce oscillator false signals w/ a squeeze indicator as squeeze provides no data as to trend or direction.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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