Indicator That Triggers Off Another Indicator

a1cturner

Well-known member
I have been working on this indicator for a while and I never could figure out my sell signal. Now I have that figured out and but I am getting too many plots.

What I want: When the up arrow fires, wait until the MACD trends down and then fire another indicator. Vice versa, when the down arrow fires, wait until the MACD trends up and then fire another indicator.

I have the indicators working as planned but there are just too many! If I get a down arrow and buy puts, I will exit on the first red dot. The problem is that the red dots keep plotting every candle until MACD reverses the other direction. At that point I have usually already had an arrow up to buy calls at which point I am waiting on a red dot to exit.

This is what I would like... If ArrowUp5 is true with 150 bars and MACDDiff < MACDDiff[1] then -25 (but then don't plot again until you get the ArrowUp5 again)
Vice Versa on ArrowDN5..

I have posted the entire code further below. Don't worry about anything except ArrowUp 6 and ArrowDN6

#################### PART I NEED HELP WITH #########################

Plot ArrowUp6 = if (ArrowUp5 is true within 125 bars) and (MACDDiff < MACDDiff[1]) then 25 else double.nan;
ArrowUp6.SetPaintingStrategy(PaintingStrategy.points);
ArrowUp6.SetLineWeight(5);
ArrowUp6.SetDefaultColor(color.red);

Plot ArrowDN6 = if (ArrowDN5 is true within 125 bars) and MACDDiff > MACDDiff[1] then -25 else double.nan;
ArrowDN6.SetPaintingStrategy(PaintingStrategy.points);
ArrowDN6.SetLineWeight(5);
ArrowDN6.SetDefaultColor(color.red);

FnHntlR.png


######################### ENTIRE CODE ##############################

#JT MOMENTUM CHANGE INDICATOR

#USED TO IDENTIFY SHORT REVERSALS IN LONGER TRENDS FOR SCALPS OR DAY TRADES ONLY.
#USE ON 1 MINUTE CHART ONLY BUT IN CONJUNCTION WITH 10 MINUTE CHART.
#I USE 5/12 AND 34/50 EMA CLOUDS ON MY 10 MINUTE CHART ALONG WITH A FASTER MACD (10, 22, 8) AND RSI.

#ONCE THE INDICATOR IS TRIGGERED WITH ARROW UP I WILL SUBMIT A 50ish DELTA CALL, 10% TRAILING STOP, BUY ORDER, ON THE BID.
#ONCE THE INDICATOR IS TRIGGERED WITH ARROW DOWN I WILL SUBMIT A 50ish DELTA PUT, 10% TRAILING STOP, BUY ORDER, ON THE BID.

#ALWAYS LOOK AT THE VOLUME OF THE OPTION YOU ARE BUYING!#

#PLAY STOCKS THAT YOU KNOW WHERE SUPPORT/RESISTANCE ARE IF POSSIBLE#

#IF THE SIGNAL STOPS BEFORE YOUR BUY TRIGGERS THAN CANCEL THE ORDER AND MOVE ON TO THE NEXT OPPURTUNITY#

#EXIT IS YOUR PREFERENCE BUT I WATCH THE 10 MINUTE 5/12 EMA CLOUD, MACD, VOLUME ETC TO TIME MY EXIT.
#I AM ALSO COMFORTABLE WITH A 50% LOSS BECAUSE I BELIEVE THAT I CAN ACHIEVE A 100% GAIN MORE OFTEN THAN NOT.
#IF I AM BEING CONSERVAITVE THOUGH I WILL WATCH FOR THE PRICE TO EXTEND SIGNIFICANTLY FROM THE 5/12 EMA AND THEN SET A 10%-15% TRAILING SELL ORDER ON THE ASK.

declare lower;

input MovAvg = AverageType.EXPONENTIAL;
input TSITimeShort = aggregationPeriod.MIN;
input TSITimeLong = aggregationPeriod.TEN_MIN;
input EMATime = aggregationPeriod.TEN_MIN;
input MACDTime = aggregationPeriod.TEN_MIN;
input TSILongLength = 34;
input TSIShortLength = 5;
input TSISignalLength = 5;
input EMAFast1 = 5;
input EMAFast2 = 12;
input EMASlow1 = 34;
input EMASlow2 = 50;
input MACDFast = 10;
input MACDSlow = 22;
input MACDLength = 8;
input Symbol = "VIX";

#CLOSE
def TSICloseShort = close(period=TSITimeShort);
def TSICloseLong = close(period=TSITimeLong);
def EMAClose = close(period=EMATime);
def MACDClose = close(period=MACDTime);
def Data = close(Symbol, period=EMATime);

#TRUE STENGTH INDEX(TSI)
def DiffShort = TSICloseShort - TSICloseShort[1];
def DiffLong = TSICloseLong - TSICloseLong[1];
def DoubleSmoothedAbsDiffShort = MovingAverage(MovAvg, MovingAverage(MovAvg, AbsValue(diffShort), TSILongLength), TSIShortLength);
def DoubleSmoothedAbsDiffLong = MovingAverage(MovAvg, MovingAverage(MovAvg, AbsValue(diffLong), TSILongLength), TSIShortLength);

#TSI 1 Min
plot TSIShort;
plot SignalShort;

TSIShort = if DoubleSmoothedAbsDiffShort == 0 then 0
else 100 * (MovingAverage(MovAvg, MovingAverage(MovAvg, DiffShort, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiffShort;
SignalShort = MovingAverage(MovAvg, TSIShort, TSISignalLength);

def ZeroLine2 = 0;

TSIShort.SetDefaultColor(GetColor(1));
SignalShort.SetDefaultColor(GetColor(8));
SignalShort.hide();

plot HighLvl1 = 25;
HighLvl1.setDefaultColor(color.dark_green);
HighLvl1.hidebubble();
HighLvl1.hidetitle();

plot LowLvl1 = -25;
LowLvl1.setDefaultColor(color.dark_red);
LowLvl1.hidebubble();
LowLvl1.hidetitle();

#TSI 10 Min
def TSILong;
def SignalLong;

TSILong = if DoubleSmoothedAbsDiffLong == 0 then 0
else 100 * (MovingAverage(MovAvg, MovingAverage(MovAvg, DiffLong, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiffLong;
SignalLong = MovingAverage(MovAvg, TSILong, TSISignalLength);

def ZeroLine1 = 0;

#EMAs
def EMA1 = MovingAverage(MovAvg, EMAClose, EMAFast1);
def EMA2 = MovingAverage(MovAvg, EMAClose, EMAFast2);
def EMA3 = MovingAverage(MovAvg, EMAClose, EMASlow1);
def EMA4 = MovingAverage(MovAvg, EMAClose, EMASlow2);
def CompareEMA1 = MovingAverage(MovAvg, Data, EMAFast1);
def CompareEMA2 = MovingAverage(MovAvg, Data, EMAFast2);

#EMA PERCENT
def EMApct = ((ema1 / ema2)*100)-100;
plot EMApctRound = round(EMApct, 2);

#MACD
def MACD = MovingAverage(MovAvg, MACDClose, MACDFast) -
MovingAverage(MovAvg, MACDClose, MACDSlow);
def MACDVar = MovingAverage(MovAvg, MACD, MACDLength);
def MACDDiff = round((MACD - MACDVar), 4);

#GET READY INDICATOR
Plot ArrowUp1 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort between -18 and -24.99) and (EMA1>EMA2) and (EMA3>EMA4) and (MACDDiff > 0) and (CompareEMA1 < CompareEMA2)
then -25
else double.nan;
#Arrowup1.SetPaintingStrategy(PaintingStrategy.arrow_up);
#ArrowUp1.SetLineWeight(2);
#ArrowUp1.SetDefaultColor(Color.violet);
plot ArrowDN1 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort between 18 and 24.99) and (EMA1<EMA2) and (EMA3<EMA4) and (MACDDiff < 0) and (CompareEMA1 > CompareEMA2)
then 25
else double.nan;
#ArrowDN1.SetPaintingStrategy(PaintingStrategy.arrow_down);
#ArrowDN1.SetLineWeight(2);
#ArrowDN1.SetDefaultColor(Color.violet);

#AddChartBubble(ArrowUp1, -25, "Call*", color.violet, no);
#AddChartBubble(ArrowDN1, 25, "Put*", color.violet, yes);

#BUY INDICATOR
Plot ArrowUp2 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort < -25) and (EMA1>EMA2) and (EMA3>EMA4) and (MACDDiff > 0) and (CompareEMA1 < CompareEMA2)
then -25
else double.nan;
#Arrowup2.SetPaintingStrategy(PaintingStrategy.arrow_up);
#ArrowUp2.SetLineWeight(2);
#ArrowUp2.SetDefaultColor(Color.green);
plot ArrowDN2 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort > 25) and (EMA1<EMA2) and (EMA3<EMA4) and (MACDDiff < 0) and (CompareEMA1 > CompareEMA2)
then 25
else double.nan;
#ArrowDN2.SetPaintingStrategy(PaintingStrategy.arrow_down);
#ArrowDN2.SetLineWeight(2);
#ArrowDN2.SetDefaultColor(Color.green);

#AddChartBubble(ArrowUp2, -25, "Call", color.green, no);
#AddChartBubble(ArrowDN2, 25, "Put", color.green, yes);

#AGAINST MARKET TREND
Plot ArrowUp3 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort between -18 and -24.99) and (EMA1>EMA2) and (EMA3>EMA4) and (MACDDiff > 0) and (CompareEMA1 > CompareEMA2)
then -25
else double.nan;
#Arrowup3.SetPaintingStrategy(PaintingStrategy.arrow_up);
#ArrowUp3.SetLineWeight(2);
#ArrowUp3.SetDefaultColor(Color.orange);
plot ArrowDN3 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort between 18 and 24.99) and (EMA1<EMA2) and (EMA3<EMA4) and (MACDDiff < 0) and (CompareEMA1 < CompareEMA2)
then 25
else double.nan;
#ArrowDN3.SetPaintingStrategy(PaintingStrategy.arrow_down);
#ArrowDN3.SetLineWeight(2);
#ArrowDN3.SetDefaultColor(Color.orange);

#AddChartBubble(ArrowUp3, -25, "X-Call*", color.orange, no);
#AddChartBubble(ArrowDN3, 25, "X-Put*", color.orange, yes);

#AGAINST MARKET TREND2
Plot ArrowUp4 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort <-25) and (EMA1>EMA2) and (EMA3>EMA4) and (MACDDiff > 0) and (CompareEMA1 > CompareEMA2)
then -25
else double.nan;
#Arrowup4.SetPaintingStrategy(PaintingStrategy.arrow_up);
#ArrowUp4.SetLineWeight(2);
#ArrowUp4.SetDefaultColor(Color.red);
plot ArrowDN4 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1300.0) < 10800) and (TSIShort >25) and (EMA1<EMA2) and (EMA3<EMA4) and (MACDDiff < 0) and (CompareEMA1 < CompareEMA2)
then 25
else double.nan;
#ArrowDN4.SetPaintingStrategy(PaintingStrategy.arrow_down);
#ArrowDN4.SetLineWeight(2);
#ArrowDN4.SetDefaultColor(Color.red);

