Re: Fun with ThinkScript April 12, 2014 03:22AM |
Registered: 10 years ago Posts: 615 |
Quote
Dynamike
Thanks for all your hard work in helping us with Thinkscript, it is such a blessing
Quote
Dynamike
You may have already written this script, but is there a Thinkscript available that will alert me ONLY when the the following four conditions occur at he EXACT same time on one timeframe when the candle closes (per Darcy's super helpful setup conditions)?
- FP or HRFP
- "E" formed (5MA & 10MA both cross 20MA)
- Money flow going in the same direction of moving average line (but not above or below 70/30)
- ADX turning up and above 25
# FP/HRFP Identifier def CCr = Average(close, 2); def CCg = Average(close[3], 3); def C1 = if (CCr[0] > CCg[0] and CCr[1] < CCg[1]) then 1 else if (CCr[0] < CCg[0] and CCr[1] > CCg[1]) then -1 else 0; def RSI = RSIWilder(length = 13).RSI; def highestRSI = Highest(RSI, 21); def lowestRSI = Lowest(RSI, 21); def RSIS = (RSI - lowestRSI) / (highestRSI - lowestRSI); def Kpd = Average(RSIS, 3); def Dpd = Average(Kpd, 5); def C2 = if (Kpd[0] > Dpd[0] and Kpd[1] < Dpd[1]) then 1 else if (Kpd[0] < Dpd[0] and Kpd[1] > Dpd[1]) then -1 else 0; def MACDr = ExpAverage(close, 8) - ExpAverage(close, 21); def MACDg = ExpAverage(MACDr, 5); def C3 = if (MACDr[0] > MACDg[0] and MACDr[1] < MACDg[1]) then 1 else if (MACDr[0] < MACDg[0] and MACDr[1] > MACDg[1]) then -1 else 0; def DIr = DIPlus(5); def DIg = DIMinus(5); def C4 = if (DIr[0] > DIg[0] and DIr[1] < DIg[1]) then 1 else if (DIr[0] < DIg[0] and DIr[1] > DIg[1]) then -1 else 0; def Count = C1 + C2 + C4; def Hup = if Count == 3 and C3 == 1 then 1 else 0; def Fup = if Count == 2 and C3 == 1 then 1 else 0; def Hdn = if Count == -3 and C3 == -1 then 1 else 0; def Fdn = if Count == -2 and C3 == -1 then 1 else 0; # ================================================================ # E-Charts v2 def MA1 = Average(close, 5); def MA2 = Average(close, 10); def MA3 = Average(close, 20); # define e-signal and crossover point def Eup = MA1 > MA2 && MA2 > MA3; def Edn = MA1 < MA2 && MA2 < MA3; def CrossUp = close > MA1 && Eup && !Eup[1]; def CrossDn = close < MA1 && Edn && !Edn[1]; # Define up and down signals def higherHigh = close > Highest(Max(open, close), 3)[1]; def lowerLow = close < Lowest(Min(open, close), 3)[1]; def SignalUp = if (CrossUp && higherHigh) then 1 else if (CrossUp[1] && higherHigh && !higherHigh[1]) then 1 else if (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2]) then 1 else Double.NaN; def SignalDn = if (CrossDn && lowerLow) then 1 else if (CrossDn[1] && lowerLow && !lowerLow[1]) then 1 else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2]) then 1 else Double.NaN; # ================================================================ # Moneyflow def MoneyFlowIndex = Average(moneyflow(high, close, low, volume, 14), 3); def MFIup = MoneyFlowIndex > MoneyflowIndex[1] AND MoneyFlowIndex <= 70; def MFIdn = MoneyFlowIndex < MoneyflowIndex[1] AND MoneyFlowIndex >= 30; # ================================================================ # ADX def DX = if (DIPlus(5) + DIMinus(5) > 0) then 100 * AbsValue(DIPlus(5) - DIMinus(5)) / (DIPlus(5) + DIMinus(5)) else 0; def ADX = WildersAverage(DX, 13); def ADXsig = ADX > ADX[1] AND ADX >= 25; # ================================================================ # Define Alerts plot AlertUp = if (Hup or Fup) AND SignalUp AND MFIup AND ADXsig then 1 else 0; AlertUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); AlertUp.SetLineWeight(4); AlertUp.SetDefaultColor(Color.YELLOW); plot AlertDn = if (Hdn or Fdn) AND SignalDn AND MFIdn AND ADXsig then 1 else 0; AlertDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); AlertDn.SetLineWeight(4); AlertDn.SetDefaultColor(Color.CYAN);
Re: Fun with ThinkScript April 12, 2014 07:51AM |
Registered: 10 years ago Posts: 27 |
Re: Fun with ThinkScript April 19, 2014 03:17PM |
Registered: 10 years ago Posts: 615 |
Quote
Blessed2Invest
Is there a way to color the background say 10 days before earnings up until earnings and then a different color 10 days after earnings.
input daysBefore = 10; input daysAfter = 10; input showLines = yes; input paintBackground = yes; DefineGlobalColor("Before Earnings", Color.GREEN); DefineGlobalColor("Earnings Release Date", Color.YELLOW); DefineGlobalColor("After Earnings", Color.CYAN); DefineGlobalColor("Fill Before", CreateColor(178, 216, 166)); DefineGlobalColor("Fill After", CreateColor(131, 191, 213)); AddVerticalLine(showLines and HasEarnings()[-daysBefore], Concat(daysBefore, " Days Before" ), GlobalColor("Before Earnings" ), Curve.FIRM); AddVerticalLine(showLines and HasEarnings(), "Earnings!", GlobalColor("Earnings Release Date" ), Curve.FIRM); AddVerticalLine(showLines and HasEarnings()[daysAfter], Concat(daysAfter, " Days After" ), GlobalColor("After Earnings" ), Curve.FIRM); def before = Sum(HasEarnings(), daysBefore)[-daysBefore]; def after = Sum(HasEarnings(), daysAfter)[1]; def value1 = HighestAll(high); def value2 = if paintBackground and before then LowestAll(low) else Double.NaN; def value3 = if paintBackground and after then LowestAll(low) else Double.NaN; AddCloud(value1, value2, GlobalColor("Fill Before" )); AddCloud(value1, value3, GlobalColor("Fill After" ));
Re: Fun with ThinkScript April 19, 2014 03:59PM |
Registered: 10 years ago Posts: 615 |
Quote
Blessed2Invest
Is there a way to color the background certain days for instance a super six time which would be the last 3 calander days of a month and the first 3 calander days of the next month. ie (april 28- may 3) and so forth. for this code you could change the days you wanted colored.
input LastXDaysOfTheMonth = 3; input FirstXDaysOfTheMonth = 3; DefineGlobalColor("Fill Color", CreateColor(131, 191, 213)); def BlockOfDays = GetMonth() != GetMonth()[-LastXDaysOfTheMonth] or GetMonth() != GetMonth()[FirstXDaysOfTheMonth]; def value1 = HighestAll(high); def value2 = if BlockOfDays then LowestAll(low) else Double.NaN; AddCloud(value1, value2, GlobalColor("Fill Color" ));
Re: Fun with ThinkScript April 20, 2014 09:51AM |
Registered: 13 years ago Posts: 20 |
Re: Fun with ThinkScript April 21, 2014 06:30AM |
Registered: 10 years ago Posts: 615 |
Quote
brcurley
Hey Robert...your coding is amazing and you have been a very valuable asset to the members of this forum. It is truly appreciated.
Quote
brcurley
With that, is it possible to create an alert that scans my work space when a certain moving average crosses another moving average? Say when the 2ma crosses above or below the 50ma.
input ShortAvg = 2; input LongAvg = 50; input PlotMovingAvgLines = yes; input ShowArrows = yes; input AudibleAlert = yes; # Define averages and conditions def MA1 = Average(close, ShortAvg); def MA2 = Average(close, LongAvg); def CrossUp = MA1 > MA2 and MA1[1] <= MA2[1]; def CrossDn = MA1 < MA2 and MA1[1] >= MA2[1]; # Plot moving averages plot ShortAverage = if PlotMovingAvgLines then MA1 else Double.NaN; ShortAverage.SetDefaultColor(CreateColor(249, 140, 182)); ShortAverage.SetLineWeight(2); plot LongAverage = if PlotMovingAvgLines then MA2 else Double.NaN; LongAverage.SetDefaultColor(CreateColor(111, 183, 214)); LongAverage.SetLineWeight(2); # Show arrows at crossover point plot ArrowUp = if CrossUp and ShowArrows then MA2 * 0.995 else Double.NaN; ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP); ArrowUp.SetLineWeight(4); ArrowUp.SetDefaultColor(CreateColor(145, 210, 144)); plot ArrowDn = if CrossDn and ShowArrows then MA2 * 1.005 else Double.NaN; ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); ArrowDn.SetLineWeight(4); ArrowDn.SetDefaultColor(CreateColor(249, 140, 182)); # Sound alerts Alert(AudibleAlert and CrossUp, Concat(GetSymbolPart(), " has crossed above then slow moving average." ), Alert.BAR, Sound.Bell); Alert(AudibleAlert and CrossDn, Concat(GetSymbolPart(), " has crossed below the slow moving average." ), Alert.BAR, Sound.Bell);
def MA1 = Average(close, 2); def MA2 = Average(close, 50); def CrossUp = MA1 > MA2 and MA1[1] <= MA2[1]; def CrossDn = MA1 < MA2 and MA1[1] >= MA2[1]; plot signal = if CrossUp then 1 else if CrossDn then -1 else 0; AssignBackgroundColor(if signal == 1 then Color.UPTICK else if signal == -1 then Color.DOWNTICK else Color.CURRENT); signal.AssignValueColor(if signal == 1 then Color.UPTICK else if signal == -1 then Color.DOWNTICK else Color.CURRENT); Alert(CrossUp, Concat(GetSymbolPart(), " has crossed above then slow moving average." ), Alert.BAR, Sound.Bell); Alert(CrossDn, Concat(GetSymbolPart(), " has crossed below the slow moving average." ), Alert.BAR, Sound.Bell);
Re: Fun with ThinkScript April 21, 2014 06:03PM |
Registered: 13 years ago Posts: 20 |
Re: Fun with ThinkScript April 28, 2014 01:03PM |
Registered: 10 years ago Posts: 615 |
Quote
Robert, how do you get a lighter color background inside your bollinger bands? Thanks, GP
def sDev = StDev(data = close, length = 21); def MA21 = Average(close, 21); plot UpperBand = MA21 + 2 * sDev; plot MidLine = MA21; plot LowerBand = MA21 - 2 * sDev; UpperBand.SetDefaultColor(CreateColor(120, 163, 214)); MidLine.SetDefaultColor(CreateColor(0, 103, 204)); LowerBand.SetDefaultColor(CreateColor(120, 163, 214)); UpperBand.SetLineWeight(1); LowerBand.SetLineWeight(1); DefineGlobalColor("FillColor", CreateColor(160, 160, 160)); AddCloud(UpperBand, LowerBand, GlobalColor("FillColor" ));
Re: Fun with ThinkScript May 01, 2014 04:37PM |
Registered: 10 years ago Posts: 27 |
Re: Fun with ThinkScript May 01, 2014 06:04PM |
Registered: 10 years ago Posts: 615 |
Quote
Dynamike
Do you know how I can create a "Scan Query" so that ONLY my stocks which have your "The Edge" (Market Maker's Edge) script conditions on my 55, 34, 21, 13 charts at the same time show up in the query list:
Quote
Dynamike
If possible, could I make two separate Scan Queries:
- One for "The Edge" UP stocks
- and the other for "The Edge" DOWN stocks
# Edge Up def TrendUp = close > average(close,8); def NSup = close > close(period = "day" )[1]; def OSup = close > open(period = "day" ); def Higher = close > high(period = "day" )[1]; plot signal = TrendUp AND NSup AND OSup AND Higher;
# Edge Down def TrendDn = close < average(close,8); def NSdn = close < close(period = "day" )[1]; def OSdn = close < open(period = "day" ); def Lower = close < low(period = "day" )[1]; plot signal = TrendDn AND NSdn AND OSdn AND Lower;
Re: Fun with ThinkScript May 02, 2014 06:07AM |
Registered: 10 years ago Posts: 27 |
Re: Fun with ThinkScript May 02, 2014 09:05PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript May 04, 2014 09:09PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript May 04, 2014 11:54PM |
Registered: 10 years ago Posts: 615 |
Quote
tanman
Looks like my post and the reply got deleted! If you replied to it can you please post the reply again? Thanks!
script TheEdge { input TimeFrame = 5; def agg = TimeFrame * 60000; def Trend = close(period = agg) > expAverage(close(period = agg), 8); def NS = close > close(period = "day" )[1]; def OS = close > open(period = "day" ); def Higher = close > high(period = "day" )[1]; def Lower = close < low(period = "day" )[1]; plot bull = Trend and NS and OS and Higher; plot bear = !Trend and !NS and !OS and Lower; plot neut = !bull and !bear; } AddLabel(TheEdge(60).bull, "Edge 60", Color.GREEN); AddLabel(TheEdge(60).bear, "Edge 60", Color.PINK); AddLabel(TheEdge(60).neut, "Edge 60", Color.LIGHT_GRAY); AddLabel(TheEdge(15).bull, "Edge 15", Color.GREEN); AddLabel(TheEdge(15).bear, "Edge 15", Color.PINK); AddLabel(TheEdge(15).neut, "Edge 15", Color.LIGHT_GRAY); AddLabel(TheEdge(5).bull, "Edge 5", Color.GREEN); AddLabel(TheEdge(5).bear, "Edge 5", Color.PINK); AddLabel(TheEdge(5).neut, "Edge 5", Color.LIGHT_GRAY);
Re: Fun with ThinkScript May 05, 2014 12:51AM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript May 05, 2014 04:31AM |
Registered: 10 years ago Posts: 615 |
Quote
tanman
Robert, Thank you so much and I really appreciate the fast reply! This is very close to what I am looking for. Instead of NS and OS, I am looking for 5 min open range. So the labels would be green if stock price higher than 8 EMA, 5 min open range, and previous day high and vice versa for red and gray in between. ... My next question would be, can all 3 labels be combined into just one label? That would be amazing!
#Calculate 5 min open range def FirstMinute = if SecondsFromTime(0930) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(0930) < 300 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]; #Define yesterday's high / low def Yhigh = high(period = "day" )[1]; def Ylow = low(period = "day" )[1]; #Define combined trend def t60 = close > ExpAverage(close(period = "1 hour" ), 8); def t15 = close > ExpAverage(close(period = "15 min" ), 8); def t5 = close > ExpAverage(close(period = "5 min" ), 8); def upTrend = t60 and t15 and t5; def dnTrend = !t60 and !t15 and !t5; #Define Signals def bull = upTrend and close > max(ORHigh, Yhigh); def bear = dnTrend and close < min(ORLow, Ylow); def neut = !bull and !bear; #Add Labels addlabel(bull, " Go ", color.green); addlabel(bear, " Go ", color.pink); addlabel(neut, " No-Go ", color.light_gray); #Sound an alert Alert(bull and !bull[1], Concat(GetSymbolPart(), " has gone bullish." ), Alert.BAR, Sound.Bell); Alert(bear and !bear[1], Concat(GetSymbolPart(), " has gone bearish." ), Alert.BAR, Sound.Bell);
Quote
tanman
Another question: What is the significance of 60,000 in the def agg? Just curious
Re: Fun with ThinkScript May 05, 2014 09:21AM |
Registered: 9 years ago Posts: 1 |
Re: Fun with ThinkScript May 05, 2014 04:10PM |
Registered: 10 years ago Posts: 615 |
Quote
lusenica
Do you have a bible to learn how to create scripts for a beginner like me.
Quote
lusenica
Btw, I'm not sure if this is the right forum, but I have a question that is bothering me.
I was wondering if it is possible to create a script whereby a large watchlist ex SPY500 or larger, is scanned and creates a new smaller watchlist which finds stocks gapping up or gapped up from the previous close, they hit the top of the 100 day Linear Regression line and start to fall after the market opens... ie Fade the Gap...
Re: Fun with ThinkScript May 07, 2014 05:46PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript May 08, 2014 01:22AM |
Registered: 10 years ago Posts: 615 |
Quote
tanman
Is there any way the signal and alert is not triggered immediately as soon as price crosses the 8EMA/open range/previous day range but is triggered only when the 5 minute bar closes above or below 8EMA/open range/previous day range? The 60 min and 15 min is ok but I want only the def t5 to be set at close of 5 minute bar above or below the line. This way the alert and signal is not triggered multiple times when price starts crossing the line because of back and forth micro movement of price. Also how can I get a written alert of stock price at the moment the signal is triggered?
I made the following changes using ATR so that the trigger is delayed a little bit but couldn't figure out how to trigger signal at close of the 5 minute bar above or below the line. Also I used round(close,2) for stock price when alert is triggered:
#Calculate 5 min open range def FirstMinute = if SecondsFromTime(0930) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(0930) < 300 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]; #Define yesterday's high / low def Yhigh = high(period = "day" )[1]; def Ylow = low(period = "day" )[1]; #Define combined trend def t60 = close > ExpAverage(close(period = "1 hour" ), 8); def t15 = close > ExpAverage(close(period = "15 min" ), 8); def t5 = close > ExpAverage(close(period = "5 min" ), 8); def upTrend = t60 and t15 and t5; def dnTrend = !t60 and !t15 and !t5; #Define Signals def ATR = WildersAverage(TrueRange(high, close, low), 14); def bull = upTrend and close > (Max(ORHigh, Yhigh) + ATR / 2); def bear = dnTrend and close < (Min(ORLow, Ylow) - ATR / 2); def neut = !bull and !bear; #Add Labels AddLabel(bull, " Go ", Color.GREEN); AddLabel(bear, " Go ", Color.PINK); AddLabel(neut, " No-Go ", Color.LIGHT_GRAY); #Sound an alert Alert(bull[1] and !bull[2], GetSymbolPart() + " has gone bullish at $" + Round(close[1], 2), Alert.BAR, Sound.Bell); Alert(bear[1] and !bear[2], GetSymbolPart() + " has gone bearish at $" + Round(close[1], 2), Alert.BAR, Sound.Bell);
Re: Fun with ThinkScript May 08, 2014 01:28PM |
Registered: 10 years ago Posts: 143 |
Re: Fun with ThinkScript May 08, 2014 03:43PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript May 09, 2014 07:59PM |
Registered: 10 years ago Posts: 27 |
Re: Fun with ThinkScript May 11, 2014 05:41AM |
Registered: 10 years ago Posts: 615 |
Quote
Dynamike
If you don't mind, could you show me what the scan query code would look like for:
- "E- Chart" UP stocks
- "E-Chart" DOWN stocks
# Scan for stocks that are currently in an "E up" condition def MAs = average(close, 5); def MAm = average(close, 10); def MAl = average(close, 20); plot Eup = MAs > MAm and MAm > MAl;
# Scan for stocks that are currently in an "E down" condition def MAs = average(close, 5); def MAm = average(close, 10); def MAl = average(close, 20); plot Edn = MAs < MAm and MAm < MAl;
# Scan for stocks that have just crossed into an "E up" condition def MAs = average(close, 5); def MAm = average(close, 10); def MAl = average(close, 20); def Eup = MAs > MAm and MAm > MAl; plot signal = close > max(open[1], close[1]) and Eup and Eup[1] and !Eup[2];
# Scan for stocks that have just crossed into an "E down" condition def MAs = average(close, 5); def MAm = average(close, 10); def MAl = average(close, 20); def Edn = MAs < MAm and MAm < MAl; plot signal = close < min(open[1], close[1]) and Edn and Edn[1] and !Edn[2];
Re: Fun with ThinkScript May 11, 2014 09:10AM |
Registered: 10 years ago Posts: 27 |
Re: Fun with ThinkScript May 14, 2014 09:28AM |
Registered: 10 years ago Posts: 464 |
Re: Fun with ThinkScript May 14, 2014 10:34AM |
Registered: 10 years ago Posts: 615 |
Quote
Hi Robert,
Had a question on this. On my daily charts it is adding this to the last 3 days. Is it doing it to you also? I can't see why it would be doing this cause it's the middle of the month.
Re: Fun with ThinkScript May 14, 2014 01:23PM |
Registered: 10 years ago Posts: 464 |
Re: Fun with ThinkScript May 14, 2014 01:37PM |
Registered: 10 years ago Posts: 615 |
Quote
I tried it with your updated formula. It still did not work. Not sure why it would draw in the middle of the month.
Re: Fun with ThinkScript May 16, 2014 06:33AM |
Registered: 9 years ago Posts: 78 |