MTF Histogram
Created at 11 Nov 2013, 10:33
MTF Histogram
11 Nov 2013, 10:33
Hi,
I'm trying to make this indicator so I can view an additional timeframe on the one chart. I have spent many hours trying to figure it out, this is where I'm up to...
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)] public class Volume : Indicator { [Output("Ask Volume", Color = Colors.Blue, PlotType = PlotType.Histogram, Thickness = 5)] public IndicatorDataSeries ask_volume { get; set; } [Output("Bid Volume", Color = Colors.Red, PlotType = PlotType.Histogram, Thickness = 5)] public IndicatorDataSeries bid_volume { get; set; } private MarketSeries series1; MarketDepth _MarketDepth; private int old_index = 0; private double sum_ask_volume = 0; private double sum_bid_volume = 0; private double high_ask_price = 0; private double low_bid_price = 999999; private double lot_size = 100000; private double highlow_range = 0; private double sum_total_volume = 0; private double old_sum_total_volume = 0; private double old_highlow_range = 0; private double Symbol_PointSize = 0; private const VerticalAlignment vAlign = VerticalAlignment.Center; private const HorizontalAlignment hAlign = HorizontalAlignment.Right; protected override void Initialize() { series1 = MarketData.GetSeries(TimeFrame.Minute); old_index = MarketSeries.Close.Count - 1; Symbol_PointSize = Symbol.PointSize; _MarketDepth = MarketData.GetMarketDepth(Symbol); _MarketDepth.Updated += OnUpdated; } void OnUpdated() { int index = MarketSeries.Close.Count - 1; double sum_ask_bid_volume = 0; double sum_bid_ask_volume = 0; //Insert values to global variables if (index != old_index) { ask_volume[index] = 0; bid_volume[index] = 0; old_index = index; sum_ask_volume = 0; sum_bid_volume = 0; high_ask_price = 0; low_bid_price = 999999; old_sum_total_volume = sum_total_volume; old_highlow_range = highlow_range; } //Insert values of Volume foreach (var entry in _MarketDepth.AskEntries) { sum_ask_volume = sum_ask_volume + (entry.Volume / lot_size); if (high_ask_price < entry.Price) { high_ask_price = entry.Price; } } foreach (var entry in _MarketDepth.BidEntries) { sum_bid_volume = sum_bid_volume + (entry.Volume / lot_size); if (low_bid_price > entry.Price) { low_bid_price = entry.Price; } } //Calc Volume sum_ask_bid_volume = (sum_ask_volume - sum_bid_volume); sum_bid_ask_volume = (sum_bid_volume - sum_ask_volume); //Show Volume Indicator var index5 = GetIndexByDate(series1, MarketSeries.OpenTime[index]); if (index5 != -1) if (sum_ask_bid_volume >= 0) { ask_volume[index] = sum_ask_bid_volume; bid_volume[index] = 0; } else { ask_volume[index] = 0; bid_volume[index] = sum_bid_ask_volume; } } public override void Calculate(int index) { } private int GetIndexByDate(MarketSeries series1, DateTime time) { for (int i = series1.Close.Count - 1; i > 0; i--) { if (time == series1.OpenTime[i]) return i; } return -1; } } }
I appreciate any help.
jtrader
11 Nov 2013, 15:24
I ended up doing this... using the Sum function.
@jtrader