Re: Fun with ThinkScript May 21, 2015 10:25PM |
Registered: 9 years ago Posts: 11 |
Re: Fun with ThinkScript May 24, 2015 11:07AM |
Registered: 8 years ago Posts: 8 |
Re: Fun with ThinkScript May 24, 2015 11:57AM |
Registered: 10 years ago Posts: 615 |
Quote
SKumar
I have a question. I am new to thinkscript. How do I get the 30 min. Candle close price of the high of the week for any ticker?
def weeklyHigh = high(period = AggregationPeriod.WEEK);
Re: Fun with ThinkScript May 24, 2015 04:18PM |
Registered: 8 years ago Posts: 8 |
Re: Fun with ThinkScript May 24, 2015 05:34PM |
Registered: 10 years ago Posts: 615 |
Quote
SKumar
Thanks Robert. I did go through the think script tutorial. But still it wasn't clear for me. What I am looking for is to find the close price of 30 min. Candle that corresponds to the high of the week when I iterate all the 30 min. Candles from Monday through Friday. Hope that makes makes sense
Regards
SKumar
# ----- Add label with the close price of the candle that hit the highest high of the week def HighCandleClose = if high == high(period = AggregationPeriod.WEEK) then close else HighCandleClose[1]; AddLabel(yes, "High Candle Close: " + HighCandleClose, Color.YELLOW);
TOS Sync Drawings BUG... May 24, 2015 08:24PM |
Registered: 9 years ago Posts: 67 |
Re: Fun with ThinkScript May 26, 2015 07:27AM |
Registered: 10 years ago Posts: 464 |
LinearRegCh100 slope issue... May 26, 2015 02:25PM |
Registered: 9 years ago Posts: 67 |
Re: Fun with ThinkScript May 26, 2015 02:47PM |
Registered: 12 years ago Posts: 321 |
Re: Fun with ThinkScript May 26, 2015 04:06PM |
Registered: 10 years ago Posts: 17 |
Trying to get the Premier Stochastic Oscillator to work in ToS May 26, 2015 06:07PM |
Registered: 8 years ago Posts: 2 |
Re: LinearRegCh100 slope issue... May 26, 2015 06:40PM |
Registered: 12 years ago Posts: 321 |
Re: Fun with ThinkScript May 26, 2015 08:09PM |
Registered: 9 years ago Posts: 67 |
Re: Fun with ThinkScript May 27, 2015 12:04AM |
Registered: 8 years ago Posts: 8 |
Re: Fun with ThinkScript May 27, 2015 08:00AM |
Registered: 10 years ago Posts: 615 |
Quote
asragov
Hello.
Found this on the Internet but it doesn't work in ToS.
Apologies for the newbie question - I don't seem to be able to make it work.
A version in TradingView is below the ToS code if that helps.
Thanks so much.
# // ========================== # // PREMIER STOCHASTIC # // Indicator # // ========================== # # Technical Analysis of Stocks & Commodities # August, 2008 # Premier Stochastic Oscillator by Lee Leibfarth # pp 30 - 36 # ported by R Houser # declare lower; # inputs: input Line1 = 0.9; input Line2 = 0.2; input StochLength = 8; input Period = 25; # variables: # oFastK(0), # oFastD(0), # oSlowK(0), # oSlowD(0), # Length(0), # NormStoch(0), # SmoothStoch(0), # Premier(0); # Value1 = Stochastic( h, l, c, StochLength, 1, 3, 1, oFastK, oFastD, oSlowK, oSlowD); def oFastK = 100 * ( ( close - Lowest( low, StochLength ) ) / ( Highest( high, StochLength ) - Lowest( low, StochLength ) ) ); def oFastD = Average( oFastK, 1 ); def oSlowK = oFastD; def oSlowD = Average( oSlowK, 3 ); # Length = iff(Period < 0, 1, squareroot(Period)); def Length = if Period < 0 then 1 else Sqrt( Period ); # NormStoch = .1 * (oslowK - 50); def NormStoch = 0.1 * ( oSlowK - 50 ); # SmoothStoch = xaverage(xaverage(NormStoch, Length), Length); def SmoothStoch = ExpAverage( ExpAverage( NormStoch, Length ), Length ); plot Premier = ( Exp( 1 * SmoothStoch ) - 1 ) / ( Exp( 1 * SmoothStoch ) + 1 ); Premier.SetDefaultColor( Color.BLUE ); plot pLine1 = Line1; pLine1.SetDefaultColor( Color.BLACK ); plot pLine2 = Line2; pLine2.SetDefaultColor( Color.GRAY ); plot nLine1 = -1 * Line1; nLine1.SetDefaultColor( Color.BLACK ); plot nLine2 = -1 * Line2; nLine2.SetDefaultColor( Color.GRAY );
Re: Fun with ThinkScript May 27, 2015 08:20AM |
Registered: 10 years ago Posts: 615 |
Quote
jluis.nra
Hello, how can I plot a small horizontal line for the week open of 4 candles ago?
input LookBack = 4; def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); def startBar = lastBar - LookBack; plot priorWeeklyOpen = if BarNumber() < startBar then Double.NaN else GetValue(open(period = "week" ), BarNumber() - startBar);
Re: Fun with ThinkScript May 27, 2015 11:50AM |
Registered: 10 years ago Posts: 17 |
Re: Fun with ThinkScript May 27, 2015 11:34PM |
Registered: 9 years ago Posts: 14 |
Re: Fun with ThinkScript May 28, 2015 08:37AM |
Registered: 10 years ago Posts: 615 |
Quote
netarchitech
Is it possible to use thinkscript to simply find the slope of the Linear Regression Channel (LinearRegCh100) and use it in a scan? I've searched all over with no luck...
Quote
netarchitech
UPDATE: Further searching yielded the following:
[tlc.thinkorswim.com]
Unfortunately, if I understand correctly, this enhancement appears to only apply to user-defined drawings. Plus, I don't want to draw on the price chart. This information would only be used within a scan...
With that said, it is encouraging to know the metadata is captured. The question remains: Can thinkScript access the metadata?
# manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = absValue(angle) >= minAngle;
Re: Fun with ThinkScript May 28, 2015 08:42AM |
Registered: 9 years ago Posts: 12 |
Re: Fun with ThinkScript May 28, 2015 09:21AM |
Registered: 10 years ago Posts: 615 |
Quote
ht65
Robert,
I am lookong to build a MA scan to display the number of days a stock has traded above a certain MA for the last say 500 days..
any help appreciated.. tip coming your way!
Re: Fun with ThinkScript May 28, 2015 09:23AM |
Registered: 9 years ago Posts: 12 |
Re: Fun with ThinkScript May 28, 2015 11:44AM |
Registered: 10 years ago Posts: 615 |
Quote
ht65
Robert,
I am lookong to build a MA scan to display the number of days a stock has traded above a certain MA for the last say 500 days..
any help appreciated.. tip coming your way!
Quote
ht65
looking for total number of days so that i can then rank them by stocks that had the most days above a certain MA..
input MA_Length = 200; #hint MA_Length: moving average length input LookBack = 500; #hint LookBack: number of days used in calculations plot MA = Average(close, MA_Length); def above = close > MA; def DaysAbove = Sum(above, LookBack); AddLabel(yes, DaysAbove + "/" + lookback + " days above MA" + ma_length, Color.WHITE);
# manually change the input values before using as a watchlist column input MA_Length = 200; input LookBack = 500; def MA = Average(close, MA_Length); def above = close > MA; plot DaysAbove = Sum(above, LookBack);
Quote
ht65
love your new blog by the way..
Re: Fun with ThinkScript May 28, 2015 12:04PM |
Registered: 9 years ago Posts: 12 |
Re: Fun with ThinkScript May 28, 2015 04:52PM |
Registered: 10 years ago Posts: 615 |
Quote
brazilianpillar
Robert,
I found this risk/reward indicator that plots your stop and target based on the amount you're trading with, how much you're willing to risk and the risk/reward ratio you want. I don't know if it's yours or not, i can't remember. Is there a simple way to plot that information based on a specific number of shares you want to buy. or even give you the number of shares that you should buy based on the amount you want to risk?
[tos.mx]
# Automatically show the Risk and Reward based on dollar amount. declare upper; input tradeAmount = 4000; input riskAmount = 250; input ratio = 2; # ---- Calculate number of shares to purchase ---- def Nshares = Floor(tradeAmount / close); AddLabel(yes, "No. of shares to buy: " + Nshares, Color.LIME); # ---- Calculate amount to risk ---- def dollarRisk = riskAmount / (Nshares); def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); plot RiskStop = if BarNumber() < lastBar then Double.NaN else GetValue(close, BarNumber() - lastBar) - GetValue(dollarRisk, BarNumber() - lastBar); plot Target1 = if BarNumber() < lastBar then Double.NaN else GetValue(close, BarNumber() - lastBar) + GetValue(dollarRisk, BarNumber() - lastBar) * ratio; plot Target2 = if BarNumber() < lastBar then Double.NaN else GetValue(close, BarNumber() - lastBar) + GetValue(dollarRisk, BarNumber() - lastBar) * (ratio + 1); RiskStop.SetDefaultColor(Color.RED); RiskStop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); RiskStop.SetLineWeight(2); Target1.SetDefaultColor(Color.GREEN); Target1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); Target1.SetLineWeight(2); Target2.SetDefaultColor(Color.GREEN); Target2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); Target2.SetLineWeight(2);
Re: Fun with ThinkScript May 28, 2015 07:14PM |
Registered: 8 years ago Posts: 6 |
Re: Fun with ThinkScript May 28, 2015 08:19PM |
Registered: 10 years ago Posts: 615 |
Quote
bijinkei
since I don't particularly know how to write a code from scratch so I tend to take parts of ones that already work and build off of that
plot UpBar = Haclose > Haclose[1]; plot DownBar = Haclose < Haclose[1];
def UpBar = HaClose > HaOpen; def DownBar = HaClose < HaOpen;
input paintbars = yes; input price = ohlc4; def HAclose = price; def HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (open[1] + close[1]) / 2); def UpBar = HAclose > HAopen; def DownBar = HAclose < HAopen; AssignPriceColor(if !paintbars then Color.CURRENT else if UpBar then Color.GREEN else Color.RED);
Re: Fun with ThinkScript May 28, 2015 08:46PM |
Registered: 9 years ago Posts: 67 |
# manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = absValue(angle) >= minAngle;Question...Would it be possible to somehow gather, but not necessarily convert, the negative values of angle in order to further filter the scan result set for either all negative values (downtrend) or all positive values (uptrend)?
Re: Fun with ThinkScript May 28, 2015 09:16PM |
Registered: 10 years ago Posts: 615 |
Quote
netarchitech
I have one follow-up question, if I may...
1. In your proffered script below, if I understand correctly, negative values of angle are converted to positive values using the absValue() function and then compared to the user-defined input minAngle:
Quote
netarchitech
Question...Would it be possible to somehow gather, but not necessarily convert, the negative values of angle in order to further filter the scan result set for either all negative values (downtrend) or all positive values (uptrend)?
In other words, run two separate scans...one for a certain value of minAngle and "upSlope", the other for a certain value of minAngle and "downSlope"...
# scan for upwardly sloping channels # manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = angle >= minAngle;
# scan for downwardly sloping channels # manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = angle < 0 and absValue(angle) >= minAngle;
Quote
netarchitech
On a side note, interestingly enough, when I ran the script today as written, with no other conditions applied, the scan result sets were significantly smaller than I thought they would be:
Out of 11,192 potential candidates...
- 55 stocks returned with minAngle = 50
- 72 stocks returned with minAngle = 40
- 89 stocks returned with minAngle = 30
- 146 stocks returned with minAngle = 20
- 391 stocks returned with minAngle = 10
- 11,192 stocks returned with minAngle = 0
Quote
netarchitech
Congratulations and all the best with the new blog. I find it to be not only a great resource and very informative, but visually appealing as well...
Re: Fun with ThinkScript May 28, 2015 11:02PM |
Registered: 8 years ago Posts: 8 |