Giter Site home page Giter Site logo

Improve stability propagation about ta4j HOT 7 OPEN

sgflt avatar sgflt commented on June 2, 2024
Improve stability propagation

from ta4j.

Comments (7)

sgflt avatar sgflt commented on June 2, 2024

Related question #1142

from ta4j.

sgflt avatar sgflt commented on June 2, 2024

If I consider following implementation:

public class DownTrendIndicator extends AbstractIndicator<Boolean> {

  private static final int UNSTABLE_BARS = 5;

  private final ADXIndicator directionStrengthIndicator;
  private final Rule downtrendRule;


  public DownTrendIndicator(final BarSeries series) {
    super(series);
    this.directionStrengthIndicator = new ADXIndicator(series, UNSTABLE_BARS);

    final var plusDMIndicator = new PlusDMIndicator(series);
    final var minusDMIndicator = new MinusDMIndicator(series);
    this.downtrendRule = new UnderIndicatorRule(plusDMIndicator, minusDMIndicator);
  }



  @Override
  public Boolean getValue(final int index) {
    return  this.directionStrengthIndicator.getValue(index).isGreaterThan(numOf(25))
            && this.downtrendRule.isSatisfied(index);
  }


  @Override
  public int getUnstableBars() {
    return UNSTABLE_BARS;
  }
}

Still, BaseStrategy have to be manually filled with unstableBars, which as user, I do not know where to get.

Related to #919

from ta4j.

sgflt avatar sgflt commented on June 2, 2024

If propagation through rules to strategy is not viable, then I am thinking about user friendly builder, which does the dirty work.

StrategyBuilder.create()
   .withIndicators(List<Indicator>)    // Takes max unstable bars
   .withEntryRule(Rule)
   .withExitRule(Rule)
   .build() // calls new BaseStrategy(entry, exit, unstableBars)
   ;

from ta4j.

TheCookieLab avatar TheCookieLab commented on June 2, 2024

Regarding your builder example, the Strategy should only need to know about its two Rules and not the Indicators they use.

An Indicator knows it's own unstable period. If we are returning NaN for any calculation within the unstable period then Rules don't need to know about the unstable period either as it can simply key off of NaN values. Typically Rules are comparing the results of one or more Indicators and if any of them are NaN it should know what to do.

from ta4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.