Reset volume count on each new bar

Questions about MultiCharts and user contributed studies.
paulc
Posts: 59
Joined: 26 Sep 2012
Has thanked: 13 times
Been thanked: 2 times

Reset volume count on each new bar

Postby paulc » 06 Nov 2014

I am trying to colour bars based on whether most trade is at bid or ask. Trouble is i cannot work out how to reset the count on each new bar. Is there a function like NewBar which i can use in the following way:

If new bar then var2 = 0 and var3 = 0.

My code is below. Thanks for any help.
Inputs: provolume( 0 ), tradeprice ( close ), bidprice ( close data3 ), askprice( close data2);

Vars: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 );

if volume - volume[1] > provolume then var0 = volume - volume[1];

// trade was made at bid
if tradeprice <= bidprice then var2 = var2 + var0;

//trade was made at ask
if tradeprice >= askprice then var3 = var3 + var0 ;

// count which is higher

if var2 > var3 then plotpaintbar(high, low, open, close, "", DarkRed);
if var2 < var3 then plotpaintbar(high, low, open, close, "", DarkGreen);



User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Reset volume count on each new bar

Postby bensat » 06 Nov 2014

Hi "PaulC",

is .....

Code: Select all

if barnumber <> barnumber[1]
begin
var2 = 0;
var3 = 0;
end;
working ? Did not test it. Just a quick idea.

Regards.

Ben

paulc
Posts: 59
Joined: 26 Sep 2012
Has thanked: 13 times
Been thanked: 2 times

Re: Reset volume count on each new bar

Postby paulc » 06 Nov 2014

Thanks bensat but no. i think there is something wierd going on. i either get the colour applied or not at all. so now using your trick i do get both colours showing instead of just one - it seems it is not sensitive to what number i use for the pro volume limit. wierdly above 35 the colour is applied and below 35 it is not applied to any bars.

so the code i have now is:
Inputs: provolume( 0 ), tradeprice ( close ), bidprice ( close data3 ), askprice( close data2);

Vars: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 );

if barnumber <> barnumber[1] then
begin

if volume - volume[1] > provolume then var0 = volume - volume[1];

// trade was made at bid
if tradeprice <= bidprice then var2 = var2 + var0;

//trade was made at ask
if tradeprice >= askprice then var3 = var3 + var0 ;

// count which is higher

if var2 > var3 then plotpaintbar(high, low, open, close, "", DarkRed);
if var2 < var3 then plotpaintbar(high, low, open, close, "", DarkGreen);

var2 = 0;
var3 = 0;
end;

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Reset volume count on each new bar

Postby bensat » 06 Nov 2014

First of all I just thought you wanted to implement a "RESET" of var2 and var3 from one bar to another. So the code sequence I provided should stay together, like :

Code: Select all

Inputs: provolume( 0 ), tradeprice ( close ), bidprice ( close data3 ), askprice( close data2);

Vars: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 ), zz(0);

//validation what kind of data we are working with (0-1 = intraday, 2 > Daily, Weekly etc)
if bartype <= 1 then zz = ticks else zz = volume;

if ( zz - zz[1] ) > provolume then var0 = ( zz - zz[1] ) else var0 = 0;

// reset of var2 and var3 on every new bar
if barnumber <> barnumber[1] then
begin
var2 = 0;
var3 = 0;
end;

// trade was made at bid
if tradeprice <= bidprice then var2 = var2 + var0;

//trade was made at ask
if tradeprice >= askprice then var3 = var3 + var0 ;

// count which is higher

if var2 > var3 then plotpaintbar(high, low, open, close, "", Red);
if var2 < var3 then plotpaintbar(high, low, open, close, "", Green);
and I get this chart as an example.

Image

2 Questions

You want to set var0 if the current vol on trade is > then the previous vol on trade or if the vol on current trade is higher then the vol on the previous trade of an amount X ? than u should set "provolume" for the amount of the difference you want, but not 0.

You want to count all vol on bid and ask within one bar for all trades where the vol of a trade was higher then the trade before ?

If you could more clarify what you really want to analyze the guys may can help you.

Regards.

Ben

paulc
Posts: 59
Joined: 26 Sep 2012
Has thanked: 13 times
Been thanked: 2 times

Re: Reset volume count on each new bar

Postby paulc » 06 Nov 2014

Hi Ben,

Thanks for your help on this.

For each bar i want to effectively count the volume done by "pros" at the bid (or below) and the volume done at ask (or above). so i am interested in the total volume which determines the colour of the bar.

However to detremine whether a trade is pro or not i am interested in the volume of each trade.

I now get the attached result but im not sure how useful it is!
Attachments
Capture.PNG
(65.91 KiB) Downloaded 471 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Reset volume count on each new bar

Postby bensat » 06 Nov 2014

PaulC,

with the code sequence :

Code: Select all

if ( zz - zz[1] ) > provolume then var0 = ( zz - zz[1] ) else var0 = 0;
you are just differing the last trade vol was higher then the trade vol before, because you declared "provolume" as 0. So if the last two trades have the same volume or the last trade has less volume, than it's not part of your calculations.

If you want to separate the small or non-pro trades from the pro trades, you have to define the vol of pro traders. Let's say 50 lots or so. It's up to your analysis what in your eyes pro traders trade. You do this with :

Code: Select all

inputs: provolume(49);
Further your code runs just in realtime and is not for analysis in history.

Good night.

Regards.

Ben

paulc
Posts: 59
Joined: 26 Sep 2012
Has thanked: 13 times
Been thanked: 2 times

Re: Reset volume count on each new bar

Postby paulc » 07 Nov 2014

Morning Bensat,

Thanks for staying with me on this one.

I thought volume was cumulative.

If i use vol - vol[1], you can see in the attached screenshot that, for provol set at 5000, MC has only painted the one very large bar which has vol over 15000 where a trade must have taken place over 5000. It doesnt paint bars with total volume over 5000 which dont contain a trade over 5000. eg there is one bar where volume is 5197 - very unlikely to include a trade of 5000. And MC doesnt paint this bar - correctly.

If i only use vol (or zz in your code) MC will paint any bar which has total volume over 5000.

So maybe i have misunderstood your point on vol - vol[1] or the keyword volume is indeed cumulative?

Also i could you elaborate on your point:
Further your code runs just in realtime and is not for analysis in history.
Thanks.
Attachments
Capture.PNG
(69.61 KiB) Downloaded 484 times


Return to “MultiCharts”