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 9091483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:37:17+00:00 2026-06-16T22:37:17+00:00

I am writing a java program to attempt to identify trends in the stock

  • 0

I am writing a java program to attempt to identify trends in the stock market and I want to identify the following pattern:

Where EMA value drops below SMA by over approx. 0.7% (Day 1), you can look for 0.2%-0.5% fluctuations (changes in the relationship between SMA & EMA up or down) between the two for the next 2-3 days. This indicates sell signal.

I have an array of float values for the EMA and SMA and then I have a separate float array called percentDif that contains the percentage difference between the EMA and SMA. For example these are the the first two sets of values for the EMA, SMA and percentDif arrays

EMA 314.395         SMA 314.9859884       percentDif -0.001876237
EMA 313.9476        SMA 314.4888908        percentDif -0.001721176

I have wrote this method to identify the pattern that I want but it is not working correctly, is there a better way that I can do this?

public void trend(){

    /*
     * Trend indicator pattern
     */
    float valueDrop = -0.7f;

    float minFluxPos = 0.2f;
    float maxFluxPos = 0.5f;

    float minFluxNeg = -0.2f;
    float maxFluxNeg = -0.5f;

    for(int i = 0; i< percentDif.length-2; i++)
    {
        //If the difference between EMA and SMA is greater or equal to -0.7 percent
        if(percentDif[i] >= valueDrop){
            //If the next day the percentage difference fluctuates between 0.2 or 0.5 either way
            if( ((percentDif[i+1] > minFluxPos) && (percentDif[i+1] < maxFluxPos))
                    || ((percentDif[i+1] > minFluxNeg) && (percentDif[i+1] < maxFluxNeg)) )
            {
                //Indicates price drop and therefore sell signal
                System.out.println("Trend Indicated - SELL");
            }
        }
    }
}

I have entered the following values in the percentDif array :
5
-0.8
-0.3

These values fit the description of the pattern and should therefore trigger the print statement but it is not doing so.

  • 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-16T22:37:18+00:00Added an answer on June 16, 2026 at 10:37 pm

    You have the comparison operators the wrong way round for the negative flux values. The if statement should be:

    if( ((percentDif[i+1] > minFluxPos) && (percentDif[i+1] < maxFluxPos))
                    || ((percentDif[i+1] < minFluxNeg) && (percentDif[i+1] > maxFluxNeg)) )
    

    Also, given the data and the boundaries you have provided, the conditions will never hold true. In the first iteration, the outer condition holds (as 5 > -0.7) but the inner one doesn’t (as -0.8 is neither between 0.2 and 0.5 nor between -0.2 and -0.5). On the second and final iteration the outer condition fails as -0.8 < -0.7.

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

Sidebar

Related Questions

I tried writing a program in Java using regex to match a pattern and
I'm writing a Java program, and I want a function that, given a string,
I am writing a Java program and at this point I want to issue
I'm writing a java program that works with .class files. I want to be
I'm writing a java program running at Linux. Below is the java method createHinted3gpFile
I am writing a Java program which automatically plugs information into a website, which
I'm writing a java program that goes out and searches twitter, finds certain instagram
I'm currently writing a java program that requires some Data to run. The data
I'm writing a multithreaded Java program where each thread potentially needs its standard output
I'm writing a program in Java where I read in data from an XML

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.