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 304,527 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

  #391 (permalink)
Hornblower
Oxnard California
 
Posts: 10 since Aug 2012
Thanks Given: 2
Thanks Received: 23

The below code is for finding stocks that provides the VSA Green Arrow indications in TOS Scan Hacker. This code must be entered as one of the criteria and as custom code. I also add criteria for price above 5 and volume above 300,000 shares for day. The nice thing about the code is that you can selectively use for monthly, weekly, daily, etc by changing the time period. This may affect the volume filter but I am not sure.


# Arguments

def volumeEMALength = 30;
def narrowSpreadFactor = 0.7;
def wideSpreadFactor = 1.5;
def aboveAvgVolfactor = 1.5;

#######
# Calculations

rec spread = high - low;
def median = (high + low ) / 2;
rec avgVolume = compoundValue(volumeEMALength, ExpAverage(volume,
volumeEMALength), Double.NaN);

# Calculate Volume moving average and it's standard deviation
rec sAvgVolume = compoundValue(volumeEMALength, Average(volume,
volumeEMALength), Double.NaN);
def sAvgVolumeSTD = stdev(sAvgVolume, volumeEMALength);

# check if the vloume has been decreasing in the past two days.
def isTwoDaysLowVol = (volume < volume[1] && volume[0] < volume[2]);

# Calculate Range information
def avgSpread = WildersAverage(spread, volumeEMALength)[0];
rec isWideSpreadBar = (spread > (wideSpreadFactor * avgSpread));
rec isNarrowSpreadBar = (spread < (narrowSpreadFactor * avgSpread));





# Check if the close is in the Highs/Lows/Middle of the bar.
# C_RP 20100809
# original code - def x1 = if (close == low) then avgSpread else (spread /(close - low));
def x1 = if (high == low) then 2.0 else if (close == low) then 2.65 else (spread /
(close - low));
# C_RP try the line below with various divisors totalSum result in a minimum of 2.3 on a spread of 1 pip instead of using a fixed 2.3 as in the line above
# def x1 = if (high==low) then 2.0 else if (close == low) then (spread / 0.43 ) else (spread / (close - low));

# Price information
rec isUpBar = close > close[1];
rec isDownBar = close < close[1];
def isUpCloseBar = (x1 < 2);
def isDownCloseBar = (x1 > 2);
def isMidCloseBar = (x1 < 2.2 && x1 > 1.8);
def isVeryHighCloseBar = (x1 < 1.35);
# C_RP 20100809 added isVeryLowCloseBar
def isVeryLowCloseBar = (x1 >= 2.65);


# Trend Definitions

rec fiveDaysSma = compoundValue(5, Average(close, 5)[0], Double.NaN);
def LongTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length =
40)[0];
def ShortTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length =
5)[0];
def MiddleTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length =
15)[0];

# stdn, stdn0, stdn1, stdn2
def strengthInDownTrend = (volume[0] > volume[1] && isDownBar[1] && isUpBar[0]
&& (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 &&
MiddleTermTrendSlope < 0);

def strengthInDownTrend1 = (volume[0] > (sAvgVolume[0] * aboveAvgVolfactor) &&
isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) &&
ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0 && LongTermTrendSlope < 0);
def strengthInDownTrend2 = (volume[1] < sAvgVolume[0] && isUpBar[0] &&
isVeryHighCloseBar && volume[0] > sAvgVolume[0] && ShortTermTrendSlope < 0);


rec bycond1 = (strengthInDownTrend or strengthInDownTrend1);
# bycond


def isStrengthConfirmationBar = (isUpBar[0] && bycond1[1]);

# bycond2 C_RP UpClose on higher volume with all slopes down adds extra strength
def isStrengthConfirmationBar2 = (isUpBar[0] && isUpCloseBar[0] && volume[0] >
volume[1] && LongTermTrendSlope < 0 && bycond1[1]);


# Plot with green arrow

# green triangle up at bottom of the bar C_RP Green arrow up 4 * tickSize for strong strength_In_DownTrend
# plot isStrengthConfirmationBarPlot = if isStrengthConfirmationBar then (low - 5 * tickSize()) else if isStrengthConfirmationBar2 then (low - 9 * tickSize()) else Double.NAN;
plot isStrengthConfirmationBarPlot = (isStrengthConfirmationBar);
# green triangle up at bottom of the bar C_RP Green arrow up 7 * tickSize for strongest strength_In_DownTrend with isUpCloseBar
# plot isStrengthConfirmationBarPlot2 = if isStrengthConfirmationBar2 then (low - 9 * tickSize()) else Double.NAN;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Futures True Range Report
The Elite Circle
Build trailing stop for micro index(s)
Psychology and Money Management
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #392 (permalink)
StockJock
Chicago + Illinois/USA
 
