I have this code:
Variables
public class AskBidRow
{
public double askVolumen = 0.0;
public double bidVolumen = 0.0;
}
public class BarItem
{
public ConcurrentDictionary<double, AskBidRow> diccItem = new ConcurrentDictionary<double, AskBidRow>();
}
private double priceAsk = 0.0;
private double priceBid = 0.0;
private double price = 0.0;
private double volumen = 0.0;
private DateTime time;
private Series<BarItem> BarItems;
protected override void OnMarketData(MarketDataEventArgs e)
{
if (Bars.Count < 0) { return; }
if (CurrentBar < 1) { return; }
if (BarItems[0] == null)
{
BarItems[0] = new BarItem();
}
if (e.MarketDataType == MarketDataType.Last)
{
priceAsk = e.Ask;
priceBid = e.Bid;
price = e.Price;
volumen = e.Volume;
time = e.Time;
//No existe todavia....
if (!BarItems[0].diccItem.ContainsKey(price))
{
BarItems[0].diccItem.TryAdd(price, new AskBidRow());
}
//ASK
if (price >= priceAsk)
{
BarItems[0].diccItem[price].askVolumen += volumen;
}
//BID
if (price <= priceBid)
{
BarItems[0].diccItem[price].bidVolumen += volumen;
}
}
}
protected override void OnBarUpdate() //OnBarUpdate event..
{
askSum = 0;
bidSum = 0;
if (CurrentBar < 1) { return; }
if (BarItems.IsValidDataPointAt(CurrentBar))
{
tmpBarItem = BarItems.GetValueAt(CurrentBar);
foreach (KeyValuePair<double, AskBidRow> fila in tmpBarItem.diccItem)
{
askSum += fila.Value.askVolumen;
bidSum += fila.Value.bidVolumen;
}
//Print("Barra anterior numero: " + CurrentBar + "El volumen en el ASK es de: " + askSum + "-----" + "el volumen en el Bid es de: " + bidSum);
}
}
If I set up the event OnBarUpdate to acces to the BarItem Series object is not working, they don't get in...
If I try to acces like this way BarItems[0] they get an error....
I want to know the ASK and the BID every OnBarUpdate, to take a decision if I get into the market or not. I have a 10 Range series...
If the onBarUpdate is set up to every onTickdate is working fine, the tell me every tick the ASK and the Bid Volume.
Thanks a lot...
Comment