NexusFi: Find Your Edge


Home Menu

 





VSA for ThinkorSwim


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one snowcloud with 93 posts (25 thanks)
    2. looks_two StockJock with 91 posts (27 thanks)
    3. looks_3 cbritton with 37 posts (71 thanks)
    4. looks_4 swimtrader with 22 posts (19 thanks)
      Best Posters
    1. looks_one Hornblower with 2.3 thanks per post
    2. looks_two cbritton with 1.9 thanks per post
    3. looks_3 StockJock with 0.3 thanks per post
    4. looks_4 snowcloud with 0.3 thanks per post
    1. trending_up 315,637 views
    2. thumb_up 223 thanks given
    3. group 86 followers
    1. forum 434 posts
    2. attach_file 131 attachments




 
Search this Thread

VSA for ThinkorSwim

  #1 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

I'm working on converting the NinjaTrader VPA indicator (found in the downloads section) to ThinkorSwim. I'm still at the beginning stages right now and I'm starting this thread so the readers here can keep me honest

Included are 2 screen shots of GDX with the indicator in ToS and NT. There are some differences in that the NT version is showing some items the ToS version is not and vice versa it seems. I hope to iron out the differences in the following days.

ToS can't draw some of the symbols the same way NT can. For example, a diamond symbol does not exist (as of this post) in ToS, so I am resorting to just using a circle. Downward pointing triangles are not supported in ToS either, so this indicator will use the upward pointing triangle. These differences will be noted in this thread.

My first objective is to get the conditions correct on displaying the symbols on the bars so that the ToS version matches the NT version. Second, I will create the volume histogram with the colored bars to match. Third, I will attempt to document as much as possible the differences between the two and note any caveats.

The ToS study has been added here, but the file extension has been changed to .txt. If you want to import it to ToS, then you have to either rename the extension to .ts and import it or copy the content of the file into a new ToS study.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Attached Thumbnails
Click image for larger version

Name:	NT_VSA_GDX.PNG
Views:	4250
Size:	58.1 KB
ID:	10894   Click image for larger version

Name:	ToS_VSA_GDX.png
Views:	2721
Size:	48.7 KB
ID:	10895  
Attached Files
Elite Membership required to download: VPAv1STUDY.txt
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Can I use Ehlers Periodogram as the lookback for another …
NinjaTrader
MC Advanced Simulated Trading.
MultiCharts
CosMik Z-TP Trading System
NinjaTrader
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #3 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


While I was comparing the ToS and NT VSA indicators that I posted earlier, I was looking at the test for no supply. In the NT version for GDX, 9/28 is a no supply bar, but not on the ToS chart for the same instrument and date. I traced this back to the results for computing the isNarrowSpreadBar which is defined as this in the NT version:

 
Code
                            
spread.Set(High[0] - Low[0]);
avgSpread = (Wilder(spreadvolumeEmaAve)[0]);
isNarrowSpreadBar.Set(spread[0] < (narrowSpreadFactor avgSpread)); 
The reason for the difference in the ToS version is that the results for the avgSpread is not equal to the NT computation which could lead to different values when computing the no supply test. ToS has a built in WildersAverage function which is what I used. The NT version has a provided Wilders indicator and it has no author on it. This is the meat of the code from that indicator:

 
Code
                            
protected override void OnBarUpdate()
{
    
// Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    
if (CurrentBar == 
    {
        
firstAvg.Set(0);
        return;
    }
    
//if (CurrentBar + 1 == Period )
    
{    
        
//calculate first average
        
firstAvg.SetSMA(Inputperiod)[0]);
    }
    
WAvg.Set( (firstAvg[1] * (period -1) + Input[0]) / period);

Googling, I found this definition of wilders ma:

Wilder's Current Day Moving Average = (Previous Day Wilder's Moving Average * (n-1) + Current Day Price)/n

So the Wilders indicator that comes with VPA is not correct. It should be something like this:

WAvg.Set( (WAvg.Get(1) * (period -1) + Input[0]) / period);

I will make some changes to this and post my findings here.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

I managed to reproduce the NT Wilder's indicator in ToS.

 
Code
                            
declare lower;
input length 30;

rec spread high low;

# ToS version
plot waa WildersAverage(spreadlength)[0];

