![]()
Ruby:def Upper = Reference VWAP(-2,2,"DAY").UpperBand; plot VwapUpper = if close > SimpleMovingAvg(close,20) then Upper else Double.NaN; plot SMA_Example = SimpleMovingAvg(close,20);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
![]()
Ruby:def Upper = Reference VWAP(-2,2,"DAY").UpperBand; plot VwapUpper = if close > SimpleMovingAvg(close,20) then Upper else Double.NaN; plot SMA_Example = SimpleMovingAvg(close,20);
This is script with VWAP and LRL's:@Guille So technically, you cannot make part of a line disappear. BUT you can make it appear as though part of the line disappeared by assigning the color of the line to be the same color as the chart background thus it blends with the background and is not 'seen'.
You didn't provide what script you are working with so this is just an EXAMPLE of what your code would look like:
AssignValueColor(if VWAP_upper_band is greater than Upper_Linear_Regression_line then purple_color else Background_color);
You can see an example and directions here: https://usethinkscript.com/threads/disappearing-moving-average-for-thinkorswim.5881/#post-56173
def
if you do not want those displayed.plot MiddleLR = InertiaAll(close);
def dist = HighestAll(AbsValue(MiddleLR - close));
plot UpperBand = MiddleLR + dist;
plot LowerLR = MiddleLR - dist;
def vUpper = reference VWAP(-2,2,"DAY").UpperBand;
plot vWapUpper = if vUpper > UpperBand then vUpper else double.nan;
def MiddleLR = InertiaAll(close);
def dist = HighestAll(AbsValue(MiddleLR - close));
def UpperBand = MiddleLR + dist;
def LowerLR = MiddleLR - dist;
def vUpper = reference VWAP(-2,2,"DAY").UpperBand;
plot vWapUpper = if vUpper > MiddleLR then vUpper else double.nan;
I think the issue is that both VWAP and LRL def's use "price"Based on the code you provided, this at least looks like this is what you're trying to do. I can assure you that the code does in fact work. The problem, however, is that it is rare for the upper vwap band to be higher than the upper regression line. I had to experiment with several different aggregations and lengths of chart just to get this occur. Change the fist three plots todef
if you do not want those displayed.
Code:plot MiddleLR = InertiaAll(close); def dist = HighestAll(AbsValue(MiddleLR - close)); plot UpperBand = MiddleLR + dist; plot LowerLR = MiddleLR - dist; def vUpper = reference VWAP(-2,2,"DAY").UpperBand; plot vWapUpper = if vUpper > UpperBand then vUpper else double.nan;
Here is another example, this one shows the upper vwap band only when it is above the center regression line.
Code:def MiddleLR = InertiaAll(close); def dist = HighestAll(AbsValue(MiddleLR - close)); def UpperBand = MiddleLR + dist; def LowerLR = MiddleLR - dist; def vUpper = reference VWAP(-2,2,"DAY").UpperBand; plot vWapUpper = if vUpper > MiddleLR then vUpper else double.nan;
I cannot make it to work.Based on the code you provided, this at least looks like this is what you're trying to do. I can assure you that the code does in fact work. The problem, however, is that it is rare for the upper vwap band to be higher than the upper regression line. I had to experiment with several different aggregations and lengths of chart just to get this occur. Change the fist three plots todef
if you do not want those displayed.
Code:plot MiddleLR = InertiaAll(close); def dist = HighestAll(AbsValue(MiddleLR - close)); plot UpperBand = MiddleLR + dist; plot LowerLR = MiddleLR - dist; def vUpper = reference VWAP(-2,2,"DAY").UpperBand; plot vWapUpper = if vUpper > UpperBand then vUpper else double.nan;
Here is another example, this one shows the upper vwap band only when it is above the center regression line.
Code:def MiddleLR = InertiaAll(close); def dist = HighestAll(AbsValue(MiddleLR - close)); def UpperBand = MiddleLR + dist; def LowerLR = MiddleLR - dist; def vUpper = reference VWAP(-2,2,"DAY").UpperBand; plot vWapUpper = if vUpper > MiddleLR then vUpper else double.nan;
Got it! It works beautifully. I changed the upper linear regression line to 75% as a compromised between the 50% and the full 100%. Check SONM and IPHA on the 1 minute chart on Friday 9/17/21 for examples. Thank you very much, Joshua!The code I gave you can be used by itself, it should not be added it to your existing code. Still, be aware that the upper vwap band hardly ever crosses above the upper regression line anyway, at least in any of the examples I cared to test.
Input DistPercent = 50;
Input HullLength = 20;
Input HullPercExt = 5;
plot MiddleLR = InertiaAll(close);
def dist = HighestAll(AbsValue(MiddleLR - close)) * (DistPercent * 0.01);
plot UpperBand = MiddleLR + dist;
plot LowerLR = MiddleLR - dist;
def vUpper = reference VWAP(-2,2,"DAY").UpperBand;
def Hull = hullMovingAvg(close,HullLength);
def hMA = Hull + (Hull * (HullPercExt * 0.01));
plot vWapUpper = if vUpper > UpperBand then vUpper else double.nan;
plot HullUpper = if hMA > UpperBand then hMA else double.nan;
def MACD = MovingAverage(MACDAveType, c, MACDFastLength) - MovingAverage(MACDAveType, c, MACDSlowLength);
def MACDValley = If(((MACD <= 0) && (MACD[0] < MACD[-1]) && (MACD[0] < Lowest(MACD[1], lookback4HighLow))), MACD, Double.NaN);
plot MACDValleyPlot = If(showMACD, MACDValley, Double.NaN);
MACDValleyPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
MACDValleyPlot.SetDefaultColor(Color.LIME);
MACDValleyPlot.HideBubble();
plot MACDValleyLine = MACDValleyPlot;
MACDValleyLine.EnableApproximation();
MACDValleyLine.SetStyle(Curve.Short_DASH);
MACDValleyLine.SetLineWeight(3);
@Cre8able I move your post here. There are a couple of solutions documented in this thread to allow a portion of a plot to be 'ignored'How do I plot where I only want to show certain portions of a plot line?
I plot the MACD. Then I plot the peaks or valleys I want (valley code below).
Then I want to connect "some" of the valleys. In the example below, I want to draw the line between point 1 and 2 and also between 3 and 4. But not between 2 and 3.
How do I code the plot to "ignore" that line?
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
![]() |
Part time novice swing trader | Questions | 2 | |
V | timeframe of chart as part of Alert in script | Questions | 1 | |
H | real-time volume indicator - can we use part of it to make zigzag real time? | Questions | 9 | |
J | How do I copy and paste part of a chart to excel? | Questions | 1 | |
A | MTF Open & High Line | Questions | 1 |
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.