ta4j-strategy-parser
ta4j-strategy-parser copied to clipboard
a library to parse Technical Analysis strategies into ta4j using antlr4
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: