Vertical Lines Peaks Alerts

baTrader

New member
I've tried many different ways to get alerts to trigger on OSpeakTrigger and OBpeakTrigger but have been unsuccessful. I feel like I must be missing something. Obviously I'm getting the verticals, so obviously the condition is true, but the alert isn't audible. Seems it may have something to do with the parameter SlowK[-1]. Can someone please help me? Is there a fix for this? Thanks!


Code:
declare upper;

#########################################################
# Parameters
input overBought = 75;
input overSold = 25;

input KPeriod = 5;
input DPeriod = 3;
input averageType = AverageType.EXPONENTIAL;

#** Oversold trigger on/off
input useOsPeakTrigger = yes;
#** Overbought triger on/off
input useObPeakTrigger = yes;

#########################################################
# Triggers
def SlowK = reference StochasticFull(overBought, overSold, KPeriod, DPeriod, high, low, close, 3, averageType).FullK;

def OSpeakTrigger = if useOsPeakTrigger and (SlowK <= overSold) and (SlowK < SlowK[-1]) and (SlowK < SlowK[1]) then 1 else 0;

def OBpeakTrigger = if useObPeakTrigger and (slowK >= overBought) and (slowK > slowK[-1]) and (slowK > slowK[1]) then 1 else 0;

#########################################################
# Vertical Lines
AddVerticalLine(OSpeakTrigger, "", Color.Green, Curve.LONG_DASH);
AddVerticalLine(OBpeakTrigger, "", Color.Red, Curve.LONG_DASH);

###################################################################################
# Alert Settings
input useAlert = yes;
input alertType = {default "BAR", "ONCE", "TICK"};
input alertText = "VERT PEAK ALERT!";
input alertSound = {"Bell", "Chimes", "Ding", "NoSound",default "Ring"};

def AT = alertType;

Alert(useAlert and OSpeakTrigger, alertText, if AT == 1 then Alert.ONCE else if AT == 2 then Alert.TICK else Alert.BAR, alertSound);
Alert(useAlert and OBpeakTrigger, alertText, if AT == 1 then Alert.ONCE else if AT == 2 then Alert.TICK else Alert.BAR, alertSound);
###################################################################################
VerticalLinesAlerts.jpg
 
Last edited:
I've tried many different ways to get alerts to trigger on OSpeakTrigger and OBpeakTrigger but have been unsuccessful. I feel like I must be missing something. Obviously I'm getting the verticals, so obviously the condition is true, but the alert isn't audible. Seems it may have something to do with the parameter SlowK[-1]. Can someone please help me? Is there a fix for this? Thanks!


Code:
declare upper;

#########################################################
# Parameters
input overBought = 75;
input overSold = 25;

input KPeriod = 5;
input DPeriod = 3;
input averageType = AverageType.EXPONENTIAL;

#** Oversold trigger on/off
input useOsPeakTrigger = yes;
#** Overbought triger on/off
input useObPeakTrigger = yes;

#########################################################
# Triggers
def SlowK = reference StochasticFull(overBought, overSold, KPeriod, DPeriod, high, low, close, 3, averageType).FullK;

def OSpeakTrigger = if useOsPeakTrigger and (SlowK <= overSold) and (SlowK < SlowK[-1]) and (SlowK < SlowK[1]) then 1 else 0;

def OBpeakTrigger = if useObPeakTrigger and (slowK >= overBought) and (slowK > slowK[-1]) and (slowK > slowK[1]) then 1 else 0;

#########################################################
# Vertical Lines
AddVerticalLine(OSpeakTrigger, "", Color.Green, Curve.LONG_DASH);
AddVerticalLine(OBpeakTrigger, "", Color.Red, Curve.LONG_DASH);

###################################################################################
# Alert Settings
input useAlert = yes;
input alertType = {default "BAR", "ONCE", "TICK"};
input alertText = "VERT PEAK ALERT!";
input alertSound = {"Bell", "Chimes", "Ding", "NoSound",default "Ring"};

def AT = alertType;

Alert(useAlert and OSpeakTrigger, alertText, if AT == 1 then Alert.ONCE else if AT == 2 then Alert.TICK else Alert.BAR, alertSound);
Alert(useAlert and OBpeakTrigger, alertText, if AT == 1 then Alert.ONCE else if AT == 2 then Alert.TICK else Alert.BAR, alertSound);
###################################################################################
View attachment 20815

Yes, you are correct, the culprit is:
SlowK[-1]

Your code is looking if the current bar is lesser (or is greater) than the bar that occurs next.
The bar that occurs next after the current bar has not happened yet.
So your script does not work in real time. If waits until the future and then goes back in time and repaints a vertical line.

Alerts are real time. Repainted verticals are not.
You can attempt to go back in time and capture the alert by changing:
Alert(useAlert and OSpeakTrigger
Alert(useAlert and OBpeakTrigger
to:
Alert(useAlert and OSpeakTrigger within 3 bars
Alert(useAlert and OBpeakTrigger within 3 bars

Most scalpers will not use future bar repainting scripts such as this one, because the 2-3 bars delay in alerting is not profitable.
 
Last edited:

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

Yes, you are correct, the culprit is:


Your code is looking if the current bar is lesser (or is greater) than the bar that occurs next.
The bar that occurs next after the current bar has not happened yet.
So your script does not work in real time. If waits until the future and then goes back in time and repaints a vertical line.

Alerts are real time. Repainted verticals are not.
You can attempt to go back in time and capture the alert by changing:

to:


Most scalpers will not use future bar repainting scripts such as this one, because the 2-3 bars delay in alerting is not profitable.

Tried that but it didn't work. Any other way to potentially get that alert, or identify the peak without using SlowK[-1]? Thanks
 
Tried that but it didn't work. Any other way to potentially get that alert, or identify the peak without using SlowK[-1]? Thanks
As explained before, attempting to scan, watchlist, or alert on repainters is an exercise in futility.
No, the essence of the script relies on the future bars: SlowK[-1].
The future bars are why the script looks so deceptively perfect.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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