Market Depth
Market Depth
28 May 2015, 17:41
Hey,
do I need the Calculate() for market depth? Because you have the MarketDepthUpdate(). How those instances interact with each other? Is the MarketDepthUpdated also called at each tick event?
My code is follows: After each 7 ticks we build the mean bid/ask and cumulate for those 7 ticks the volume etc. We compare of each 7 tick bar if the bid or ask volume is larger and mark each bar with 1 or -1 (sell or buy) if bid vol is larger than ask vol.
To include this data I have to add each stae to the indicatorsseriesresult Rersult. How can I do this (Add, Append ?)?
using System; using System.Text; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using System.Collections.Generic; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class domind : Indicator { [Output("Result")] public IndicatorDataSeries states { get; set; } double sum_bid = 0; double sum_ask = 0; double bid_vol = 0; double ask_vol = 0; int i = 1; int state; double magn = 0; // List<int> states = new List<int>(); private MarketDepth _marketDepth; public override void Calculate(int index) { } protected override void Initialize() { _marketDepth = MarketData.GetMarketDepth(Symbol); // subscribe to event Updated _marketDepth.Updated += MarketDepthUpdated; } void MarketDepthUpdated() { foreach (var entry in _marketDepth.BidEntries) { if (i < 8) { i++; double dVolume = Math.Round(entry.Volume / 1000000.0, 2); double entryPrice = entry.Price; sum_bid = sum_bid + entryPrice; bid_vol += dVolume; } else { if (bid_vol > ask_vol) { state = -1; magn += state; states.Append(state); } else { state = 1; magn += state; states.Add(state); } i = 1; bid_vol = 0; } } foreach (var entry in _marketDepth.AskEntries) { if (i < 8) { i++; double dVolume = Math.Round(entry.Volume / 1000000.0, 2); double entryPrice = entry.Price; sum_ask = sum_ask + entryPrice; ask_vol += dVolume; } else { if (bid_vol > ask_vol) { state = -1; magn += state; states.Add(state); } else { state = 1; magn += state; states.Add(state); } i = 1; ask_vol = 0; } } } } }
Replies
Spotware
12 Jun 2015, 12:28
Dear Trader,
MarketDepth.Updated event is raised when MarketDepth is changed. MarketDepth is changed on every tick as well. So you do not need to use Calculate method when you use MarketDepth.
In order to fill IndicatorDataSeries you need to set values by indexes.
For example:
Result[index] = (MarketSeries.Close[index] - lowestlow) / (highesthigh - lowestlow) * 100;
@Spotware
maxwell
30 May 2015, 11:58
I really like to get help here. I am a newby and I dont know where to inform anywhere else.
Thanks!
@maxwell