# Indicator for when two conditions are met

#### Jack Sprat

##### New member
Hi!
I was trying to write a strategy that would give some sort of indication (vertical line, up/down arrow) when two conditions were met. What I have so far is :

addverticalLine( if price_trend crosses above 0 then high else double.nan);
addverticalLine( if price_trend crosses below 0 then low else double.nan);
addverticalLine( if up[1] < 1 and up > 0 then low else Double.NaN);
addverticalLine( if down[1] < 1 and down > 0 then high else Double.NaN);

What I would like is a line or arrow when both addverticalLine( if price_trend crosses above 0 then high else double.nan); and addverticalLine( if up[1] < 1 and up > 0 then low else Double.NaN); happen and then conversely when both addverticalLine( if price_trend crosses below 0 then low else double.nan); and addverticalLine( if down[1] < 1 and down > 0 then high else Double.NaN); happen.

I've been trying various things all day but the combinations I was coming up were still missing like half the signals. Any help would be greatly appreciated!

Thanks

Solution
you are using addverticalline() incorrectly.
it wants 4 parameters. you are giving it 1 and of the wrong data type.
i think, if you provide 1 parameter to a function, without the parameter name, it is assumed to be the first one. the first parameter is supposed to be true/false , to trigger it during a point in time, during a candle.
your formula results in a price value.

your code doesn't include what price_trend or up or down are , so they may be another problem.
i guessed that up and down are 2 conditions.

what i would do,
...add a formula to define price_trend , as a true/false value
...define variables for each condition that are true/false
...use those variable names as the 1st parameter in addverticalline( )

this won't work...
you are using addverticalline() incorrectly.
it wants 4 parameters. you are giving it 1 and of the wrong data type.
i think, if you provide 1 parameter to a function, without the parameter name, it is assumed to be the first one. the first parameter is supposed to be true/false , to trigger it during a point in time, during a candle.
your formula results in a price value.

your code doesn't include what price_trend or up or down are , so they may be another problem.
i guessed that up and down are 2 conditions.

what i would do,
...add a formula to define price_trend , as a true/false value
...define variables for each condition that are true/false
...use those variable names as the 1st parameter in addverticalline( )

this won't work until a formula for price_trend is added.

Code:
``````def price_trend = ?
def up = if price_trend crosses above 0 then 1 else 0;
def down = if price_trend crosses below 0 then 1 else 0;

# these are redundant, same as up and down
def cond1 = if up[1] == 0 and up == 1 then 1 else 0;
def cond2 = if down[1] == 0 and down == 1 then 1 else 0;

# the 4th parameter is line type. it can be left out
addverticalline( up, "UP", color.green );
addverticalline( down, "DOWN", color.red );``````

Great, thank you for your reply and explaining it for me. This is my first time trying to write an indicator so I'm still trying to figure it out. I appreciate the example and I'll see what I can work out!
Thanks

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
231 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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.