Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

dbntina

VWAP Indicator with 1SD and 2SD bands

Recommended Posts

Guys I am not a TS coding guru by any means...still new at it but wanted to share this code if anyone else was interested. Just wrote this code for myself to keep up with JPERL's threads on Market Statistics. It plots the VWAP, and 1st and 2nd Standard Deviation bands. It lines up with his numbers within a tick or two so I think it is working correctly.

 

Any other TS coders out there please take a look because it can probably be improved upon.

 

This is my first post of a file so if I screwed something up...be gentle!

 

Hope this helps,

 

dbntina

boxmeister :)

DBVWAP_SD.ELD

Share this post


Link to post
Share on other sites

Good post mate. I've been wanting to do this since reading Jpearls threads. I am however using ninja trader, so (if you dont mind) Im going to try and convert your code to ninja script.

 

I dont think there are too many ninja users out there - everybody seems to use esignal or tradestation!

 

Cheers, Jay.

Share this post


Link to post
Share on other sites

Hi DbnTina,

I am not sure if the calculation for vi is correct.

In your EL you have used

variance_i = ((UpTicks[Value1]+DownTicks[Value1])/ShareW) * (Square(AvgPrice-VolWAPValue));

 

where (UpTicks+DownTicks) represents volume of the bar ... I think in a probability calculation one should use total volume at price i, not just volume of the bar i. Lets ask Jerry for clarification.

Share this post


Link to post
Share on other sites

Hi DbnTina,

I am not sure if the calculation for vi is correct.

In your EL you have used

variance_i = ((UpTicks[Value1]+DownTicks[Value1])/ShareW) * (Square(AvgPrice-VolWAPValue));

 

where (UpTicks+DownTicks) represents volume of the bar ... I think in a probability calculation one should use total volume at price i, not just volume of the bar i. Lets ask Jerry for clarification.

 

 

 

 

NickM001,

 

You are correct. In the code, ShareW is always the total share volume up to the current time from your start. You divide the volume of the current bar by the total volume and use this "normalized volume" to multiply with according to Jerry. This should be correct if I am understanding the formula correctly. It also seems to line up with Jerry's bands so I think it is correct.

 

Let me know...I can correct if I am not suppossed to normalize this way...

 

Thanks for taking a look at the code if it is incorrect we want to find out now.

 

dbntina :)

Share this post


Link to post
Share on other sites

Hi dbntina,

 

Thank you for your contribution. If you happen to need any updating on the code, threads here can be edited at anytime so please feel free to do so. Also, would it be possible to add a screenshot of the indicator in action? It would help traders give a visual clue on what the indicator is all about. Thanks.

Share this post


Link to post
Share on other sites

OK let me try to explain again my understanding of the formula. Let quote what Jerry wrote in his explanation:

QUOTE#######################################

While we won't address all these questions in one thread their answers can be obtained by analysis of the volume distribution function. To do so requires that we introduce a third property of the volume distribution function called the Standard Deviation of the VWAP, SD for short. SD is computed from the following equations:

 

NOTE : Formula did not copy ... see http://www.traderslaboratory.com/forums/f6/trading-with-market-statistics-iv-standard-2101.html

 

where the summation subscript i, runs over all prices in the volume distribution

pi = ith price in the volume distribution

Pi = vi/V is the probability of occurrence of price pi

vi = the volume traded at price pi from the volume distribution

V = total volume for the entire distribution

#################################

 

Note that factor vi is volume traded at price pi. If I understand your code, you have used volume of the bar, or volume at time , not as described in the formula.

 

To get proper value for vi, you would have to keep track of all the volume distribution at EACH price level of the range in the array and use the value of volume array element that corresponds to price pi. It can be done, but it would take more then few lines of code, unfortunately.

 

For some odd reason, it does not seem to make much difference even if you set vi/V = 1, for the few sample charts I looked at. So for all practical purposes, SD value is usable...

Share this post


Link to post
Share on other sites

I think it's considered an 'acceptable' trade of computational complexity/speed against accuracy.

 

You can control the accuracy by putting a second series of lower timeframe bars and applying the indicator to that perhaps? (hide the second series). A 1 tick series should be completely accurate?

 

