"Trifecta" Indicator For ThinkOrSwim

PennyStockPump

New member
Hi all, I was curious if somebody could help me but together a "Trifecta" indicator based on a strategy I first saw from Trifecta Rick (https://twitter.com/twitwitrk). While not wanting to only use the indicator to take trades, I have seen that its a pretty significant indication of reversal trades.

What I was wanting to create was an upper indicator that would plot a vertical line when all three items have Crossovers within "x" amount of candles of each other (maybe 5?). I am open to ideas if it is just a vertical line or maybe a cloud-type look when all three indicators have confluence.

Here is the rather simple strategy using the ToS built-in indicators that is used on the 5 minute chart:
  • 5 SMA and 13 SMA Crossver
  • MACD Crossover
  • Vortex Indicator Crossover

Thank you in advance for any help!
 
Last edited by a moderator:

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

Hi all, I was curious if somebody could help me but together a "Trifecta" indicator based on a strategy I first saw from Trifecta Rick (https://twitter.com/twitwitrk). While not wanting to only use the indicator to take trades, I have seen that its a pretty significant indication of reversal trades.

What I was wanting to create was an upper indicator that would plot a vertical line when all three items have Crossovers within "x" amount of candles of each other (maybe 5?). I am open to ideas if it is just a vertical line or maybe a cloud-type look when all three indicators have confluence.

Here is the rather simple strategy using the ToS built-in indicators that is used on the 5 minute chart:
  • 5 SMA and 13 SMA Crossver
  • MACD Crossover
  • Vortex Indicator Crossover

Thank you in advance for any help!

If all you're wanting is crossovers of the SMA, Vortex, and the Upsignal/Downsignal of the MACD, then this should be what you're looking for:

Code:
## Trying the trifecta thingy from twitter

input fast_len = 5;
input slow_len = 13;
input avgtype = averageType.SIMPLE;
input show_avglines = no;
input src = close;

# Moving averages
plot fastma = movingAverage(avgtype, src, fast_len);
fastma.sethiding(!show_avglines);

plot slowma = movingAverage(avgtype, src, slow_len);
slowma.sethiding(!show_avglines);

def maup = fastma crosses above slowma and fastma > slowma;
def madn = fastma crosses below slowma and fastma < slowma;

# Vortex section
input vortex_length = 14;

def trSum = sum(TrueRange(high, close, low), vortex_length);
def "VI+" = if trSum == 0 then 0 else sum(AbsValue(high - low[1]), vortex_length) / trSum;
def "VI-" = if trSum == 0 then 0 else sum(AbsValue(low - high[1]), vortex_length) / trSum;

def vortup = "VI+" crosses above "VI-" and "VI+" > "VI-";
def vortdn = "VI+" crosses below "VI-" and "VI+" < "VI-";

## MACD
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value - Avg;
def zeroline = 0;

plot UpSignal = Diff crosses above ZeroLine ;
upsignal.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
upsignal.setdefaultcolor(color.white);

plot DownSignal = Diff crosses below ZeroLine;
downsignal.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
downsignal.setdefaultcolor(color.white);

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);


## Combined sigs;
def trifecta_up = upsignal and vortup and maup;
plot triup = trifecta_up;
triup.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
triup.setdefaultcolor(color.green);
triup.setlineweight(3);

def trifecta_dn = downsignal and vortdn and madn;
plot tridn = trifecta_dn;
tridn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
tridn.setdefaultcolor(color.red);
tridn.setlineweight(3);

# End

and here is the link:
http://tos.mx/n0hkDEe

I will be honest though, you'll probably need to set more flexible conditions such as letting these indicators fire within a candle or two of each other -- otherwise, it fires extremely rarely. Here's an example of SPX on the 15min, where it only fired once within a 30-day chart:
HEy26aY.png


Is that what you had in mind? I only set it as arrows since you mentioned you wanted an upper indicator, but I did add the option to display the SMAs as well if that may help you stay in a trade.
 
If all you're wanting is crossovers of the SMA, Vortex, and the Upsignal/Downsignal of the MACD, then this should be what you're looking for:

Code:
## Trying the trifecta thingy from twitter

input fast_len = 5;
input slow_len = 13;
input avgtype = averageType.SIMPLE;
input show_avglines = no;
input src = close;

# Moving averages
plot fastma = movingAverage(avgtype, src, fast_len);
fastma.sethiding(!show_avglines);

plot slowma = movingAverage(avgtype, src, slow_len);
slowma.sethiding(!show_avglines);

def maup = fastma crosses above slowma and fastma > slowma;
def madn = fastma crosses below slowma and fastma < slowma;

# Vortex section
input vortex_length = 14;

def trSum = sum(TrueRange(high, close, low), vortex_length);
def "VI+" = if trSum == 0 then 0 else sum(AbsValue(high - low[1]), vortex_length) / trSum;
def "VI-" = if trSum == 0 then 0 else sum(AbsValue(low - high[1]), vortex_length) / trSum;

def vortup = "VI+" crosses above "VI-" and "VI+" > "VI-";
def vortdn = "VI+" crosses below "VI-" and "VI+" < "VI-";

## MACD
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value - Avg;
def zeroline = 0;

plot UpSignal = Diff crosses above ZeroLine ;
upsignal.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
upsignal.setdefaultcolor(color.white);

plot DownSignal = Diff crosses below ZeroLine;
downsignal.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
downsignal.setdefaultcolor(color.white);

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);


