Files
spark/src/DataStreamSuite/SharedStreams/Business/MarketData/Charting/SMAStream.cs
T

24 lines
841 B
C#

namespace bts.SilverPine {
using bts;
using BCG;
[DataStreamUserRespresentation("SMA")]
public class SMAStream : ViewStream {
public SMAStream(ViewStream ohlc_str, int period) {
GlobalMapStream rs = new GlobalMapStream(ohlc_str, "ts_event", "contract",
(rows, idx) => {
IBlueRow ir = rows.ElementAt((int)idx);
IEnumerable<double> closes = BlueDataUtility.get_colvalues<double>(rows, "close", (int)idx + 1, period + 2);
double rsi = IndicatorCalc.calculate_RSI(closes.ToList(), period);
IBlueTableSchema schema = ir.schema.add_columns(Tuple.Create(typeof(double), "rsi"));
MutableBlueRow nr = new MutableBlueRow(schema, ir);
nr.setValue("rsi", rsi);
return nr;
});
mySetRealSource(rs);
}
}
}