Just a thought.

 

Oh and thanks Dbntina!

Share this post


Link to post
Share on other sites

Nick,

 

You are exactly correct...I know what you are getting at for sure. Blowfish is exactly right...the code I wrote on a 10M bar will do what you are getting at but only at 10M increments. A 5M bar will be more accurate...then a 3M bar will be even more accurate...then a 2M bar will be even more accurate...etc. Jerry is content using a 2M bar. Technically you would have to run it how you are describing to get it exact but I am not sure that it is necessary according Jerry he thinks running it on a 2M bar is close enough.

 

I understand though what you are saying because if I remember my match classes correctly it is a continuous function not a discrete function? I am approximating (so is Jerry I believe) using calculations at every 2 minutes (discrete) when the true value would be evaluated constantly like a continuous function.

 

We will get more and more accurate as will decrease our bar interval. But knowing that the bands are truly at .38 on the S&P as oppossed to having our numbers 1 to 2 ticks off (I don't know if this is the case but I am just giving an example) I think it is close enough on a 2M according to Jerry.

 

Let me know if I am misunderstanding what you are getting at...the important thing is that the code is doing the same thing as Jerry's code on a 2 minute chart...that was all I was trying to accomplish so I could follow Jerry's logic and trade management.

 

dbntina :)

Share this post


Link to post
Share on other sites

I don't want to beat this to death, since the code is performing close enough to what Jerry has. However, it is only important if you decide to expand the code to include volume distribution. At that point you will realize that assumptions made in this code are not valid in all cases. It is accurate observation that the smaller the time frame is, the more accurate calculation becomes, simply because there is an underlying assumption that the volume was constant within the bar interval ( we know the total volume of the bar, and range of the bar). Calculation will be accurate as long as the price does not hit the same level more then once. Now suppose that we have a consolidation day when the price moves back and forth several times thru the range. Every time it comes to the price pi, you will have to add volume of that instance to previous volume at the same price and build volume histogram bar for the price pi. Now when you do calculation for the SD, you would take sum of the volume at price pi and divide it with total volume for the session . I hope that this explanation is better then previous attempts.

Share this post


Link to post
Share on other sites

Nick,

 

I hope I didn't mislead anyone. I should have been more clear. The indicator I posted does not give the exact VWAP or SD bands. It most definitely is an approximation. I am only trying to create the identical indicator Jerry uses on his 2min charts for TS users.

 

It should be the exact way that Jerry told us to caculate it. That is all I am trying to accomplish. He said to take the open/hi/low/close and divide by 4, for the price bar...that in itself already throws some level of accuracy out the window. However I am normalizing the volume according to the way he said to do it I think.

 

I would like people to check the code for accuracy according to the way Jerry does it...not for exact accuracy of VWAP and SD bands...I already know it is not to that level of accuracy.

 

Hopefully everyone is clear on what the indicator is doing now. But I agree with you it is not accurate the way you are talking about...that was not my intention. My intention was to create Jerry's indicator for TS users.

 

Hope that clears it up,

 

Thanks,

 

dbntina :)

Share this post


Link to post
Share on other sites
Soultrader,

 

I have the screenshot. Can you point me to the instructions on how to add the image to the eld?

 

Thanks,

 

dbntina

 

Hi dbntina,

 

You should be able to edit your first post and then edit the attachment manager. Pm me if you are still having problems.

Share this post


Link to post
Share on other sites

Soultrader, I still can't find how to edit my original post...having said that...

 

I have coded the VWAP, SD bands and PVP on a tick by tick basis on a 1 Tick chart. I was thinking I could simply hide the 1 tick chart and plot the indicators on a 2 minute chart and everything would be cool...problem is that it gives me an error "Tick and Volume intervals cannot be used in a mult-symbol chart".

 

Does anyone know of a way around this to plot the data gathered from the 1Tick to plot on a minute chart? There has to be a way around this. Maybe creating a function and access...I don't know just thinking out loud...like I said I am new to the functionality of TS and need help.

 

I will post for all TS users for free if we can get this thing figured out.

 

Any help is appreciated. This should be the fix that NICK was pointing out for accuracy in the indicator thread.

 

