Calculate sales/buys
Calculate sales/buys
13 Jun 2023, 02:11
Hi.
When I get the bars on the OnStart() method, I try to calculate if the Tick volume is from a sell (on the bid side) or from a buy (on the ask side). So, I do the following:
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MyTakeProfit : Robot
{
blah... blah... blah...
private Bars bars;
private Ticks ticks;
long sells = 0;
long buys = 0;
protected override void OnStart()
{
bars = MarketData.GetBars(TimeFrame.Tick);
bars.Tick += Bars_Tick;
ticks = MarketData.GetTicks();
ticks.Tick += Ticks_Tick;
for (int i=0; i<bars.Count; i++)
{
if (bars[i].Close == ticks[i].Bid)
sells += bars[i].TickVolume;
if (bars[i].Close == ticks[i].Ask)
buys += bars[i].TickVolume;
if (bars[i].OpenTime != ticks[i].Time)
throw new Exception("different times");
}
Print($"sells: {sells}, buys: {buys}");
}
}
My problem is that the sales are always equal to the amount of bars.Count() which tells me that the closing price is always equal to the Bid price.
I would expect this to be wrong as we also have buys.
Am I doing something wrong? Maybe it is the demo account at Pepperstone or something?
Is it any way to calculate the sales & the buys? Maybe by looking the asks/bids going up/down compared to the previous ones?
Thank you very much for your help.
Efthymios
Replies
ekalyvio
13 Jun 2023, 14:55
RE:
PanagiotisChar said:
Hi Efthymie,
Bars are constructed exclusively on bid prices. Therefore the outcome you describe is expected. A suggestion would be to just loop over the ticks collection and check which price was changed (bid or ask) and increase the relevant counter accordingly.
Need help? Join us on Telegram
Hi Panagioti.
I am not quite sure if any of the suggestions (mine or yours) should be correct.
Without being an expert in trading, I guess that there could be a sale or a buy that doesn't change either the bid or the ask.
Hypothetically, someone is bidding 200 stocks of MSFT at $204. Then someone sells 50 stocks of MSFT at $204. I imagine that at that point, the bid price shouldn't change as there are some 150 stocks remaining to be bought. Also, since a lot of brokers have usually fixed spreads, the ask will not change too.
Am I wrong in what I say?
If that is the case, then we can never be sure that the order that happened was a sale or a buy.
So... I am wondering how all these volume profile indicators for cTrader work and if they display correct values.
@ekalyvio
PanagiotisChar
13 Jun 2023, 08:31
Hi Efthymie,
Bars are constructed exclusively on bid prices. Therefore the outcome you describe is expected. A suggestion would be to just loop over the ticks collection and check which price was changed (bid or ask) and increase the relevant counter accordingly.
Aieden Technologies
Need help? Join us on Telegram
@PanagiotisChar