Re: Fun with ThinkScript June 20, 2014 11:56AM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript June 20, 2014 06:40PM |
Registered: 10 years ago Posts: 15 |
Re: Fun with ThinkScript June 20, 2014 08:02PM |
Registered: 11 years ago Posts: 615 |
Quote
mark1234
Hi Robert, been following this thread and want to say I appreciate your generosity.
Quote
mark1234
I wonder if I could to call upon your expertise.
I am having some difficulty creating a thinkscript of a simple moving average that will show exclusively on my daily charts.
For example when I click on my daily chart the SMA will automatically display the 30, 50, and 100 day moving average lines, when I go back to say a 5 minute chart those moving average lines are no longer displayed.
declare hide_on_intraday;
Re: Fun with ThinkScript June 20, 2014 08:33PM |
Registered: 10 years ago Posts: 15 |
Re: Fun with ThinkScript June 21, 2014 11:04PM |
Registered: 10 years ago Posts: 17 |
Re: Fun with ThinkScript June 22, 2014 04:48PM |
Registered: 11 years ago Posts: 615 |
Quote
Gaterz
Ok, I've thought about this some more...I'm trading futures which are traded in contracts. I'm thinking if the average # of contracts is X or higher, the bar is painted one color. If the average # of contracts is Y or lower, the bar is painted another color. Everything else in between is painted a neutral color.
Re: Fun with ThinkScript June 24, 2014 12:00PM |
Registered: 10 years ago Posts: 78 |
Re: Fun with ThinkScript June 24, 2014 06:28PM |
Registered: 11 years ago Posts: 615 |
Quote
linter
hey, robert: here's a nice little inside-day, narrow-range-4 script that i've taken from an old post on the Lawyer Trader blog and wondered if you might be able to do a few things to it for me:
i'm soley interested in those times when the yellow dot (NR4) and the violet dot (low volatility) line up right together. Is there a way to:
1/ put a big fat arrow on the screen whenever this happens, above the bar in question?
1b/ make it sound an alarm?
2/ write a scan for the condition?
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5; def insideDay = high < high[1] and low > low[1]; def range = high - low; def NR4 = range < Lowest(range[1], 3); plot signal = lowVol and insideDay and NR4; signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); signal.SetDefaultColor(Color.MAGENTA); signal.SetLineWeight(5); Alert(signal, getsymbol() + " inside & narrow range day.", alert.bar, sound.ring);
Re: Fun with ThinkScript June 25, 2014 08:58AM |
Registered: 10 years ago Posts: 78 |
Re: Fun with ThinkScript June 25, 2014 11:01AM |
Registered: 10 years ago Posts: 2 |
Re: Fun with ThinkScript June 25, 2014 09:13PM |
Registered: 10 years ago Posts: 17 |
Re: Fun with ThinkScript June 25, 2014 09:49PM |
Registered: 10 years ago Posts: 9 |
Re: Fun with ThinkScript June 26, 2014 07:50AM |
Registered: 11 years ago Posts: 615 |
Quote
eurekaaa
I was wondering if someone could help me as my question is more complex and I'd like to have some sort of text output for my watchlist.
It's a two part watchlist - maybe they need to be seperate or I would prefer if they could be combined into one.
A. For a close inside of the Bollinger Bands, calculate the number of days of consecutive closes inside the bands and display it like "In: n" where n is the number of days. Only display this when n > 15, say else display blank.
B. For a close outside of the Bollinger Bands, I'm looking to calculate the number of consecutive days outside of the bands only if the close was immediately inside of the bollinger bands (see A above) for a minimum mumber of days, say 19 and display it lilke "Ex: m" where m is the number of days outside of the bollinger bands. For eg. the stock is inside of the bollinger bands for 22 days and then it's outside for 4 days - "Ex: 4". else display blank.
Re: Fun with ThinkScript June 26, 2014 08:10AM |
Registered: 11 years ago Posts: 615 |
Quote
Gaterz
Can I get a script for the previous week's High and low? Plotted on "today's" chart
input ShowTodayOnly = yes; def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay(); plot HighLW = if !today then Double.NaN else high(period = "week" )[1]; HighLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); plot LowLW = if !today then Double.NaN else low(period = "week" )[1]; LowLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Re: Fun with ThinkScript June 26, 2014 08:17AM |
Registered: 11 years ago Posts: 615 |
Quote
wiineedmore
I just started to use the RSI EMA and wondered if a alarm could be made that would change the background color and a bell ring when EMA touches the OverSold and OverBought lines. Then when the level goes back within the range the background goes back to normal?
declare lower; input length = 14; input over_bought = 70; input over_sold = 30; input price = close; def NetChgAvg = ExpAverage(price - price[1], length); def TotChgAvg = ExpAverage(AbsValue(price - price[1]), length); def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0; plot RSI_EMA = 50 * (ChgRatio + 1); plot OverSold = over_sold; plot OverBought = over_bought; RSI_EMA.SetDefaultColor(GetColor(8)); OverBought.SetDefaultColor(GetColor(5)); OverSold.SetDefaultColor(GetColor(5)); AssignBackgroundColor(if RSI_EMA >= OverBought then Color.PINK else if RSI_EMA <= OverSold then Color.LIGHT_GREEN else Color.CURRENT); def soundAlert = (RSI_EMA crosses above OverBought) or (RSI_EMA crosses below OverSold); Alert(soundAlert, "", Alert.BAR, Sound.Ring);
Re: Fun with ThinkScript June 26, 2014 03:32PM |
Registered: 10 years ago Posts: 17 |
Re: Fun with ThinkScript June 26, 2014 03:53PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript June 26, 2014 11:48PM |
Registered: 10 years ago Posts: 9 |
Re: Fun with ThinkScript June 27, 2014 07:08AM |
Registered: 11 years ago Posts: 615 |
Quote
eurekaaa
I was wondering if someone could help me as my question is more complex and I'd like to have some sort of text output for my watchlist.
It's a two part watchlist - maybe they need to be seperate or I would prefer if they could be combined into one.
A. For a close inside of the Bollinger Bands, calculate the number of days of consecutive closes inside the bands and display it like "In: n" where n is the number of days. Only display this when n > 15, say else display blank.
B. For a close outside of the Bollinger Bands, I'm looking to calculate the number of consecutive days outside of the bands only if the close was immediately inside of the bollinger bands (see A above) for a minimum mumber of days, say 19 and display it lilke "Ex: m" where m is the number of days outside of the bollinger bands. For eg. the stock is inside of the bollinger bands for 22 days and then it's outside for 4 days - "Ex: 4". else display blank.
input length = 21; def sDev = StDev(data = close, length = length); def Avg = Average(close, length); def UpperBand = Avg + 2 * sDev; def LowerBand = Avg - 2 * sDev; def inband = if close < UpperBand and close > LowerBand then inband[1] + 1 else 0; def outband = if close > UpperBand or close < LowerBand then outband[1] + 1 else 0; AddLabel(inband, "In BB: " + inband, Color.YELLOW); AddLabel(outband, "Out BB: " + outband, Color.WHITE);
input length = 21; input MinDaysInband = 15; def sDev = StDev(data = close, length = length); def Avg = Average(close, length); def UpperBand = Avg + 2 * sDev; def LowerBand = Avg - 2 * sDev; def inband = if close < UpperBand and close > LowerBand then inband[1] + 1 else 0; def outband = if inband[1] >= MinDaysInband and close > UpperBand or close < LowerBand then outband[1] + 1 else 0; AddLabel(inband >= MinDaysInband, "In BB: " + inband, Color.BLACK); AddLabel(outband, "Out BB: " + outband, Color.WHITE); AddLabel(inband < MinDaysInband and !outband, " ", Color.CURRENT); AssignBackgroundColor(if inband >= MinDaysInband then Color.DARK_ORANGE else if outband then Color.PLUM else Color.CURRENT);
Re: Fun with ThinkScript June 27, 2014 11:10AM |
Registered: 10 years ago Posts: 78 |
Re: Fun with ThinkScript June 27, 2014 11:24AM |
Registered: 11 years ago Posts: 615 |
Quote
linter
my concern here is that the updating of the column lags behind too much for the numbers to be useful. hmmm. i don't know. what do you think?
input sym = "$DJI"; def Net = Round(close(sym) - close(sym, period = "day" )[1], 1); AddLabel(Net >= 20, "DJI: " + Net, Color.GREEN); AddLabel(Net <= -20, "DJI: " + Net, Color.PINK); AddLabel(Net between -19.9 and 19.9, "DJI: " + Net, Color.LIGHT_GRAY);
Re: Fun with ThinkScript June 27, 2014 11:48AM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript June 27, 2014 12:00PM |
Registered: 11 years ago Posts: 615 |
plot NetChg = close - close[1];
Re: Fun with ThinkScript June 27, 2014 12:04PM |
Registered: 11 years ago Posts: 615 |
Re: Fun with ThinkScript June 27, 2014 12:12PM |
Registered: 11 years ago Posts: 615 |
Quote
I also have a question..... If I draw trend lines using the tools available through TOS, can you create a formula that would give me an alert, notifying me when a candle closes above or below that line?
Re: Fun with ThinkScript June 27, 2014 12:53PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript June 27, 2014 01:44PM |
Registered: 10 years ago Posts: 1 |
Re: Fun with ThinkScript June 27, 2014 03:13PM |
Registered: 10 years ago Posts: 78 |
Re: Fun with ThinkScript June 27, 2014 03:58PM |
Registered: 11 years ago Posts: 615 |
Quote
linter
seems to me, though, that you once wrote a bit of code that plotted the opening range and also plotted lines just beneath the OR high and just above the low. can't remember if alerts were part of the study. i'll have to go back through this thread and see if anything rings a bell. does this sound familiar?
# 5 min opening range # Robert Payne def OpenRangeMinutes = 5; def MarketOpenTime = 0930; input ShowTodayOnly = yes; def Today = if GetDay() == GetLastDay() then 1 else 0; def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0; def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1]; def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1]; plot OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN; plot OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN; OpenRangeHigh.SetStyle(Curve.SHORT_DASH); OpenRangeHigh.SetDefaultColor(Color.YELLOW); OpenRangeHigh.SetLineWeight(1); OpenRangeLow.SetStyle(Curve.SHORT_DASH); OpenRangeLow.SetDefaultColor(Color.YELLOW); OpenRangeLow.SetLineWeight(1); # Plot 5 min entry line def first30 = if SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) > 0 then 1 else 0; def dailyRange = high(period="day" )[1] - low(period="day" )[1]; def range = average(dailyrange,10); plot entryLine1 = if first30 then openrangehigh + (range * 0.03) else double.nan; entryline1.setdefaultcolor(color.green); entryline1.setpaintingStrategy(paintingStrategy.HORIZONTAL); plot entryLine2 = if first30 then openrangelow - (range * 0.03) else double.nan; entryline2.setdefaultcolor(color.green); entryline2.setpaintingStrategy(paintingStrategy.HORIZONTAL); def SoundAlert = high crosses above entryLine1 or low crosses below entryLine2; Alert(SoundAlert, "Something exciting just happened with " + GetSymbol(), Alert.BAR, Sound.Ring);
# 30 min opening range # Robert Payne def OpenRangeMinutes = 30; def MarketOpenTime = 0930; input ShowTodayOnly = yes; def Today = if GetDay() == GetLastDay() then 1 else 0; def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0; def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1]; def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1]; plot OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN; plot OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN; OpenRangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); OpenRangeHigh.SetDefaultColor(Color.YELLOW); OpenRangeHigh.SetLineWeight(2); OpenRangeLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); OpenRangeLow.SetDefaultColor(Color.YELLOW); OpenRangeLow.SetLineWeight(2); DefineGlobalColor("cloud", CreateColor(161, 182, 158)); AddCloud(OpenRangeHigh, OpenRangeLow, GlobalColor("cloud" )); def dailyRange = high(period = "day" )[1] - low(period = "day" )[1]; def range = Average(dailyRange, 10); plot entryLine1 = OpenRangeHigh + (range * 0.06); entryLine1.SetDefaultColor(Color.GREEN); plot entryLine2 = OpenRangeLow - (range * 0.06); entryLine2.SetDefaultColor(Color.GREEN); def SoundAlert = high crosses above entryLine1 or low crosses below entryLine2; Alert(SoundAlert, "Something exciting just happened with " + GetSymbol(), Alert.BAR, Sound.Ring);
Re: Fun with ThinkScript June 27, 2014 04:09PM |
Registered: 10 years ago Posts: 2 |