chisound wrote:What i want it to do is calculate the VWAP internally of each bar, in other words, calculate for each bar the following:
IntrabarVWAP = Sum of (Price of trade X volume of trade ) / ( Sum of volume)
When a bar opens it needs to calculate (Price of Trade x volume of trade ) for each trade in a bar, sum them up, keep a running total of total traded volume during a bar, then when the bar closes it needs to calculate the above formula and then reset (Price of Trade x volume of trade ) and the running total of total volume traded for a bar to zero so that it can be calculated again for the next bar. It's the same as doing a regular VWAP calculation that is done for a trading day bar by bar, except the VWAP is calculated for each bar on a tick by tick or trade by trade basis.
The Current code is only returning the close of each bar for the IntrabarVWAP which is not possible. I hope this helps.
I am using Multicharts 7.0 and i don't think that the intrabarpersist variable declaration works as it is supposed to work even if you run the indicator with every tick.
Many thanks for your help.
I hope you can see that your description here is quite different from what you had in your prevoous posts, and your code is nowhere near a mirror of either.
What you have right now is a continuous thought of things you have in mind. They are not logics. They are spaghettis.
You have to organize yourself better... cut down a complex task into small pieces, so that you can attack them one by one.
1. rewrite your description in a line-by-line format. (just like coding, but in plain English)
ie. write down
one thought per line,
one logic per line,
one action per line,
no two thoughts on the same sentence,
no two sentences on the same line.
2. Draw up a variable table.
Work out how many variables you need to make the computation,
and write down the logic behind each variable before you start coding.
This is a start, you will discover more as you progress.