Study alert with costume code not working

fabriciom

New member
I'm having trouble creating a study alert with costume code.

I'm trying to create and alert that fires when a full candle crosses a study value.

Problem is that I can't seem to get script code that works in a study work in the alarm code.

Any clues?

Thanks
 
Solution
so, without much more to go on, I'll assume you want a full candle (wicks and all) to be above a simple moving average (or below):

Code:
def MA = SimpleMovingAvg(price = CLOSE, length = 25);
def up_condition = if LOW crosses above MA then 1 else 0;
def dn_condition = if HIGH crosses below MA then 1 else 0;
Alert(condition = up_condition or dn_condition, text = "Full Candle Cleared MA", Alert.BAR, Sound.Chimes));

perhaps that will get you moving in the direction you want.

-mashume
so, without much more to go on, I'll assume you want a full candle (wicks and all) to be above a simple moving average (or below):

Code:
def MA = SimpleMovingAvg(price = CLOSE, length = 25);
def up_condition = if LOW crosses above MA then 1 else 0;
def dn_condition = if HIGH crosses below MA then 1 else 0;
Alert(condition = up_condition or dn_condition, text = "Full Candle Cleared MA", Alert.BAR, Sound.Chimes));

perhaps that will get you moving in the direction you want.

-mashume
 
Solution
so, without much more to go on, I'll assume you want a full candle (wicks and all) to be above a simple moving average (or below):

Code:
def MA = SimpleMovingAvg(price = CLOSE, length = 25);
def up_condition = if LOW crosses above MA then 1 else 0;
def dn_condition = if HIGH crosses below MA then 1 else 0;
Alert(condition = up_condition or dn_condition, text = "Full Candle Cleared MA", Alert.BAR, Sound.Chimes));

perhaps that will get you moving in the direction you want.

-mashume

Hi,

Thanks for the reply.

When I open my study alert I find this code I created with the wizard:

close crosses BasicHull("length" = 120)

How would I go about using your code? If I throw the Alert() function in there would it work? Or do I need to create a separate study?

I would like to use the Study Alert route because I can setup different chart time spaces. For example, I have an alert for 30m, 1h, and 4h.

Thanks.

Update:
Tried the following code but no go:

def MA = BasicHull("length" = 120);
def up_condition = if LOW crosses above MA then 1 else 0;
def dn_condition = if HIGH crosses below MA then 1 else 0;
up_condition OR dn_condition
 
Last edited:
Make a new study. Put this code in it:
Code:
declare upper;
def MA = HullMovingAvg(price = CLOSE, length = 120);
def up_condition = if LOW crosses above MA then 1 else 0;
def dn_condition = if HIGH crosses below MA then 1 else 0;
Alert(condition = up_condition == 1 OR dn_condition == 1, text = "Full Candle Cleared MA", Alert.BAR, Sound.Chimes));
then make sure it is running on each of your timeframe charts (add it to the studies for that chart) and you should be in business.
(or not... I'm not in ToS at the moment, just here in a text editor.)

Note that I've used LOW crossing above and HIGH crossing below rather than CLOSE crossing, as that's how we define that the whole candle has moved above (or below) the moving average.

mashume
 
Make a new study. Put this code in it:
Code:
declare upper;
def MA = HullMovingAvg(price = CLOSE, length = 120);
def up_condition = if LOW crosses above MA then 1 else 0;
def dn_condition = if HIGH crosses below MA then 1 else 0;
Alert(condition = up_condition == 1 OR dn_condition == 1, text = "Full Candle Cleared MA", Alert.BAR, Sound.Chimes));
then make sure it is running on each of your timeframe charts (add it to the studies for that chart) and you should be in business.
(or not... I'm not in ToS at the moment, just here in a text editor.)

Note that I've used LOW crossing above and HIGH crossing below rather than CLOSE crossing, as that's how we define that the whole candle has moved above (or below) the moving average.

mashume

Hello again!

Thank you for your help. With the info you provided I was able to come up with the following code that works.

high crosses below BasicHull("length" = 120) or low crosses above BasicHull("length" = 120)

Thanks for your help friend!
 
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
418 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