dbntina ;)

Share this post


Link to post
Share on other sites

You would put the 1 tick series on the chart add the indicator on that series then, then hide the initial 1 tick series.

 

Simply add a second 2 5 10 15 minute data series of the same instrument (whatever you want to trade from) to the chart.

 

Cheers,

 

PS. have you posted the PvP yet I could not see it

PPS. Great work!! Thanks you (if I had not already thanked you).

Share this post


Link to post
Share on other sites
Guest cooter
You would put the 1 tick series on the chart add the indicator on that series then, then hide the initial 1 tick series.

 

Simply add a second 2 5 10 15 minute data series of the same instrument (whatever you want to trade from) to the chart.

 

Cheers,

 

PS. have you posted the PvP yet I could not see it

PPS. Great work!! Thanks you (if I had not already thanked you).

 

That doesn't work on Tradestation as you can't mix and match tick and minute data series on the same chart.

 

Try ADE (all data anywhere) as a workaround. You'll find more info about it in the Tradestation.com forums.

Share this post


Link to post
Share on other sites

Does anyone here use Amibroker for their charts? The programming language seems very flexible, I just wish I knew how to program! If someone could convert these for that program I would be eternally grateful. Specifically the standard deviations for the VWAP. Thanks!

Share this post


Link to post
Share on other sites

Thanks Cooter and Blowfish for your help...finally got ADE working and I can see the PVP on my minute charts with the VWAP and SD bands...appreciate the knowledge on this board!

 

Testing it out now for a few days.

 

dbntina

Share this post


Link to post
Share on other sites

Could someone tell me which of these SD bands look correct (yellow or blue). Actually I cant work out why they differ as the actual formula I use is the same in both, I just am summing the bars slightly differently.

 

Be really great full if someone could compare with ensigns finishing values. Note that the YM chart ends at 3.15pm central

 

Cheers.

Nick

SDBands.thumb.png.8098b835c0573511cf6875db1834124e.png

SDBands1.thumb.png.f879a537f3f61126099248dc3f015ef0.png

Share this post


Link to post
Share on other sites

OK figured out what was wrong with the last two indicators but have come up with something that I think is OK.

 

The reason for this is that there are some performance issues with the indicator here as it has to scan the series back to the days start when there is a new tick. Applying it to a tick chart (especially at the end of the day) it slows right down.

 

Anyway I figured there should be a way to do it using running statistics and indeed there is. There is a side benefit to doing it this way as you don't get cumulative rounding errors (according to the signal processing guys). This does not get rid of the sampling inaccuracy that Nick mentions earlier in the thread.

 

I'd welcome comments? I wonder if rounding errors would explain the 2 or 3 ticks difference?

SDBands2.thumb.png.de3c7b969a32149f625f725f3d8a61dc.png

Share this post


Link to post
Share on other sites

One last chart a 1 tick of the same period as the last post (yesterdays ER2). Looks good to me? It is much much quicker this way and its plausible to run it on 1 tick charts (meaning complete accuracy is attainable if desired). If it looks good enough I'll upload it.

 

Incidentally watching PvP for the last week or two and comparing tick precise with 1 & 2 minutes I think I might have changed my mind - tick precise would have kept you out of a couple of bad trades due to quicker 'flipping'

 

Cheers