# NT version
rec nta compoundValue(1average(spread,length), 0);
plot ntb = (nta[1]*(length-1) + spread)/length
Plotting the 2 values on the same graph shows that they are different. See the attached image.

I did a random sampling comparison between the NT versions on ToS and NT. The values are accurate to within 2 decimal places.

I will be posting the updated NT version shortly.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Attached Thumbnails
Click image for larger version

Name:	ToS_Comp1.png
Views:	1835
Size:	68.4 KB
ID:	10946  
Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

This is the code that I think should be used for the NT Wilders indicator:

 
Code
                            
            if (CurrentBar <= period)
            {
                return;
            }
            else if (
CurrentBar == period+1)  // the first calculation in the Wilders average
            
{
                
WAvg.Set(SMA(Input,period)[0]);
            }
            else 
// all subsequent calculations
            
{
                
WAvg.Set((WAvg[1] * (period-1) + Input[0])/period);
            } 
I did some comparison between the values of plotting the spread using the wilders average on both ToS and NT. For the first 60 bars or so, the values differ but that difference decreases. I'm not sure why that is. Maybe something in the way I wrote the indicator? After those 60 bars, there is no difference to within 2 decimal places.

At this point, I don't know the authors original intention. Did they mean to use Wilders average and incorrectly implement the indicator? Or was this intentional? If the former, then the version in the download section is incorrect and, I think, the above patch should be what is needed. The downside is that it *could* give false signals as what I am suspecting is the reason for the difference between the ToS and NT version that I mentioned before (not counting my code errors ).

My expectation that someone with authority on this subject chiming in here is pretty slim and my knowledge of the VSA algorithm is limited. That being said, I am proceeding with the assumption that the Wilders average (as defined by Wilder) is to be used so future NT charts in this thread will be based on the revised indicator.

If you are using NT's VPA indicator, I hope you take this under advisement.

Anyways, I will post more charts for comparison and iron out more issues.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Started this thread Reply With Quote
  #6 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

So what's the deal with this bit of code?

 
Code
                            
