How to code one signal per entry / exit

Yo Adrian

New member
I have multiple alerts for both long and short entries. Sometimes when all trigger I get a long string of audio alerts. I'd like to only have one alert per entry.

My code for alerts:
Code:
Alert(UpSignal_A[1], " ", Alert.BAR, Sound.Ding);
Alert(UpSignal_B[1], " ", Alert.BAR, Sound.Ding);
Alert(UpSignal_C[1], " ", Alert.BAR, Sound.Ding);

I tried this with no luck:
Code:
Alert(UpSignal_A[1] or UpSignal_B[1] or UpSignal_C[1], " ", Alert.BAR, Sound.Ding);

I also tried this with no luck:
Code:
Alert(
UpSignal_A[1], " ", Alert.BAR, Sound.Ding
or
Alert(UpSignal_B[1], " ", Alert.BAR, Sound.Ding);
or
Alert(UpSignal_C[1], " ", Alert.BAR, Sound.Ding);
);

Is it a syntax issue or are conditional alerts like this not possible?

Oh, yes sorry about that :) Here's the full script
Code:
input price = close;
input length = 9;
input length2 = 12;
input displace = 0;
input showBreakoutSignals = yes;

plot AvgExp = ExpAverage(price[-displace], length);
plot AvgExp2 = ExpAverage(price[-displace], length2);

def rising = AvgExp[1] < AvgExp[0];
def falling = AvgExp[1] > AvgExp[0];
def rising2 = AvgExp2[1] < AvgExp2[0];
def falling2 = AvgExp2[1] > AvgExp2[0];

plot UpSignal = price crosses above AvgExp and rising and rising2;
plot DownSignal = price crosses below AvgExp and falling and falling2;

plot UpTrend = AvgExp[2] < AvgExp[1] and AvgExp[1] < AvgExp[0];
plot DownTrend = AvgExp[2] > AvgExp[1] and AvgExp[1] > AvgExp[0];

plot BullBreak = close[0] > high[1] and close[0] > high[2] and close[0] > high[3];
plot BearBreak = close[0] < low[1] and close[0] < low[2] and close[0] < low[3];

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

UpTrend.SetDefaultColor(Color.UPTICK);
UpTrend.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownTrend.SetDefaultColor(Color.DOWNTICK);
DownTrend.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

BullBreak.SetDefaultColor(Color.UPTICK);
BullBreak.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BearBreak.SetDefaultColor(Color.DOWNTICK);
BearBreak.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Alert(UpSignal[1], " ", Alert.BAR, Sound.Ding);
Alert(DownSignal[1], " ", Alert.BAR, Sound.Ding);
Alert(UpTrend[1], " ", Alert.BAR, Sound.Ding);
Alert(DownTrend[1], " ", Alert.BAR, Sound.Ding);
Alert(BullBreak[1], " ", Alert.BAR, Sound.Ding);
Alert(BearBreak[1], " ", Alert.BAR, Sound.Ding);
 
Last edited by a moderator:
I have multiple alerts for both long and short entries. Sometimes when all trigger I get a long string of audio alerts. I'd like to only have one alert per entry.

Your signals occur on every bar therefore you will be alerted on every bar.
SQBkfpM.png
NFM6ulU.png

Less signals == less alerts.
Use of a recursive statement will find the 1st and last signals of your trend:
Ruby:
input price = close;
input length = 9;
input length2 = 12;

plot AvgExp = ExpAverage(price, length);
plot AvgExp2 = ExpAverage(price, length2);

def rising = AvgExp[1] < AvgExp[0];
def falling = AvgExp[1] > AvgExp[0];
def rising2 = AvgExp2[1] < AvgExp2[0];
def falling2 = AvgExp2[1] > AvgExp2[0];

def UpSignal = price crosses above AvgExp and rising and rising2;
def DownSignal = price crosses below AvgExp and falling and falling2;

def UpTrend = AvgExp[2] < AvgExp[1] and AvgExp[1] < AvgExp[0];
def DownTrend = AvgExp[2] > AvgExp[1] and AvgExp[1] > AvgExp[0];

def BullBreak = close[0] > high[1] and close[0] > high[2] and close[0] > high[3];
def BearBreak = close[0] < low[1] and close[0] < low[2] and close[0] < low[3];

def once_per_entry =
if UpSignal or UpTrend or BullBreak then 1 else
if DownSignal or DownTrend or BullBreak then 0 else once_per_entry[1] ;

plot UpTrigger = once_per_entry and !once_per_entry[1];
     UpTrigger.SetDefaultColor(Color.UPTICK);
     UpTrigger.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot DnTrigger = once_per_entry[1] and !once_per_entry;
     DnTrigger.SetDefaultColor(Color.DOWNTICK);
     DnTrigger.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Alert(UpTrigger[1], " ", Alert.BAR, Sound.Ding);
Alert(DnTrigger[1], " ", Alert.BAR, Sound.Ding);

An even better choice is to use @JoeDV's P&L snippet at the end of all your studies.
https://usethinkscript.com/threads/backtesting-a-tos-strategy.10942/#post-119884
It will limit your signals to once per entry / exit AND will highlight why this could be an unprofitable strategy.
 

Attachments

  • SQBkfpM.png
    SQBkfpM.png
    79.6 KB · Views: 225
Last edited:

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
347 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