## Combined sigs;
def trifecta_up = upsignal and vortup and maup;
plot triup = trifecta_up;
triup.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
triup.setdefaultcolor(color.green);
triup.setlineweight(3);

def trifecta_dn = downsignal and vortdn and madn;
plot tridn = trifecta_dn;
tridn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
tridn.setdefaultcolor(color.red);
tridn.setlineweight(3);

# End

and here is the link:
http://tos.mx/n0hkDEe

I will be honest though, you'll probably need to set more flexible conditions such as letting these indicators fire within a candle or two of each other -- otherwise, it fires extremely rarely. Here's an example of SPX on the 15min, where it only fired once within a 30-day chart:
HEy26aY.png


Is that what you had in mind? I only set it as arrows since you mentioned you wanted an upper indicator, but I did add the option to display the SMAs as well if that may help you stay in a trade.

Awesome! This was exactly what I'd had in mind for an upper indicator! I completely agree with needing to set more flexible conditions for the different indicators to be able to fire within a few candles of each other. Is there a way to set that at 3 candles?
 
Awesome! This was exactly what I'd had in mind for an upper indicator! I completely agree with needing to set more flexible conditions for the different indicators to be able to fire within a few candles of each other. Is there a way to set that at 3 candles?
Sure, this should add a buffer range of candles for each signal, defaulted to 3 -- if say, a MACD crossover and vortex crossover happen any time within a three-candle range, the signal should still fire. one thing you may notice if you look at the code though, is that I didn't add the logic for the MA crossover, which I mainly did because

1. The simple moving averages are the slowest moving aspect of this study, and
2. With that logic added there were a LOT of false signals, even when lowering the buffer to 2.

if you want to change it back, you can -- it's just at the bottom of the code. Or, if you want the study to go back to how conservative the previous version was, just change the buffer value back to 1.

http://tos.mx/vAB7XxF
 
anyway to be able to have this in a watchlist, with a green (buy signal) or red (sell signal) and have a count of number of candles elapsed since signal (time frame can be set, default should be 5 min candles) @Chemmy
 
Last edited:
anyway to be able to have this in a watchlist, with a green (buy signal) or red (sell signal) and have a count of number of candles elapsed since signal (time frame can be set, default should be 5 min candles) @Chemmy
Watchlist Script
Ruby:
# Watchlist Version
## Trying the trifecta thingy from twitter

input fast_len = 5;
input slow_len = 13;
input avgtype = averageType.SIMPLE;
input show_avglines = no;
input src = close;

# Moving averages
plot fastma = movingAverage(avgtype, src, fast_len);
fastma.sethiding(!show_avglines);

plot slowma = movingAverage(avgtype, src, slow_len);
slowma.sethiding(!show_avglines);

def maup = fastma crosses above slowma and fastma > slowma;
def madn = fastma crosses below slowma and fastma < slowma;

# Vortex section
input vortex_length = 14;

def trSum = sum(TrueRange(high, close, low), vortex_length);
def "VI+" = if trSum == 0 then 0 else sum(AbsValue(high - low[1]), vortex_length) / trSum;
def "VI-" = if trSum == 0 then 0 else sum(AbsValue(low - high[1]), vortex_length) / trSum;

def vortup = "VI+" crosses above "VI-" and "VI+" > "VI-";
def vortdn = "VI+" crosses below "VI-" and "VI+" < "VI-";

## MACD
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value - Avg;
def zeroline = 0;

def UpSignal = Diff crosses above ZeroLine ;
def DownSignal = Diff crosses below ZeroLine;

## Combined sigs;
def trifecta_up = upsignal and vortup and maup;
plot triup = trifecta_up;
triup.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
triup.setdefaultcolor(color.blue);
triup.setlineweight(3);

def trifecta_dn = downsignal and vortdn and madn;
plot tridn = trifecta_dn;
tridn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
tridn.setdefaultcolor(color.magenta);
tridn.setlineweight(3);

def bar = barNumber();

def stateUp = trifecta_up;
def stateDn = trifecta_dn;
def transitionBull = stateup[1]==0 and stateup==1;
def transitionBear = statedn[1]==0 and stateDn==1;
def transitionBar = if transitionBull or transitionBear
                    then bar
                    else transitionBar[1];
def BullBar = if transitionBull then bar else if transitionBear then 0 else BullBar[1];
def BearBar = if transitionBear then bar else if transitionBull then 0 else BearBar[1];
def transitionPrice = if bar == HighestAll(transitionBar)
                      then close
                      else transitionPrice[1];

def BullBarsAgo = if bar != BullBar
                 then bar - BullBar
                 else if bar == BullBar
                      then Double.NaN
                 else BullBar[1];
def BearBarsAgo = if bar != BearBar
                 then bar - BearBar
                 else if bar == BearBar
                      then Double.NaN
                 else BearBar[1];



AddLabel(yes,
if BullBar then "Bulls started: " + BullBarsAgo + " bars ago " else
if BearBar then "Bears started: " + BearBarsAgo + " bars ago " else " ");

AssignbackgroundColor(
if BullBar then color.green else
if BearBar then color.red else color.light_gray);


# End
b1dEQGe.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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