protected override void OnBarUpdate()
{

    if (
CurrentBar volumeEmaAve) return;
    
spread.Set(High[0] - Low[0]);
    ...
    
// Calculate Range information
    
avgSpread = (Wilder(spreadvolumeEmaAve)[0]);
    ...

In the Wilder function, the first element computed is the SMA on the given data series. However, the first condition of the OnBarUpdate() says that if the current bar is less than volumeEmaAve, then exit. Let's assume that volumeEmaAve = 10. So when CurrentBar == 10, the first value of the spread is set and the SMA for the part of Wilders indicator is calculated on the spread. Right? So the SMA on 10 bars of data is

Sum(High[n] - Low[n])/10 for n = 0..9

Right? But only 1 value of the spread data series is set because of the first condition. So that sum is just

(High[0] - Low[0])/10

This creates incorrect computed values for the average spread.

To get the correct sum of the spread for the first 10 bars, the spread data series must be set for bars 1..9. The following code will set the spread then perform the condition:

 
Code
                            
protected override void OnBarUpdate()
{
    
spread.Set(High[0] - Low[0]);
    if (
CurrentBar volumeEmaAve) return;
    ...
    
// Calculate Range information
    
avgSpread = (Wilder(spreadvolumeEmaAve)[0]);
    ...

Now the SMA on the Wilders algorithm is correctly computed.

Be careful with that C# code!

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 thatguy 
New Brunswick, NJ
 
Experience: Intermediate
Platform: N/A
Trading: N/A
Posts: 133 since Jun 2009
Thanks Given: 46
Thanks Received: 157

If I can put in my two cents, I would suggest you take a step back and think what you want to accomplish.

VSA is based on a few simple concepts, like No Demand, No Supply, Tests, Thrusts, etc. The VSA Ninja Indicator is just one author's interpretation of mathematically defining these concepts.

If your goal is to assume that the author of the NinjaTrader's VSA interpretation is "correct" and try to match it exactly, then it is important to port his code exactly.

On the other hand, VSA is not a mechanical system and should not be treated as such. I think this more important to understand the concepts and once you do, this really doesn't matter what kind of moving average you use to define the average range as long as you do it in a consistent way. There is no way to say one is better than the other.

Reply With Quote
Thanked by:
  #8 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


thatguy View Post
If I can put in my two cents, I would suggest you take a step back and think what you want to accomplish.

VSA is based on a few simple concepts, like No Demand, No Supply, Tests, Thrusts, etc. The VSA Ninja Indicator is just one author's interpretation of mathematically defining these concepts.

If your goal is to assume that the author of the NinjaTrader's VSA interpretation is "correct" and try to match it exactly, then it is important to port his code exactly.

On the other hand, VSA is not a mechanical system and should not be treated as such. I think this more important to understand the concepts and once you do, this really doesn't matter what kind of moving average you use to define the average range as long as you do it in a consistent way. There is no way to say one is better than the other.

The goal is to have a usable ToS version based on the NT version of what I think the author's intentions are. I am detailing this process so others can benefit from this conversion and hopefully 1) gain an understanding of how complex coding can be, and 2) don't assume any indicator does what they think it actually does.

My assumption is with the intention of what the author means, not blindly porting the indicator line for line. If that means corrections and improvements can be proposed back into the NT version, then I think I have accomplished something. I have been pointing out "issues" with the NT version for the purpose of learning and to make others aware that the implementation may produce false signals based on that implementation. While VSA is not a mechanical system, it does act as a guide for the user to make informed decisions.

Making observations and proposing corrections in this sense is analogous to getting a car mechanic to inspect your Prius. If you assume that the brakes on your Prius work well for you, then there's no need to have someone double check Toyota's work.


Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

In the variables section in the NT version, narrowSpreadFactor is defined as a double with a value 0.7:

 
Code
                            
        private double highCloseFactor 0.70;
        private 
double lowCloseFactor 0.25;
        private 
double narrowSpreadFactor 0.7
However, the Properties section reassigns these values to have a minimum of 1:

 
Code
                            
        [Description("High Close Factor")]
        [
Category("Price Parameters")]
        [
Gui.Design.DisplayNameAttribute("High Close Factor")]
        public 
double DwHighClose
        
{
            
get { return highCloseFactor; }
            
set highCloseFactor Math.Max(1value); }
        }

        [
Description("Low Close Factor")]
        [
Category("Price Parameters")]
        [
Gui.Design.DisplayNameAttribute("Low Close Factor")]
        public 
double DwLowClose
        
{
            
get { return lowCloseFactor; }
            
set lowCloseFactor Math.Max(1value); }
        }

        [
Description("Narrow Spread Factor")]
        [
Category("Spread Parameters")]
        [
Gui.Design.DisplayNameAttribute("Narrow Spread Factor")]
        public 
double DwNarrowSpread
        
{
            
get { return narrowSpreadFactor; }
            
set narrowSpreadFactor Math.Max(1value); }
        } 
For example, when this indicator is added to a chart, narrowSpreadFactor is set to 1 and not the default of 0.7. ultraHighVolfactor and aboveAvgVolfactor have minimum property values of 1, but these have a default of 2 and 1.5, respectively.

If you want to use the default values, then I suggest you set the above three to have a minimum of 0 in the properties section.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Started this thread Reply With Quote
  #10 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


Sorry I have not posted much lately. I've been busy with other things.

With the changes in the NT version I mentioned in the previous postings, I am now able to match both.

I have a new version of the VSA study for ThinkorSwim. This version has the input parameters for the scaling factors as well as paint bar colors by trend (see the screen shot). I also added code to hide the titles for each plot since that can get very messy and not really convey any useful information.

(Please remember that the attached ToS study is a .txt file. If you want to import it into ToS, you need to change the extension to .ts or copy the content of the file into a new ToS study.)

ToS has some rudimentary text plotting functions that I plan on using for matching with some of the banners on the NT version. I'm not sure how this will work out, but I'll try to get something useful in the coming days. I plan on making the volume plot at some point as well.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Attached Thumbnails
Click image for larger version

Name:	ToS_VSA_GDX.png
Views:	1481
Size:	48.0 KB
ID:	11450  
Attached Files
Elite Membership required to download: VPAv1STUDY.txt
Started this thread Reply With Quote
Thanked by:




Last Updated on May 21, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts