feat: K线图添加MA均线、标准行情布局、买入卖出按钮
This commit is contained in:
@@ -76,16 +76,39 @@ class ChartProvider extends ChangeNotifier {
|
||||
List<Candle> _candles = [];
|
||||
List<Candle> get candles => _candles;
|
||||
|
||||
List<CandleData> get candleData => _candles
|
||||
.map((c) => CandleData(
|
||||
timestamp: c.timestamp,
|
||||
open: c.open,
|
||||
high: c.high,
|
||||
low: c.low,
|
||||
close: c.close,
|
||||
volume: c.volume,
|
||||
))
|
||||
.toList();
|
||||
List<CandleData> get candleData {
|
||||
final baseData = _candles
|
||||
.map((c) => CandleData(
|
||||
timestamp: c.timestamp,
|
||||
open: c.open,
|
||||
high: c.high,
|
||||
low: c.low,
|
||||
close: c.close,
|
||||
volume: c.volume,
|
||||
))
|
||||
.toList();
|
||||
|
||||
// 如果开启MA,计算均线并添加到趋势线
|
||||
if (_indicators.showMA && baseData.isNotEmpty) {
|
||||
final ma7 = CandleData.computeMA(baseData, 7);
|
||||
final ma14 = CandleData.computeMA(baseData, 14);
|
||||
final ma30 = CandleData.computeMA(baseData, 30);
|
||||
|
||||
return List.generate(baseData.length, (i) {
|
||||
return CandleData(
|
||||
timestamp: baseData[i].timestamp,
|
||||
open: baseData[i].open,
|
||||
high: baseData[i].high,
|
||||
low: baseData[i].low,
|
||||
close: baseData[i].close,
|
||||
volume: baseData[i].volume,
|
||||
trends: [ma7[i], ma14[i], ma30[i]],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return baseData;
|
||||
}
|
||||
|
||||
// 状态
|
||||
bool _loading = false;
|
||||
|
||||
Reference in New Issue
Block a user