SDBands3.thumb.png.e2771bb7f91a4cf90df76e235f6580ac.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • Date: 16th April 2024. Market News – Stocks and currencies sell off; USD up. Economic Indicators & Central Banks:   Stocks and currencies sell off, while the US Dollar picks up haven flows. Treasuries yields spiked again to fresh 2024 peaks before paring losses into the close, post, the stronger than expected retail sales eliciting a broad sell off in the markets. Rates surged as the data pushed rate cut bets further into the future with July now less than a 50-50 chance. Wall Street finished with steep declines led by tech. Stocks opened in the green on a relief trade after Israel repulsed the well advertised attack from Iran on Sunday. But equities turned sharply lower and extended last week’s declines amid the rise in yields. Investor concerns were intensified as Israel threatened retaliation. There’s growing anxiety over earnings even after a big beat from Goldman Sachs. UK labor market data was mixed, as the ILO unemployment rate unexpectedly lifted, while wage growth came in higher than anticipated – The data suggests that the labor market is catching up with the recession. Mixed messages then for the BoE. China grew by 5.3% in Q1 however the numbers are causing a lot of doubts over sustainability of this growth. The bounce came in the first 2 months of the year. In March, growth in retail sales slumped and industrial output decelerated below forecasts, suggesting challenges on the horizon. Today: Germany ZEW, US housing starts & industrial production, Fed Vice Chair Philip Jefferson speech, BOE Bailey speech & IMF outlook. Earnings releases: Morgan Stanley and Bank of America. Financial Markets Performance:   The US Dollar rallied to 106.19 after testing 106.25, gaining against JPY and rising to 154.23, despite intervention risk. Yen traders started to see the 160 mark as the next Resistance level. Gold surged 1.76% to $2386 per ounce amid geopolitical risks and Chinese buying, even as the USD firmed and yields climbed. USOIL is flat at $85 per barrel. Market Trends:   Breaks of key technical levels exacerbated the sell off. Tech was the big loser with the NASDAQ plunging -1.79% to 15,885 while the S&P500 dropped -1.20% to 5061, with the Dow sliding -0.65% to 37,735. The S&P had the biggest 2-day sell off since March 2023. Nikkei and ASX lost -1.9% and -1.8% respectively, and the Hang Seng is down -2.1%. European bourses are down more than -1% and US futures are also in the red. CTA selling tsunami: “Just a few points lower CTAs will for the first time this year start selling in size, to add insult to injury, we are breaking major trend-lines in equities and the gamma stabilizer is totally gone.” Short term CTA threshold levels are kicking in big time according to GS. Medium term is 4873 (most important) while the long term level is at 4605. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HFM Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Andria Pichidi Market Analyst HFMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • Date: 15th April 2024. Market News – Negative Reversion; Safe Havens Rally. Trading Leveraged Products is risky Economic Indicators & Central Banks:   Markets weigh risk of retaliation cycle in Middle East. Initially the retaliatory strike from Iran on Israel fostered a haven bid, into bonds, gold and other haven assets, as it threatens a wider regional conflict. However, this morning, Oil and Asian equity markets were muted as traders shrugged off fears of a war escalation in the Middle East. Iran said “the matter can be deemed concluded”, and President Joe Biden has called on Israel to exercise restraint following Iran’s drone and missile strike, as part of Washington’s efforts to ease tensions in the Middle East and minimize the likelihood of a widespread regional conflict. New US and UK sanctions banned deliveries of Russian supplies, i.e. key industrial metals, produced after midnight on Friday. Aluminum jumped 9.4%, nickel rose 8.8%, suggesting brokers are bracing for major supply chain disruption. Financial Markets Performance:   The USDIndex fell back from highs over 106 to currently 105.70. The Yen dip against USD to 153.85. USOIL settled lower at 84.50 per barrel and Gold is trading below session highs at currently $2357.92 per ounce. Copper, more liquid and driven by the global economy over recent weeks, was more subdued this morning. Currently at $4.3180. Market Trends:   Asian stock markets traded mixed, but European and US futures are slightly higher after a tough session on Friday and yields have picked up. Mainland China bourses outperformed overnight, after Beijing offered renewed regulatory support. The PBOC meanwhile left the 1-year MLF rate unchanged, while once again draining funds from the system. Nikkei slipped 1% to 39,114.19. On Friday, NASDAQ slumped -1.62% to 16,175, unwinding most of Thursday’s 1.68% jump to a new all-time high at 16,442. The S&P500 fell -1.46% and the Dow dropped 1.24%. Declines were broadbased with all 11 sectors of the S&P finishing in the red. JPMorgan Chase sank 6.5% despite reporting stronger profit in Q1. The nation’s largest bank gave a forecast for a key source of income this year that fell below Wall Street’s estimate, calling for only modest growth. Apple shipments drop by 10% in Q1. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HFM Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Andria Pichidi Market Analyst HFMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • The morning of my last post I happened to glance over to the side and saw “...angst over the FOMC’s rate trajectory triggered a flight to safety, hence boosting the haven demand. “   http://www.traderslaboratory.com/forums/topic/21621-hfmarkets-hfmcom-market-analysis-services/page/17/?tab=comments#comment-228522   I reacted, but didn’t take time to  respond then... will now --- HFBlogNews, I don’t know if you are simply aggregating the chosen narratives for the day or if it’s your own reporting... either way - “flight to safety”????  haven ?????  Re: “safety  - ”Those ‘solid rocks’ are getting so fragile a hit from a dandelion blowball might shatter them... like now nobody wants to buy longer term new issues at these rates...yet the financial media still follows the scripts... The imagery they pound day in and day out makes it look like the Fed knows what they’re doing to help ‘us’... They do know what they’re doing - but it certainly is not to help ‘us’... and it is not to ‘control’ inflation... And at some point in the not too distant future, the interest due will eat a huge portion of the ‘revenue’ Re: “haven” The defaults are coming ...  The US will not be the first to default... but it will certainly not be the very last to default !! ...Enough casual anti-white racism for the day  ... just sayin’
    • Date: 12th April 2024. Producer Inflation On The Rise, But Will Earnings Hold Demand Steady?     Producer inflation rose slightly less than previous expectations, but the annual figure continues to rise. The annual PPI rose to 2.1% and the Core PPI rose to 2.4%. The NASDAQ and SNP500 end the day higher, but the Dow Jones continues to struggle. This morning earnings kick off with the banking sector including JP Morgan, BlackRock and Wells Fargo. All 3 stocks trade higher during pre-trading hours. The Euro trades lower against all currencies despite the ECB’s attempt to establish a hawkish tone. USA100 – The NASDAQ Climbs Higher, But Is the Growth Sustainable? The NASDAQ was the only index which did not witness a significant decline at the opening of the US session. In addition to this, the USA100 is the only index which is witnessing indications of a bullish market. The price has crossed onto a higher high breaking the resistance level at $18,269. The index is also trading above the 75-Bar EMA and at the 65.00 level on the RSI which signals buyers are controlling the market. However, a similar large bullish impulse wave was also formed on the 3rd and 5th of the month and was followed by a correction. Therefore, investors need to be cautious of a bearish breakout which may signal a correction back to the 75-bar EMA (18,165). The medium-term growth and its sustainability will depend on the upcoming earnings data.   Bond yields declined during this morning’s Asian session by 18 points, which is positive for the stock market. However, even with the decline, bond yields remain significantly higher than Monday’s opening yield. This week the 10-year bond yield rose from 4.424 to 4.558, which is a concern. If bond yields again start to rise, the stock market potentially can again become pressured. 25% of the NASDAQ ended the day lower and 75% higher. This gives a clear indication of the sentiment towards the technology sector and reassures traders about the price movement. Another positive was all of the top 12 influential stocks rose in value. Apple, NVIDIA and Broadcom saw the strongest gains, all rising more than 4%. Producer inflation read slightly lower than expectations, however, the index continues to rise. The Producer Price Index rose from 1.6% to 2.1% and the Core PPI from 2.1% to 2.4%. Therefore, it is not indicating inflation will become easier to tackle in the upcoming months. For this reason, investors should note that inflation and the monetary policy is still a risk and can trigger strong bearish impulse waves. EURUSD – The Euro Declines Against Major Currencies The European Central Bank is attempting to concentrate on the positive factors and give no indications of when the committee may opt to cut rates. For example, President Lagarde advises “sales figures” remain stable, but the issue remains they are stably low. Officials said the decline in prices generally confirms medium-term forecasts and is ensured by a decrease in the cost of food and goods. Most experts continue to believe that the first reduction in interest rates will happen in June, and there may be three or four in total during the year. Due to this, the Euro is declining against all currencies including the Pound, Yen and Swiss Franc. The US Dollar Index on the other hand trades 0.39% higher and is almost trading at a 23-week high. Due to this momentum, the price of the exchange continues to indicate a decline in favor of the US Dollar.   Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HFM Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Michalis Efthymiou Market Analyst HMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • $MSFT Microsoft stock top of range breakout above 433.1, https://stockconsultant.com/?MSFT
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.