26 lines
953 B
C#
26 lines
953 B
C#
namespace bts.SilverPine {
|
|
using BCG;
|
|
|
|
using bts;
|
|
|
|
[DataStreamUserRespresentation("RSI")]
|
|
public class RSIStream : ViewStream {
|
|
// public RSIStream(ViewStreamDatabase vsd, string symbol, int n_days) {
|
|
|
|
// }
|
|
|
|
public RSIStream(ViewStream instrument_ohlc_str, int period) {
|
|
GlobalMapStream rs = new GlobalMapStream(instrument_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);
|
|
}
|
|
}
|
|
} |