Candlestick Settings
The candlestick pattern functions (the CDL* family) judge each candle — is its body "long", its shadow "short", two candles "near" — relative to a set of tunable thresholds. These settings control those judgements.
API
A candle characteristic is measured against an average of a chosen range over the previous avgPeriod bars, scaled by factor. For each setting type:
- range type — what to measure: the real body (open-to-close), the high-to-low range, or the mean of the upper and lower shadows.
avgPeriod— how many prior bars to average (0means "use only the current candle", no averaging).factor— the multiplier applied to that average to form the threshold: finite and not negative.
TA_RetCode TA_SetCandleSettings( TA_CandleSettingType settingType,
TA_RangeType rangeType,
int avgPeriod,
double factor );
TA_RetCode TA_RestoreCandleDefaultSettings( TA_CandleSettingType settingType );
/* Treat a "long body" as 1.2x the average real body of the last 10 candles: */
TA_SetCandleSettings( TA_BodyLong, TA_RangeType_RealBody, 10, 1.2 );
/* ...later, restore the default for that one setting: */
TA_RestoreCandleDefaultSettings( TA_BodyLong );use ta_lib::{CandleSetting, CandleSettingType, Core, RangeType};
// Treat a "long body" as 1.2x the average real body of the last 10 candles:
let core = Core::builder()
.candle_setting(
CandleSettingType::BodyLong,
CandleSetting { range_type: RangeType::RealBody, avg_period: 10, factor: 1.2 },
)
.build()?;import io.github.talib.CandleSettingType;
import io.github.talib.Core;
import io.github.talib.RangeType;
// Treat a "long body" as 1.2x the average real body of the last 10 candles:
Core core = Core.builder()
.candleSetting(CandleSettingType.BODY_LONG, RangeType.REAL_BODY, 10, 1.2)
.build();
// ...later, restore the default for that one setting:
Core restored = core.toBuilder()
.restoreCandleDefault(CandleSettingType.BODY_LONG)
.build();using TALib;
// Treat a "long body" as 1.2x the average real body of the last 10 candles:
Core core = Core.Builder()
.CandleSetting(CandleSettingType.BodyLong, RangeType.RealBody, 10, 1.2)
.Build();
// ...restore one setting, or every one with AllCandleSettings:
Core restored = core.ToBuilder()
.RestoreCandleDefault(CandleSettingType.BodyLong)
.Build();In C, the unstable period and the candle settings are process-wide. Change them only while no TA function is running and no stream is open (specification).
Setting types and defaults
The setting types, with the defaults every binding starts from. C spells them TA_BodyLong; Rust CandleSettingType::BodyLong; C# CandleSettingType.BodyLong; Java takes its own constant case, CandleSettingType.BODY_LONG.
| Setting | Range type | avgPeriod | factor |
|---|---|---|---|
BodyLong | RealBody | 10 | 1.0 |
BodyVeryLong | RealBody | 10 | 3.0 |
BodyShort | RealBody | 10 | 1.0 |
BodyDoji | HighLow | 10 | 0.1 |
ShadowLong | RealBody | 0 | 1.0 |
ShadowVeryLong | RealBody | 0 | 2.0 |
ShadowShort | Shadows | 10 | 1.0 |
ShadowVeryShort | HighLow | 10 | 0.1 |
Near | HighLow | 5 | 0.2 |
Far | HighLow | 5 | 0.6 |
Equal | HighLow | 5 | 0.05 |
AllCandleSettings targets every setting at once. It is meaningful only to the restore call.
See also
- C/C++ Core API / Rust Core API
- Unstable Period
- The candlestick pattern functions in the function reference (the
Pattern Recognitiongroup).