Pinch Play Indicator for ThinkorSwim

Shinthus

Member
2019 Donor
Hey everyone! I know a lot of us like reversal indicators and arrows on the Price chart. I was late-night diving into the ThinkScript_Cloud and found this accurate PinchPlay indicator by a guy named Dilbert. Please see his explanation below.

# A pinch play is essentially a PPO (or MACD) with an ADX that is
# squeezing together. This would be when the PPO drops and bottoms
# out while at the same time the ADX rises and tops out. If you
# configure the PPO above the ADX in lower subgraph the plots appear
# to pinch together when a long signal occurs. It is a wonderful play
# with good results of moves back to the 20 DMA. It displays arrows
# on the price plot when conditions are met.
#
# This study was written using the logic in the RSI divergence study
# posted recently. The logic for the short version is works in
# progress.
#
# 08.31.2015 - Dilbert - add short logic
#
# The logic for the long pinch play is fine. However I had trouble
# getting the logic for the short pinch to work.
#
# 09.05.2015 - Dilbert - Removed short logic, so that this can be scanned for long pinch
#
# When the short logic was added it made the study too complex to run
# scan queries. In order to run a scan query for a long trade, reference
# this study in the scanner.
#
# PinchPlay()."PinchUp" is true
#
# Note that the name of this study is "PinchPlay".


This is what it looks like. It "misses" sometimes, but it's never too far off. Setting a 25% stop loss for options might be enough to consistently generate profits in the long run. Works on all timeframes. Please test it and give feedback.

https://tos.mx/WGFnns
Does anybody think they can add "short logic" into this for people not interested in scanning? Unless you are using a D or W timeframe, scanning is a waste of time for this, in my opinion. By the time your scan shows results, the stocks that just signaled will be mid-move for intraday timeframes. I think this indicator could give good sell signals based on how accurate these buys are.
 
Last edited by a moderator:

markos

Well-known member
VIP
Dilbert knows his stuff. If he took the Short out, it was for a good reason.

However, that shouldn't stop other coders from taking on a challenge!
 
Last edited:

Mcerej

New member
I’ve been searching long and hard for a scanner that will find the PPO ADX pinch. Does anybody know how this can be accomplished
 

Bendu

Member
VIP
look at the right hand side, top of TOS window you will find Setup, click it and you will find Open shared item
 

iAskQs

Member
I was in the thinkscript lounge today discussing this indicator and others provided an older version that has the short logic as well. I don't know whether this works as intended though because Dilbert noted in the code something about the short logic not working right, so please be careful. I'm unsure if he just couldn't make it a scan or if there was something actually wrong with the code. With that disclaimer aside, I put on my charts and it provides long and short signals. So here is the code:

Code:
# Pinch Play
# Dilbert_PinchPlay
# V1.1 - 083115  - Dilbert  -  Add short logic
# V1   - 082715  - Dilbert  -  1st code code cut

#11:19 Dilbert: I never have liked that pinch down signal.  Just the pinch up.

Input ADXLength = 14;
# Start PPO code
input nShort = 8;
input nLong = 13;

Input PPOShortEMA = 9;
Input PPOLongEMA = 26;

def C = close;
Def PPO = (MovAvgExponential(C,PPOShortEMA) - MovAvgExponential(C,PPOLongEMA))/MovAvgExponential(C,PPOLongEMA);

#def PPO = 100 * ((ExpAverage(c, nShort) - ExpAverage(c, nLong)) / ExpAverage(c, nLong));
def ADX = ADX(ADXlength);

#hint: recognizes and signals divergences between PPO and price.
input n = 1;
input n2 = 2;
#hint n: controls how the slow pivot level is recognized. n=3 means that a slow pivot level is recognized when a high/low is preceded by 3 equal or lesser/greater (resp.) high's/low's and followed by 3 lesser/greater high's/low's. 
###############################################################################################
#  Long logic
def isADXHigh = CompoundValue(n,
    ADX[n] == Highest(ADX, n * 2 + 1) && ADX[n] > ADX && fold i = 1 to n with x=1 while x == 1 do 
        ADX[n] > GetValue(ADX, i) 
    , 0
);

def isPPOLow = CompoundValue(n,
    PPO[n] == Lowest(PPO, n * 2 + 1) && PPO[n] < PPO && fold j = 1 to n with y=1 while y == 1 do 
        PPO[n] < GetValue(PPO, j) 
    , 0
);

def ADXPivotHigh = CompoundValue(n,
    if isADXHigh then ADX[n] else ADXPivotHigh[1],
    0
);
plot highAtADXPivotHigh = CompoundValue(n,
    if isADXHigh then Max(ADX[n], ADX[n - 1]) else Double.NaN,
    0
);
def PPOPivotLow = CompoundValue(n,
    if isPPOLow then PPO[n] else PPOPivotLow[1],
    0
);
plot lowAtPPOPivotLow = CompoundValue(n,
    if isPPOLow then Min(PPO[n], PPO[n - 1]) else Double.NaN,
    0
);
###############################################################################################
# Short logic
def isPPOHigh= compoundValue(n,
    PPO[n]==highest(PPO,n*2+1) && PPO[n]> PPO && fold i2=1 to n with x2=1 while x2==1 do 
        PPO[n] > getValue(PPO,i2) 
    ,0
);
def PPOPivotHigh= compoundValue(n,
    if isPPOHigh then PPO[n] else PPOPivotHigh[1],
    0
);
plot highAtPPOPivotHigh=compoundValue(n,
    if isPPOHigh then max(PPO[n],PPO[n-1]) else Double.NaN,
    0
);

############################################################################################### 
highAtPPOPivotHigh.SetDefaultColor(Color.Cyan);
highAtADXPivotHigh.SetDefaultColor(Color.Yellow);
highAtPPOPivotHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
highAtADXPivotHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
lowAtPPOPivotLow.SetDefaultColor(Color.orange);
lowAtPPOPivotLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

highAtPPOPivotHigh.Hide();
highAtADXPivotHigh.Hide();
lowAtPPOPivotLow.Hide();

#plot PinchUp = if PPO < - .03 and ADX > ADX[10] and ADX > 20 and highAtADXPivotHigh is true #within n2 bars and lowAtPPOPivotLow is true within n2 bars then 1 else Double.NaN;

plot PinchUp = if ADX > ADX[10] and ADX > 20 and highAtADXPivotHigh and lowAtPPOPivotLow then 1 else Double.NaN;
PinchUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
PinchUp.SetDefaultColor(Color.Green);
Alert(PinchUp, "Pinch Down", sound = Sound.Ring, "alert type" = Alert.BAR);

#plot PinchDn = if ADX > ADX[10] and ADX > 20 and highAtADXPivotHigh and highAtPPOPivotHigh then 1 else Double.NaN;
plot PinchDn = if ADX > 20 and highAtADXPivotHigh and highAtPPOPivotHigh then 1 else Double.NaN;

Alert(PinchUp, "Pinch Down", sound = Sound.Ring, "alert type" = Alert.BAR);
PinchDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
PinchDn.SetDefaultColor(Color.Red);
Alert(PinchDn, "Pinch Down", sound = Sound.Ring, "alert type" = Alert.BAR);

# End Study
 
Last edited:
the pinch works with other indi besides ppo , ill have to see if i can find my notes on the pinch, i studied the pinch a a lot but never used it with tos!
 

Similar threads

Top