WmaIndicator<T, D> class
Renders weighted moving average (WMA) indicator.
A weighted moving average (WMA) is an arithmetic moving average calculated by adding recent closing prices and then dividing the total by the number of time periods in the calculation average.
It also has a valueField property. Based on this property, the indicator will be rendered.
The indicator elements are:
- The dataSource, which is used provide data for the technical indicators without any series.
- The xValueMapper, which is a value mapper to map the x values with the technical indicator.
- The highValueMapper, which is a value mapper to map the high values with the technical indicator.
- The lowValueMapper, which is a value mapper to map the low values with the technical indicator.
- The openValueMapper, which is a value mapper to map the open values with the technical indicator.
- The closeValueMapper, which is a value mapper to map the close values with the technical indicator.
- The xAxisName and yAxisName, which is used map the technical indicator with the multiple axes.
- The seriesName, which is used map the technical indicator with the series based on names.
- The valueField, which is used to determines the field for the rendering of WMA indicator.
- The period, which is used determines the start point for the rendering of technical indicator.
Formula
Data (Closing Prices for Each Day):
- Day 1: $100
- Day 2: $105
- Day 3: $110
- Day 4: $120
- Day 5: $103
- ...
- Day 15: $110
- Day 16: $108
- …
- Day 29: $110
- Day 30: $120
Calculation of WMA:
-
WMA for single data = currentPrice * (n/ sum of period);
-
The equation we use for weighing each number is the day number divided by the sum of all day numbers. Since we are looking at five days, the sum of all day numbers in this example is 15 (i.e., 5 + 4 + 3 + 2 + 1).
-
WMA on Period 3:
-
If we need to calculate the 3rd day WMA means, current value is 110, period 3 days sum is 6 (3+2+1), then
-
100 * (1/6) = 6.25
-
105 * (2/6) = 17.5
-
110 * (3/6) = 18.33
-
WMA on Period 16:
-
If we need to calculate the 16th day WMA means, current value is 108, previous 16-day sum is 136 (16+15+14+13+...+1).
-
Day1: 100 * (1/136) = 0.7
-
....
-
Day 16: 108 * (16/136) = 12.070
Example
This snippet shows how to create a WmaIndicator by mapping the series data source.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: SfCartesianChart(
primaryXAxis: const DateTimeAxis(),
primaryYAxis: const NumericAxis(),
axes: const <ChartAxis>[
NumericAxis(
majorGridLines: MajorGridLines(width: 0),
opposedPosition: true,
name: 'yAxis',
),
],
indicators: <TechnicalIndicator<ChartSampleData, DateTime>>[
WmaIndicator<ChartSampleData, DateTime>(
seriesName: 'AAPL',
yAxisName: 'yAxis',
period: 15,
),
],
series: <CartesianSeries<ChartSampleData, DateTime>>[
HiloOpenCloseSeries<ChartSampleData, DateTime>(
dataSource: getChartData(),
xValueMapper: (ChartSampleData sales, _) => sales.x as DateTime,
lowValueMapper: (ChartSampleData sales, _) => sales.low,
highValueMapper: (ChartSampleData sales, _) => sales.high,
openValueMapper: (ChartSampleData sales, _) => sales.open,
closeValueMapper: (ChartSampleData sales, _) => sales.close,
name: 'AAPL',
),
],
),
),
),
);
}
This snippet shows how to create a WmaIndicator using a direct data source.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: SfCartesianChart(
primaryXAxis: const DateTimeAxis(),
primaryYAxis: const NumericAxis(),
axes: const <ChartAxis>[
NumericAxis(
majorGridLines: MajorGridLines(width: 0),
opposedPosition: true,
name: 'yAxis',
),
],
indicators: <TechnicalIndicator<ChartSampleData, DateTime>>[
WmaIndicator<ChartSampleData, DateTime>(
dataSource: getChartData(),
xValueMapper: (ChartSampleData sales, _) => sales.x as DateTime,
lowValueMapper: (ChartSampleData sales, _) => sales.low,
highValueMapper: (ChartSampleData sales, _) => sales.high,
openValueMapper: (ChartSampleData sales, _) => sales.open,
closeValueMapper: (ChartSampleData sales, _) => sales.close,
yAxisName: 'yAxis',
period: 15,
),
],
),
),
),
);
}
- Inheritance
-
- Object
- TechnicalIndicator<
T, D> - WmaIndicator
- Annotations
Constructors
-
WmaIndicator({bool isVisible = true, String? xAxisName, String? yAxisName, String? seriesName, List<
double> dashArray = const <double>[0, 0], double animationDuration = 1500, double animationDelay = 0, List<T> ? dataSource, ChartValueMapper<T, D> ? xValueMapper, ChartValueMapper<T, num> ? highValueMapper, ChartValueMapper<T, num> ? lowValueMapper, ChartValueMapper<T, num> ? openValueMapper, ChartValueMapper<T, num> ? closeValueMapper, String? name, bool isVisibleInLegend = true, LegendIconType legendIconType = LegendIconType.seriesType, String? legendItemText, Color signalLineColor = Colors.blue, double signalLineWidth = 2, int period = 14, String valueField = 'close', ChartIndicatorRenderCallback? onRenderDetailsUpdate}) - Creating an argument constructor of WmaIndicator class.
Properties
- animationDelay → double
-
Delay duration of the technical indicator's animation.
It takes a millisecond value as input.
By default, the technical indicator will get animated for the specified
duration. If animationDelay is specified, then the technical indicator
will begin to animate after the specified duration.
finalinherited
- animationDuration → double
-
Animation duration for the technical indicators.
finalinherited
-
closeValueMapper
→ ChartIndexedValueMapper<
num?> ? -
Value mapper to map the close values with technical indicators.
finalinherited
-
dashArray
→ List<
double> -
Property to provide dash array for the technical indicators.
finalinherited
-
dataSource
→ List<
T> ? -
Property to provide data for the technical indicators without any series.
finalinherited
- hashCode → int
-
The hash code for this object.
no setteroverride
-
highValueMapper
→ ChartIndexedValueMapper<
num?> ? -
Value mapper to map the high values with technical indicators.
finalinherited
- isVisible → bool
-
Boolean property to change the visibility of the technical indicators.
finalinherited
- isVisibleInLegend → bool
-
Boolean property to determine the rendering of legends for the
technical indicators.
finalinherited
- legendIconType → LegendIconType
-
Property to provide icon type for the technical indicators legend.
finalinherited
- legendItemText → String?
-
Property to provide the text for the technical indicators legend.
finalinherited
-
lowValueMapper
→ ChartIndexedValueMapper<
num?> ? -
Value mapper to map the low values with technical indicators.
finalinherited
- name → String?
-
Property to provide name for the technical indicators.
finalinherited
- onRenderDetailsUpdate → ChartIndicatorRenderCallback?
-
Callback which gets called while rendering the indicators.
finalinherited
-
openValueMapper
→ ChartIndexedValueMapper<
num?> ? -
Value mapper to map the open values with technical indicators.
finalinherited
- period → int
-
Period determines the start point for the rendering of
technical indicators.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seriesName → String?
-
Property to link indicators to a series based on names.
finalinherited
- signalLineColor → Color
-
Property to provide the color of the signal line in the
technical indicators.
finalinherited
- signalLineWidth → double
-
Property to provide the width of the signal line in the
technical indicators.
finalinherited
- valueField → String
-
Value field value for WMA indicator.
final
-
volumeValueMapper
→ ChartIndexedValueMapper<
num?> ? -
Volume of series.
finalinherited
- xAxisName → String?
-
Property to map the technical indicators with the axes.
finalinherited
-
xValueMapper
→ ChartIndexedValueMapper<
D> ? -
Value mapper to map the x values with technical indicators.
finalinherited
- yAxisName → String?
-
Property to map the technical indicators with the axes.
finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override