Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:04:48+00:00 2026-06-18T09:04:48+00:00

I am writing a program that identifies patterns in stock market data and I

  • 0

I am writing a program that identifies patterns in stock market data and I am trying to identify the following short term pattern:

if the the low value is less than the open value by at least 3 and the close value is within 2 of the open value.

I am reading in the values from a CSV file in the following format but without the headers:

Open    High    Low     Close
353.4   359.2   347.7   349
351.4   354.08  349.1   353.1
350.1   354     349.3   350.2
352.4   353.28  348.7   349.8
345.7   352.3   345.7   351.5

The values are stored in float arraylists called closePrice, openPrice, lowPrice. I am calculating the
This is the code I have wrote to try and identify the pattern within the data.

    for(int i = 0; i < closePrice.size(); i ++)
    {
        //Difference between opening price and the price low
        float priceDrop = Math.abs(openPrice.get(i) - lowPrice.get(i));
        //Difference between opening price and close price (regardless of positive or negative)
        float closingDiff = Math.abs(openPrice.get(i) - closePrice.get(i));

        float dropTolerance = 3.0f;
        float closingTolerance = 2.0f;

        if( (priceDrop > dropTolerance) || (closingDiff < closingTolerance) )
        {
            System.out.println("price drop = " + priceDrop + " closing diff = " + closingDiff);
            System.out.println("Hangman pattern" + "\n");
        }
    }

So what it should do is test if the price drops more than 3 and then the closing price is within 2 of the opening price however when I run the program it seems to let everything bypass the if statement. My output is:

price drop = 5.6999817 closing diff = 4.399994
Hangman pattern
price drop = 2.2999878 closing diff = 1.7000122
Hangman pattern
price drop = 0.8000183 closing diff = 0.1000061
Hangman pattern

Is it because I am comparing floats? Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:04:49+00:00Added an answer on June 18, 2026 at 9:04 am

    It looks like you’ve confused the AND operator and the OR operator.

    You state you only want to output if both conditions are met, but your code says you will output if either condition is met.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read data from an online XML file. The
I'm new to C but trying some system calls. I'm writing program that iterates
I'm writing a program that reads and processes large amounts of data. To speed
Im writing a program that should read input via stdin, so I have the
I'm writing a program that handles DBs and writes any changes into ListView for
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting
I am writing a program that permutes a list of names based on a
I'm writing a program that lets the user input 6 temperature readings, and then
I am writing a program that downloads images to the hard drive and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.