TTM_Squeeze Backtest

Squeeze

New member
So I have come across a back tester for TTM_Squeeze not my code but was wondering if the community can help tweak this below. This is were I found the code from the video link- https://tosindicators.com/indicators/ttm-squeeze-backtester

Original Code below:

Code:
input length = 20;
input nk = 1.5;
input nBB = 2.0;

def squeeze = TTM_Squeeze(close, length, nk, nBB).SqueezeAlert;

def EMA13 = ExpAverage(close, 13);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);

def bullish = EMA13 > EMA21 and EMA21 > EMA34;
def bearish = EMA13 < EMA21 and EMA21 < EMA34;

def fiveDotSqueeze = Sum(squeeze, 5) == 0;

def bullishSignal = if fiveDotSqueeze and bullish then 1 else 0;
def bearishSignal = if fiveDotSqueeze and bearish then 1 else 0;

def exitBullishTrade = if EMA13 < EMA21 and EMA13[1] >= EMA21[1] then 1 else 0;
def exitBearishTrade = if EMA13 > EMA21 and EMA13[1] <= EMA21[1] then 1 else 0;

AddOrder(OrderType.Buy_To_Open, BullishSignal,Close, 100);
AddOrder(OrderType.Sell_To_Close, high>= entryPrice() + entryPrice()*0.03, entryPrice() + entryPrice()*0.03, 10);
AddOrder(OrderType.Sell_To_Close, exitBullishTrade,Close, 100);

AddOrder(OrderType.Sell_To_Open, bearishSignal,Close, 100);
AddOrder(OrderType.Sell_To_Close, low<= entryPrice() - entryPrice()*0.03, entryPrice() - entryPrice()*0.03, 10);
AddOrder(OrderType.Buy_To_Close, exitBearishTrade,Close, 100);

Couple of things to insert below: need help with the code

Create:

1. alert when to buy to open is true
2. alert when to sell to close is true

Not sure how this can be done but the code below if true then override the alerts above ? In the image below you can see the purple trades means it was one or the codes below. I hope that makes sense if not let me know..

0Bm8E2U.png


Code:
AddOrder(OrderType.Sell_To_Close, high>= entryPrice() + entryPrice()*0.03, entryPrice() + entryPrice()*0.03, 10);
Code:
AddOrder(OrderType.Sell_To_Close, low<= entryPrice() - entryPrice()*0.03, entryPrice() - entryPrice()*0.03, 10);

Send Alerts: to phone/email or forward the message log to txt sms? Would it be possible to send when an alert- buy to open vice verse sell to close? Or
if someone can help me create it in marketwatch and create an alert?
 
Try this:

Code:
# Alerts
Alert(BullishSignal, " ", Alert.Bar, Sound.Chimes);
Alert(exitBullishTrade, " ", Alert.Bar, Sound.Bell);
 

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

If this is true or vice verse if bearish
Code:
def bullishSignal = if fiveDotSqueeze and bullish then 1 else 0

I believe that is what makes an add order pop on the screen so in turn plot an arrow similar to what the add order does ? I am trying to replicate the strategy into a scan so I can make a watchlist, Then when a stock appears into scan watchlist I can send an txt to my phone. and can do the same when its a bearish signal to remove. Am i approaching this the right way @BenTen ?
 
@Squeeze I'm going to assume that you want to scan for the following:

Code:
def bullishSignal = if fiveDotSqueeze and bullish then 1 else 0;
def bearishSignal = if fiveDotSqueeze and bearish then 1 else 0;

Here is the new script that you need to add as an indicator:

Code:
input length = 20;
input nk = 1.5;
input nBB = 2.0;

def squeeze = TTM_Squeeze(close, length, nk, nBB).SqueezeAlert;

def EMA13 = ExpAverage(close, 13);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);

def bullish = EMA13 > EMA21 and EMA21 > EMA34;
def bearish = EMA13 < EMA21 and EMA21 < EMA34;

def fiveDotSqueeze = Sum(squeeze, 5) == 0;

def bullishSignal = if fiveDotSqueeze and bullish then 1 else 0;
def bearishSignal = if fiveDotSqueeze and bearish then 1 else 0;

plot bull = bullishSignal;
bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot bear = bearishSignal;
bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

This will plot up and down arrows on your chart. You can set up the scanner to something like this:

MhdSa9G.png


If you still need help with the scanner, watch the tutorial below:


In order to get alerts through your phone, you need to save your scanner as a watchlist and select the following option: Alerts when scan results change....

1VyQPrW.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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