Test the High if equal to $XX.50

I want to test the high price of a stock true if any dollar number but not true if after the decimal it is not $xx.50

so $10.50 is true
but $10.49 and $10.51 is not true

so $11.50 is true
but $11.49 and $11.51 is not true

etc...

and same for all dollar numbers

dollars are a variable but the fraction is a user defined number.
 
Solution
OK.

Code:
declare lower;

def cents = high % 1;
plot TwoBitMultiples = if cents == 0.25 or cents == 0.50 or cents == 0.75 then 1 else 0;

I moved the modulo arithmetic out of the comparison for efficiency. calculate once, compare many is more efficient.

as to what constitutes a 1 or a zero, 1 is usually true and 0 is false. Your original post asked:
...stock true if any dollar number
so I made everything 1 unless it wasn't at the half-dollar mark.
your statement
but not true if after the decimal it is not $xx.50
contains a double negative and is therefore ambiguous, so I took the first part (which is clear) and used that as the basis for what was 1 and what was zero. :)

This version makes more sense to my head...
Code:
declare lower;

plot NotFourBits = if high % 1 == 0.5 then 0 else 1;

this uses modulo arithmetic to look at the remainder. Anything divided by itself will leave only the decimal portion of the number. We then compare that to 0.5 and return 1 (true) if it is not equal and 0 (false) if it is true. (that statement makes my head hurt)

-mashume
 
this works perfect

great now if I try to add several user inputs such as 0.5 or 0.25 or 0.75 I get an unexpected result the whole line is 1 never any zero.
declare lower;

input PsychoNumber1 = 0.5;
input PsychoNumber2 = 0.25;
input PsychoNumber3 = 0.75;

plot PsychologicalNumbers = if high % 1 == (PsychoNumber1 or PsychoNumber1 or PsychoNumber1) then 1 else 0;

this code produces a straight line at 1. I expect it to produce zero and only one if the decimals are 0.5 or 0.25 or 0.75

am I not combining the Or statement properly? should there be an And/Or type of statement instead? I can't find the syntax that works here.
 
OK.

Code:
declare lower;

def cents = high % 1;
plot TwoBitMultiples = if cents == 0.25 or cents == 0.50 or cents == 0.75 then 1 else 0;

I moved the modulo arithmetic out of the comparison for efficiency. calculate once, compare many is more efficient.

as to what constitutes a 1 or a zero, 1 is usually true and 0 is false. Your original post asked:
...stock true if any dollar number
so I made everything 1 unless it wasn't at the half-dollar mark.
your statement
but not true if after the decimal it is not $xx.50
contains a double negative and is therefore ambiguous, so I took the first part (which is clear) and used that as the basis for what was 1 and what was zero. :)

This version makes more sense to my head, where a value at $0.25 multiples excluding the round dollar is true and everything else is false.
If it plots a straight line, then the chart has nothing that is exactly on the quarters. Look at something like /es and it'll ALL be true, since the tick size there is 0.25.

-mashume
 
Solution

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