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?
 

Squeeze

New member
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 ?
 

BenTen

Administrative
Staff member
Staff
VIP
@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
 

Squeeze

New member
Another thing is the strategy is good just trying to not look at it all the time, so I am trying to come up with an alert system. I like using it the only thing is it produces a lot of arrows when you scan. I was wondering if we can just have the first arrow appear as the ones that follow are useless.. then there is a gap boom the first arrow appears. @barbaros @rj3137 @BenTen
4ZEMPGa.png
 
Last edited:

Similar threads

Top