Posts: 256 since Aug 2010
Thanks Given: 15
Thanks Received: 154


Hornblower View Post
The below code is for finding stocks that provides the VSA Green Arrow indications in TOS Scan Hacker. This code must be entered as one of the criteria and as custom code. I also add criteria for price above 5 and volume above 300,000 shares for day. The nice thing about the code is that you can selectively use for monthly, weekly, daily, etc by changing the time period. This may affect the volume filter but I am not sure.

Great code, Hornblower. How do you get the "rec" command to work in a ThinkScript custom quote? For a long time "rec" commands didn't work in ThinkScript custom quotes, they worked only in indicators and I've been looking for a way arround that or waiting for the TOS developers to change ThinkScript. Also, could you show me what part of your code is the reference indicator and which part is the custom quote? Thanks.

Reply With Quote
Thanked by:
  #393 (permalink)
tonylipton
jennings missouri america
 
Posts: 24 since Sep 2010
Thanks Given: 5
Thanks Received: 28


it could be that if a rec command doesn't reference itself then it is treated as a def command?

Reply With Quote
  #394 (permalink)
Hornblower
Oxnard California
 
Posts: 10 since Aug 2012
Thanks Given: 2
Thanks Received: 23

The code originated from the TOS thinkscript from the latest Volume Spread Analysis code (VPAV1_09Study.ts) provided in this thread. I just extracted the code from that source that is necessary for scanning only for a green arrow and let the TOS scanner find those stocks meeting the criteria. Remember the code is limited to find those stocks that have a green arrow for that day but could be modified for green arrow for week, hour, etc by selecting the aggregate period. The default is the "D" (daily).

Early question on why the "rec" works is not important. All I know is that it works now when you paste the code into the custom box for scanning. If you get errors, just modify the code to make it work using thinkscript code. TOS may have also changed the rules in using "rec" since you previously utilized it. TOS also provides a wizard to aid "non-programmers" in building custom code.


Good Luck.

Reply With Quote
  #395 (permalink)
 
WilleeMac's Avatar
 WilleeMac 
Prospect, KY. USA
 
Experience: None
Platform: Sierra Chart
Broker: Infinity
Trading: /CL
Posts: 687 since Jan 2012
Thanks Given: 309
Thanks Received: 617

I took the links provided and compiled them into a word document

Hope this proves useful/ helpful

Regardless of time frame (these seem to be day) this applies to all timeframes - if I didn't suggest day you would no different than five (5) minute intraday

Think fractals

-Bill

Attached Files
Elite Membership required to download: VPA Logic and Setups2.doc
Follow me on Twitter Reply With Quote
Thanked by:
  #396 (permalink)
tottenham
west palm beach
 
Posts: 2 since May 2012
Thanks Given: 0
Thanks Received: 0

I am wondering where this thread migrated to, there was mention of bigmike's. How is the study being used? Why is it a video file and how to import to TOS?
Appreciate any information, thanks.

Reply With Quote
  #397 (permalink)
 
WilleeMac's Avatar
 WilleeMac 
Prospect, KY. USA
 
Experience: None
Platform: Sierra Chart
Broker: Infinity
Trading: /CL
Posts: 687 since Jan 2012
Thanks Given: 309
Thanks Received: 617

Windows thinks it's a video file because of the .ts extension

You can either manually cut and paste the code or use the TOS import function

If you use the import function it must have a .ts extension or TOS will not recognize it

-Bill_M

Follow me on Twitter Reply With Quote
  #398 (permalink)
tonylipton
jennings missouri america
 
Posts: 24 since Sep 2010
Thanks Given: 5
Thanks Received: 28


snowcloud View Post
After a few weeks work I have finished this round of changes to the study. Some of the changes are referenced in previous posts but many are not. One thing that bothered me about the original study was that the color scheme assigned to the symbols seemed to make no sense at all. (By reading a NinjaTrader thread on the original code I discovered that the programmer himself was less than satisified with the color scheme). I changed it using the ROYGBIV color spectrum as a model. I also added UpArrow and DownArrow symbols to indicate the strongest indications. The legend and a brief explanation is pasted below.