#AddChartBubble(ArrowUp4, -25, "X-Call", color.red, no);
#AddChartBubble(ArrowDN4, 25, "X-Put", color.red, yes);

#TEST
Plot ArrowUp5 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1545.0) < 0) and (TSIShort > TSIShort[1]) and (EMAPctRound > EMAPctRound[1]) and (MACDDiff > MACDDiff[1]) and (CompareEMA1 < CompareEMA2) then -25 else double.nan;
ArrowUp5.SetPaintingStrategy(PaintingStrategy.arrow_up);
ArrowUp5.SetLineWeight(2);
ArrowUp5.SetDefaultColor(color.pink);

Plot ArrowUp6 = if (ArrowUp5 is true within 125 bars) and (MACDDiff < MACDDiff[1]) then 25 else double.nan;
ArrowUp6.SetPaintingStrategy(PaintingStrategy.points);
ArrowUp6.SetLineWeight(5);
ArrowUp6.SetDefaultColor(color.red);

#TEST
Plot ArrowDN5 = if (secondsfromtime (1000.0) > 0) and (secondsfromtime (1545.0) < 0) and (TSIShort < TSIShort[1]) and (EMAPctRound < EMAPctRound[1]) and (MACDDiff < MACDDiff[1]) and (CompareEMA1 > CompareEMA2) then 25 else double.nan;
ArrowDN5.SetPaintingStrategy(PaintingStrategy.arrow_down);
ArrowDN5.SetLineWeight(2);
ArrowDN5.SetDefaultColor(color.pink);

