I am trying to get the bid ask volume inside the bar from the example
the problem is that I need a method to get the bid and ask volume without tick replay.
I am trying to create this indicator on my own - from the example of the developers
But the result is without successfully
Below is my code
I ask for help in the task, or a real example of how you can get the volume at bid ask prices without tick replay
private void CalculateValues(bool forceCurrentBar) { // This lets us know what processing mode we are in // if indexOffset == 0 and State is Realtime then we are in 'realtime processing mode' // if indexOffset is > 0 then we are in 'historical processing mode' int indexOffset = BarsArray[1].Count - 1 - CurrentBars[1]; bool inTransition = State == State.Realtime && indexOffset > 1; // For Calculate.OnBarClose in realtime processing we have to advance the index on the tick series to not be one tick behind // The means, at the end of the 'transition' (where State is Realtime but we are still in historical processing mode) -> we have to calculate two ticks (CurrentBars[1] and CurrentBars[1] + 1) if (!inTransition && lastInTransition && !forceCurrentBar && Calculate == Calculate.OnBarClose) CalculateValues(true); bool useCurrentBar = State == State.Historical || inTransition || Calculate != Calculate.OnBarClose || forceCurrentBar; // This is where we decide what index to use int whatBar = useCurrentBar ? CurrentBars[1] : Math.Min(CurrentBars[1] + 1, BarsArray[1].Count - 1); // This is how we get the right tick values double volume = BarsArray[1].GetVolume(whatBar); double price = BarsArray[1].GetClose(whatBar); // Accumulate volume if (price >= BarsArray[1].GetAsk(whatBar)) buys += volume; else if (price <= BarsArray[1].GetBid(whatBar)) sells += volume; lastInTransition = inTransition; // LAST if (MyDict.ContainsKey(price)) MyDict[price] += volume; else MyDict.Add(price, volume); // Ask if (price >= buys) // { if (!MyDictAsk.ContainsKey(price)) MyDictAsk.Add(price, volume); else MyDictAsk[price] += volume; if (!MyDictBid.ContainsKey(price)) MyDictBid.Add(price, 0); } // Bid else if (price <= sells) // { if (!MyDictBid.ContainsKey(price)) MyDictBid.Add(price, volume); else MyDictBid[price] += volume; if (!MyDictAsk.ContainsKey(price)) MyDictAsk.Add(price, 0); } else // { if (!MyDictAsk.ContainsKey(price)) MyDictAsk.Add(price, volume); else MyDictAsk[price] += volume; if (!MyDictBid.ContainsKey(price)) MyDictBid.Add(price, volume); else MyDictBid[price] += volume; } // price Bid Ask double volAskS = 0; double volBidS = 0; foreach (double kvp in MyDictAsk.Keys) { volAskS += volume; } foreach (double kvp in MyDictBid.Keys) { volBidS += volume; } } private void SetValues(int barsAgo) { foreach (double kvp in MyDictAsk.Keys) if (volAskS > 100) { Print(volAskS); } } private void ResetValues(bool isNewSession) { MyDict.Clear(); MyDictAsk.Clear(); MyDictAsk.Clear(); buys = sells = 1; if (Bars.IsFirstBarOfSession) { volAskS = 0; volBidS = 0; } if (isNewSession) { volAskS = 0; volBidS = 0; } }
Comment