I was also bothered by the fact that candles identified as UpThrusts often don't look anything like traditional UpThrusts. However, in most cases the Red Squares, Triangles, and DownArrows attached to those candles seem to work pretty well as indications of an impending downtrend. Because they seem to work pretty well as indicators I decided not to change the underlying code, at least until I have a clearer picture of why they work but don't look like UpThrusts. I'm still watching them.

Another thing I noticed is that often times a group of two or three candles that don't contain an UpThrust identification individually would be considered an UpThrust if taken together. So, I added Two Period and Three Period UpThrust indicators. I just did this today so I'm still evaluating their effectiveness.

I'm very interested in hearing what works, what doesn't work, and what other traders think of this study so please post comments, criticisms, etc. here. I won't have much time to devote to tweaking the code in the next few weeks or months because of other projects I am working on, but I'm still very interested in hearing comments about the study.

Btw, I use this study mostly on 2-minute candles, but am also watching it on 5 and 15-minute candles. I've attached an image of a chart from this morning which shows, among other things, two really good examples of various kinds of UpThrusts (Red Square, Triangle, and DownArrow; Magenta Three Period UpThrust) indicating impending downtrends. It also shows two good examples of Stopping Volume (Green Circle) after the first downtrend of the second test of highs at around 7:00 and at the end of the longer-term downtrend at about 8:00.

And finally, I don't know why the original code for NinjaTrader is called VPA (Volume Price Analysis) instead of VSA but I just kept the acronym in the filename for consistency's sake.

Legend from the study Comments:
# This is a conversion of the NinjaTrader VPA indicator. ToS does not support directional
# triangles and diamonds, so there are some differences. The triangles are left as is, just
# not pointing a specific direction. The diamonds have been replaced with circles.

# C_RP Original notes by cbritton are above. Changes made after 20100722 by Richard Paske are marked below by the C_RP comment tag. A few bugs were fixed. More significantly, the color scheme for symbols was changed radically in an attempt to map directional strength to hue based on the ROYGBIV color spectrum. In addition, a symbol's shape and its vertical position above or below a candle now imparts added meaning to it. In general, the strength of a symbol is assigned by its color and shape in that order. In certain circumstances a symbol's vertical offset from its candle's top or bottom strengthens the symbol's meaning. The symbol strength hierarchy is defined as follows:

# 1. Color: Symbols below candles are assigned strength from weakest to strongest in this order: white (or grey), cyan (blue/green), green. A red symbol under a candle indicates the failure of the symbol attached below the candle immediately preceding it.
# Symbols above candles are assigned strength from weakest to strongest in this order: yellow, orange, red. A green symbol above a candle indicates the failure of a symbol attached above the candle immediately preceding it. A magenta (pinkish purple) square above a candle is a special case indicating Distribution. Another special case for testing purposes as of 20100830 is a white triangle high above a candle indicating a Gravestone Doji.
# Symbols drawn on the middle of a candle are of two types with one variation. A green circle indicates Effort to Move Up on up bars. A magenta (pinkish purple) circle indicates Effort to Move Down on down bars except for red down bars on which magenta displays poorly. In order to be seen easily, yellow circles indicate Effort to Move Down on red down bars.

# 2. Shape: A symbol of a given color is assigned increasing strength according to this hierarchy (from low to high): circle, square, triangle, downward or upward arrow. In certain circumstances two symbols of the same shape and color will be stacked vertically, adding strength through the combined symbols. Occasionally, two different symbols will be stacked vertically because that candle satisfies the criteria for two indications.

# Listed below are the symbols and their meanings.



# ___Symbols in the Middle of Candles___
# Green Circle - Effort to Move Up
# Magenta Circle - Effort to Move Down
# Yellow Circle - Effort to Move Down on Red Down Candles

is there a reason why you would not want to know of a move up on green up candles? or is that called something else?

tia
tony

Reply With Quote
  #399 (permalink)
Jonny473
Frankfurt
 
Posts: 6 since Sep 2012
Thanks Given: 2
Thanks Received: 1

Hi guys, great code to scan for arrows!

Reply With Quote
  #400 (permalink)
Jonny473
Frankfurt
 
Posts: 6 since Sep 2012
Thanks Given: 2
Thanks Received: 1


I have a question:

Can the code below be turned around, so we can scan for the red arrows?


Many thanks
Jonas

Reply With Quote




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