Plot ArrowDN6 = if (secondsfromtime (1000.0) > 0) and (ArrowDN5 is true within 125 bars) and MACDDiff > MACDDiff[1] then -25 else double.nan;
ArrowDN6.SetPaintingStrategy(PaintingStrategy.points);
ArrowDN6.SetLineWeight(5);
ArrowDN6.SetDefaultColor(color.red);

#SCANNER
#CALL SCANNER
#http://tos.mx/Q8TQIeB
#PUT SCANNER
#http://tos.mx/GXBvdf0
 
Last edited:
Tried defining my sell signals first but that didn't work.


#Attempt 1
def SellSignal = if (ArrowUp5 is true within 125 bars) and (MACDDiff < MACDDiff[1]) then 25 else double.nan;
Plot ArrowUp6 = if SellSignal and !SellSignal[1] then 25 else double.nan;
ArrowUp6.SetPaintingStrategy(PaintingStrategy.points);
ArrowUp6.SetLineWeight(5);
ArrowUp6.SetDefaultColor(color.red);

#Attempt 2
def SellSignal = if (ArrowUp5 is true within 125 bars) and (MACDDiff < MACDDiff[1]) then 25 else double.nan;
Plot ArrowUp6 = if SellSignal is true and SellSignal[1] is false then 25 else double.nan;
ArrowUp6.SetPaintingStrategy(PaintingStrategy.points);
ArrowUp6.SetLineWeight(5);
ArrowUp6.SetDefaultColor(color.red);

#Attempt 3
def SellPut = ((secondsfromtime (1000.0) > 0) and (secondsfromtime (1600.0) < 0) and (ArrowDN5 is true within 125 bars) and (MACDDiff > MACDDiff[1]));
def SellPut2 = if (SellPut is true and SellPut[1] is false) then 1 else if (SellPut is true and SellPut[1] is true) then 0 else 0;
Plot ArrowDN6 = if SellPut2 then -25 else double.nan;
ArrowDN6.SetPaintingStrategy(PaintingStrategy.points);
ArrowDN6.SetLineWeight(5);
ArrowDN6.SetDefaultColor(color.red);
 
Last edited:
I figured it out. Since I am using MTF of 1 minute and 10 minute I had to exchange the [1] for [10] so instead of:
Plot ArrowUp6 = if SellSignal and !SellSignal[1] then 25 else double.nan;
I had to instead input:
Plot ArrowUp6 = if SellSignal and !SellSignal[10] then 25 else double.nan;

That got rid of any red dots that were within one 10 minute bar of another red dot which was most of them.

It would be great if someone had a little bit better way where I only get one sell signal (red dot) after a buy signal (Call or Put) until the next entry signal (Call or Put) but it's good enough for me as it is now.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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