SkillAgentSearch skills...

Ta4j Strategy Parser

a library to parse Technical Analysis strategies into ta4j using antlr4

Install / Use

npx skills add massigerardi/ta4j-strategy-parser

Installs into whichever agent you are using.

About this skill

Quality Score

0/100

Supported Platforms

Universal

README

ta4j Strategy Parser

ta4j Strategy Parser is a library to parse Technical Analysis strategies into ta4j using antlr4.

Strategies

Strategies are defined as combination of GO_LONG and GO_SHORT combined signals.

A signal could be a combination of indicator expressions and logical expressions.

(((DEMA[5] >= SMA[45]) OR ((TEMA[30] <= 1.3) OR ((DEMA[74] >= 0.3637) OR (CCI[30] <= 0.5)))) AND ((TEMA[30] <= 1.3) OR ((DEMA[74] >= 0.3637) OR (CCI[30] <= 0.5)))) [GO_LONG] 
; 
((TEMA[30] <= 1.3) OR ((DEMA[74] >= 0.3637) OR (CCII[30] <= 0.5))) [GO_SHORT]",

Logical expressions must be inserted between parentheses

  • correct
((DEMA[74] >= 0.3637) OR (CCII[30] <= 0.5))
  • incorrect
(DEMA[74] >= 0.3637) OR (CCII[30] <= 0.5)

Use


import org.ambulando.strategy.ta4j.parser.*;

    ...
    String input = "(RSI[5] <= 7.5) [GO_LONG] ; (CCII[5] >= 7.9) [GO_SHORT]";
    try
    {
      BarSeries barSeries = getBarSeries();
      Strategy strategy = parser.parse(input, barSeries);
    }
    catch (ParserException e)
    {
      List<ParserError> errors = e.getErrors();
      //handle errors
    }
    ...

Operators

  • Logic operators between signals
    • OR
    • AND
  • mathematical operators between indicators:
    • >=
    • <=

Indicators

Use of the indicator can be found in ta4j docs At now, the following indicators are recognized by the parser:

|INDICATOR |USE| |----------|---| | Close Price|CPRICE| | Volume|VOLUME| | Simple Moving Average - SMA|SMA[timeframe:int]| | Double Exponential Moving Average - DEMA|DEMA[timeframe:int]| | Exponential Moving Average - EMA|EMA[timeframe:int]| | Triple Exponential Moving Average – TEMA|TEMA[timeframe:int]| | Weighted Moving Average WMA|WMA[timeframe:int]| | William's R - WILLIAMS|WILLIAMS[timeframe:int]| | Commodity Channel Index - CCI|CCI[timeframe:int]| | Relative Strength Index - RSI|RSI[timeframe:int]| | Ulcer Index - UI|UI[timeframe:int]| | Average Directional Index - ADX|ADX[timeframe:int]| | Hull Moving Average HMA|HMA[timeframe:int]| | Zero-Lag Exponential Moving Average - ZLEMA|ZLEMA[timeframe:int]| | Kaufman's Adaptive Moving Average - KAMA|KAMA[timeframe:int,timeframe:int,timeframe:int]| | Moving Average Convergence Divergence - MACD|MACD[timeframe:int,timeframe:int]| | Percentage price oscillator - PPO|PPO[timeframe:int,timeframe:int]| | Volume-Weighted Average Price - VWAP|VWAP[timeframe:int]| | Chaikin Oscillator - COI|COI[timeframe:int,timeframe:int]| | Accumulation Distribution - ADI|ADI| | Intraday Intensity Index - III|III| | Chaikin Money Flow - CMF|CMF[timeframe:int]| | Moving Volume Weighted Average Price - MVWAP|MVWAP[timeframe:int,timeframe:int]| | Negative Volume Index - NVI|NVI| | Rate Of Change of Volume - ROCV|ROCV[timeframe:int]| | Positive Volume Index - PVI|PVI| | On Balance Volume - OBV|OBV|

Related Skills

View on GitHub
GitHub Stars23
CategoryDevelopment
Updated8mo ago
Forks8

Languages

Java

Security Score

87/100

Audited on Dec 9, 2025

No findings