Re: Fun with ThinkScript August 21, 2014 10:37PM |
Registered: 9 years ago Posts: 8 |
Re: Fun with ThinkScript August 22, 2014 12:38AM |
Registered: 10 years ago Posts: 615 |
Quote
exgamer
I've been messing around with the code you rewrote for Wes on page 11 the # 30 min opening range with fib retracements but the only thing I can't figure out is how to prevent it from showing up in pre-market. It's only annoying because the drawing pre-market is from the previous day, not the current day.
plot h30 = if !today then Double.NaN else OR30high;
plot h30 = if !today or secondstilltime(0930) > 0 then Double.NaN else OR30high;
Re: Fun with ThinkScript August 22, 2014 07:56AM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript August 22, 2014 11:55AM |
Registered: 9 years ago Posts: 8 |
Re: Fun with ThinkScript September 04, 2014 09:26AM |
Registered: 13 years ago Posts: 216 |
Re: Fun with ThinkScript September 04, 2014 05:55PM |
Registered: 10 years ago Posts: 615 |
Quote
funkho
Robert,
I want to express my thanks again for the work that you've done with TOS. I love what you've put together!
DefineGlobalColor("time", CreateColor(148, 214, 232)); def nMinutes = GetAggregationPeriod() / 60000; def Weekly = if nMinutes == 10080 then 1 else Double.NaN; def Daily = if nMinutes == 1440 then 1 else Double.NaN; def Intraday = if nMinutes < 1440 then 1 else Double.NaN; AddLabel(Weekly, "Weekly", GlobalColor("time" )); AddLabel(Daily, "Daily", GlobalColor("time" )); AddLabel(Intraday, nMinutes + " min", GlobalColor("time" ));
Re: Fun with ThinkScript September 05, 2014 04:01PM |
Registered: 10 years ago Posts: 615 |
# E-Charts v3 declare upper; input short_average = 5; input medium_average = 10; input long_average = 20; input average_type = {default "SMA", "EMA"}; input showArrows = yes; def MA1; def MA2; def MA3; switch (average_type) { case "SMA": MA1 = Average(close, short_average); MA2 = Average(close, medium_average); MA3 = Average(close, long_average); case "EMA": MA1 = ExpAverage(close, short_average); MA2 = ExpAverage(close, medium_average); MA3 = ExpAverage(close, long_average); } # 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; # Plot the moving average lines plot ln1 = MA1; ln1.SetDefaultColor(CreateColor(145, 210, 144)); ln1.SetLineWeight(2); plot ln2 = MA2; ln2.SetDefaultColor(CreateColor(111, 183, 214)); ln2.SetLineWeight(2); plot ln3 = MA3; ln3.SetDefaultColor(CreateColor(249, 140, 182)); ln3.SetLineWeight(2); # Show an arrow plot ArrowUp = if SignalUp and showArrows then low * 0.997 else Double.NaN; ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); ArrowUp.SetLineWeight(4); ArrowUp.SetDefaultColor(Color.YELLOW); plot ArrowDn = if SignalDn and showArrows then high * 1.003 else Double.NaN; ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); ArrowDn.SetLineWeight(4); ArrowDn.SetDefaultColor(Color.CYAN); # Add label for Eup or Edn AddLabel(Eup, "E Up", CreateColor(134, 202, 93)); AddLabel(Edn, "E Dn", CreateColor(232, 148, 157)); # Calculate Meter Values def sl1 = ma1 > ma1[1]; def sl2 = ma2 > ma2[1]; def sl3 = ma3 > ma3[1]; def p1 = close > ma1; def p2 = close > ma2; def p3 = close > ma3; def u1 = 2 * (close > open); def u2 = 2 * (close > high[1]); def d1 = 2 * (close < open); def d2 = 2 * (close < low[1]); def UPstr = sl1 + sl2 + sl3 + p1 + p2 + p3 + u1 + u2; def DNstr = !sl1 + !sl2 + !sl3 + !p1 +!p2 + !p3 + d1 + d2; # Add Strength Meter AddLabel(Eup or Edn, " ", if Eup and UPstr >= 3 then CreateColor(128, 199, 94) else if Edn and DNstr >= 3 then CreateColor(232, 143, 153) else CreateColor(177,177,166)); AddLabel(Eup or Edn, " ", if Eup and UPstr >= 6 then CreateColor(99, 197, 72) else if Edn and DNstr >= 6 then CreateColor(238, 123, 136) else CreateColor(177,177,166)); AddLabel(Eup or Edn, " ", if Eup and UPstr >= 8 then CreateColor(65, 195, 50) else if Edn and DNstr >= 8 then CreateColor(245, 101, 117) else CreateColor(177,177,166)); AddLabel(Eup or Edn, " ", if Eup and UPstr == 10 then CreateColor(41, 192, 36) else if Edn and DNstr == 10 then CreateColor(249, 81, 101) else CreateColor(177,177,166));
Re: Fun with ThinkScript September 06, 2014 12:04PM |
Registered: 9 years ago Posts: 60 |
Re: Fun with ThinkScript September 07, 2014 02:32AM |
Registered: 10 years ago Posts: 615 |
Quote
Sara
Can't be in a watch list signal ?
# Complex UP Signal def Value = MACD(2, 5, 2, "EMA" ).Value; def Avg = MACD(2, 5, 2, "EMA" ).Avg; def MACDup = Value > Avg; def SlowD = StochasticFull(80, 30, 2, 2, hlc3, hlc3, hlc3, 3, "EMA" ).FullD; def SlowDup = SlowD crosses above 30; def CCI = CCI(7); def CCIup = CCI crosses above -100; def MFIup = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses above 20; def emaInc = ExpAverage(Max(close - close[5], 0), 5); def emaDec = ExpAverage(Max(close[5] - close, 0), 5); def RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec); def RMIob = RMI >= 75; def RMIos = RMI <= 25; plot signalUP = MACDup and SlowDup and CCIup and MFIup and RMIos; signalUP.assignValueColor(if signalUP then color.green else color.light_gray); assignBackgroundColor(if signalup then color.green else color.light_gray);
# Complex Down Signal def Value = MACD(2, 5, 2, "EMA" ).Value; def Avg = MACD(2, 5, 2, "EMA" ).Avg; def MACDdn = Value <= Avg; def SlowD = StochasticFull(80, 30, 2, 2, hlc3, hlc3, hlc3, 3, "EMA" ).FullD; def SlowDdn = SlowD crosses below 80; def CCI = CCI(7); def CCIdn = CCI crosses below 100; def MFIdn = MoneyFlowIndex(length = 1).MoneyFlowIndex crosses below 80; def emaInc = ExpAverage(Max(close - close[5], 0), 5); def emaDec = ExpAverage(Max(close[5] - close, 0), 5); def RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec); def RMIob = RMI >= 75; plot signalDN = MACDdn and SlowDdn and CCIdn and MFIdn and RMIob; signalDN.assignValueColor(if signalDN then color.red else color.light_gray); AssignBackgroundColor(if signalDN then color.red else color.light_gray);
Re: Fun with ThinkScript September 07, 2014 07:43AM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 07, 2014 09:09AM |
Registered: 10 years ago Posts: 615 |
Quote
meyer99
Trigger for a long trade is when price (close) crosses above the Kijun
and the previous two closes are below the Kijun and the Chikou is above
the Kumo (cloud).
close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26];
close > Kijunthat translates to, "today's close is above today's Kijun" which makes sense
close[1] < Kijun[1] and close[2] < Kijun[2]that translates to, "yesterday's close was below yesterday's Kijun AND the day before yesterday's close was below the day before yesterday's Kijun" and that makes sense.
Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26]* Ok...this one doesn't make sense to me because it translates to, "the Chikou from 26 days ago is above the SpanA from 26 days ago AND the Chikou from 26 days ago is above the SpanB from 26 days ago.
Chikou > SpanA and Chikou > SpanB
Re: Fun with ThinkScript September 07, 2014 12:32PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 07, 2014 12:34PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 07, 2014 12:50PM |
Registered: 10 years ago Posts: 615 |
Quote
meyer99
I mean 26 days ago is what I want.
# Ichimoku UP Alert def Tenkan = (Highest(high, 9) + Lowest(low, 9)) / 2; def Kijun = (Highest(high, 26) + Lowest(low, 26)) / 2; def SpanA = (Tenkan[26] + Kijun[26]) / 2; def SpanB = (Highest(high[26], 2 * 26) + Lowest(low[26], 2 * 26)) / 2; def Chikou = close[-26]; plot SignalUP = close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26]; SignalUP.assignValueColor(if SignalUP then color.green else color.gray); AssignBackgroundColor(if SignalUP then color.green else color.gray); Alert(SignalUP, "Ichimoku alert for " + getsymbol(), Alert.bar, Sound.ding);
# Ichimoku DOWN Alert def Tenkan = (Highest(high, 9) + Lowest(low, 9)) / 2; def Kijun = (Highest(high, 26) + Lowest(low, 26)) / 2; def SpanA = (Tenkan[26] + Kijun[26]) / 2; def SpanB = (Highest(high[26], 2 * 26) + Lowest(low[26], 2 * 26)) / 2; def Chikou = close[-26]; plot SignalDN = close < Kijun and close[1] > Kijun[1] and close[2] > Kijun[2] and Chikou[26] < SpanA[26] and Chikou[26] < SpanB[26]; SignalDN.assignValueColor(if SignalDN then color.red else color.gray); AssignBackgroundColor(if signalDN then color.red else color.gray); Alert(SignalDN, "Ichimoku alert for " + getsymbol(), Alert.bar, Sound.ding);
Re: Fun with ThinkScript September 07, 2014 01:09PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 07, 2014 01:14PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript September 07, 2014 04:17PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 07, 2014 04:43PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript September 07, 2014 05:46PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 07, 2014 06:05PM |
Registered: 10 years ago Posts: 615 |
Quote
meyer99
Robert,
I am sorry I did not ask the right question. How come sometimes I get a solid color and sometimes I get a number (0.0 and/or 1)?
def Chikou = close[-26]; plot SignalUP = close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and Chikou[26] > SpanA[26] and Chikou[26] > SpanB[26];
plot SignalUP = close > Kijun and close[1] < Kijun[1] and close[2] < Kijun[2] and close > SpanA[26] and close > SpanB[26];
Re: Fun with ThinkScript September 07, 2014 06:25PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 08, 2014 10:23AM |
Registered: 9 years ago Posts: 34 |
# RHouser created 3X Oscillator code # RHouser modified to include alerts: bubbles and audio # RHouser updated 5/18/12 due to FullD not being calculated # correctly by TOS # Stochastic calculated using Lane's formulas # Updated 5/23/12 - ability to turn on/off alert bubbles # Place # before or delete last line of code should OB/OS # colored candles not to show on chart - code provided by # by Achilles Dent 5/21/12 declare lower; input K_period = 10; input D_period = 10; input SlowTrendLength = 3; input smoothing_type = { default EMA, SMA }; input stochastic_type = { FAST, default SLOW }; input over_bought = 85; input over_sold = 25; input show_bubbles = yes; input show_sec_bbls = no; input show_alerts = no; def aggPer = getAggregationPeriod(); def adjAggPer = if aggPer == AggregationPeriod.MIN then AggregationPeriod.THREE_MIN else if aggPer == AggregationPeriod.TWO_MIN then AggregationPeriod.FIVE_MIN else if aggPer == AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN else if aggPer == AggregationPeriod.FOUR_MIN then AggregationPeriod.TEN_MIN else if aggPer == AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN else if aggPer == AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN else if aggPer == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR else if aggPer == AggregationPeriod.TWENTY_MIN then AggregationPeriod.HOUR else if aggPer == AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS else if aggPer == AggregationPeriod.HOUR then AggregationPeriod.FOUR_HOURS else if aggPer == AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY else if aggPer == AggregationPeriod.FOUR_HOURS then AggregationPeriod.DAY else if aggPer == AggregationPeriod.DAY then AggregationPeriod.THREE_DAYS else if aggPer == AggregationPeriod.TWO_DAYS then AggregationPeriod.WEEK else if aggPer == AggregationPeriod.THREE_DAYS then AggregationPeriod.WEEK else if aggPer == AggregationPeriod.FOUR_DAYS then AggregationPeriod.MONTH else if aggPer == AggregationPeriod.WEEK then AggregationPeriod.MONTH else if aggPer == AggregationPeriod.MONTH then AggregationPeriod.MONTH else Double.NaN; def _kPeriod; def _dPeriod; def _slowTrendLength; if aggPer == AggregationPeriod.MONTH then { _kPeriod = K_period * 3; _dPeriod = D_period * 3; _slowTrendLength = SlowTrendLength * 3; } else { _kPeriod = K_period; _dPeriod = D_period; _slowTrendLength = SlowTrendLength; } def priceH = high( period = adjAggPer ); def priceL = low( period = adjAggPer ); def priceC = close( period = adjAggPer ); def lowest_low = lowest( low, _kPeriod ); def highest_high = highest( high, _kPeriod ); def fastK = if ( highest_high - lowest_low ) <= 0 then 0 else 100 * ( close - lowest_low ) / ( highest_high - lowest_low ); def fastD = if smoothing_type == smoothing_type.EMA then ExpAverage( fastK, _dPeriod ) else Average( fastK, _dPeriod ); def slowK = fastD; def slowD = if smoothing_type == smoothing_type.EMA then ExpAverage( slowK, _dPeriod ) else Average( slowK, _dPeriod ); #---Stochastic plot stochD = if stochastic_type == stochastic_type.FAST then fastD else slowD; stochD.SetPaintingStrategy( PaintingStrategy.POINTS ); stochD.AssignValueColor( if stochD >= stochD[1] then Color.CYAN else if stochD < stochD[1] then Color.BLUE else Color.GRAY ); #---Reference lines plot OverBought = over_bought; OverBought.SetDefaultColor( Color.BLACK ); def Hundred = 100; AddCloud( OverBought, Hundred, Color.RED, Color.RED ); plot OverSold = over_sold; OverSold.SetDefaultColor( Color.BLACK ); def Zero = 0; AddCloud( OverSold, Zero, Color.YELLOW, Color.YELLOW ); #---Calculate primary buy/sell def primaryBuy = stochD >= OverSold and stochD[1] < OverSold; def primarySell = stochD <= OverBought and stochD[1] > OverBought; #---Calculate secondary buy/sell def fastTrendUp = stochD < stochD[-1]; def slowTrendUp = stochD > stochD[_slowTrendLength]; def valley = fastTrendUp and !fastTrendUp[1] and stochD > OverSold; def peak = !fastTrendUp and fastTrendUp[1] and stochD < OverBought; def secondaryBuy = valley and stochD < OverBought; def secondarySell = peak and stochD > OverSold; plot buy = if primaryBuy or secondaryBuy then stochD else Double.NaN; buy.DefineColor( "pBuy", Color.UPTICK ); buy.DefineColor( "sBuy", CreateColor( 0, 255, 0 ) ); buy.AssignValueColor( if primaryBuy then buy.color( "pBuy" ) else buy.color( "sBuy" ) ); buy.SetPaintingStrategy( PaintingStrategy.ARROW_UP ); buy.setHiding( show_bubbles ); plot sell = if primarySell or secondarySell then stochD else Double.NaN; sell.DefineColor( "pSell", Color.DOWNTICK ); sell.DefineColor( "sSell", Color.MAGENTA ); sell.AssignValueColor( if primarySell then sell.color( "pSell" ) else sell.color( "sSell" ) ); sell.SetPaintingStrategy( PaintingStrategy.ARROW_DOWN ); sell.setHiding( show_bubbles ); AddChartBubble( show_bubbles and primaryBuy, stochD, "pBUY", Color.UPTICK, no ); AddChartBubble( show_bubbles and show_sec_bbls and secondaryBuy, stochD, "sBUY", CreateColor( 0, 255, 0 ), no ); AddChartBubble( show_bubbles and primarySell, stochD, "pSELL", Color.DOWNTICK, yes ); AddChartBubble( show_bubbles and show_sec_bbls and secondarySell, stochD, "sSELL", Color.MAGENTA, yes ); alert( show_alerts and buy, if primaryBuy then concat( "Primary BUY @ ", close ) else concat( "Secondary BUY @ ", close ), Alert.BAR, Sound.Ring ); alert( show_alerts and sell, if primarySell then concat( "Primary SELL @ ", close ) else concat( "secondary SELL @ ", close ), Alert.BAR, Sound.Chimes ); AssignPriceColor(if slowk>80 then Color.cyan else if slowk<20 then color.pink else color.current);
Re: Fun with ThinkScript September 08, 2014 06:37PM |
Registered: 10 years ago Posts: 615 |
Quote
strategynode
I found this code on thinkscript (free) its called the 3X Oscillator code. I wanted to see if there is any way to add an option of using RSI Wilder (I choose the length, the overbought oversold, and if I want to use it in the calculation). Also the alert won't trigger in the original code.
alert( show_alerts and (primaryBuy or secondaryBuy), if primaryBuy then concat( "Primary BUY @ ", close ) else concat( "Secondary BUY @ ", close ), Alert.BAR, Sound.Ring ); alert( show_alerts and (primarySell or secondarySell), if primarySell then concat( "Primary SELL @ ", close ) else concat( "secondary SELL @ ", close ), Alert.BAR, Sound.Chimes );
Re: Fun with ThinkScript September 09, 2014 04:19PM |
Registered: 9 years ago Posts: 16 |
Re: Fun with ThinkScript September 09, 2014 04:27PM |
Registered: 9 years ago Posts: 34 |
Re: Fun with ThinkScript September 09, 2014 04:33PM |
Registered: 9 years ago Posts: 34 |
Re: Fun with ThinkScript September 09, 2014 04:37PM |
Registered: 10 years ago Posts: 615 |
Quote
meyer99
Robert,
The alert works great on the watch list. But what do you think about this:
Re: Fun with ThinkScript September 09, 2014 04:42PM |
Registered: 10 years ago Posts: 615 |
Quote
strategynode
Perfect I am going to add this today and test it tomorrow.
Thanks you,
StrategyNode
Quote
strategynode
Hi Robert,
I have another idea or question which I am not sure if it is possible to code or not.
In one of your previous posts you created a small code where the low of the bar moved with each bar.
Based on that Idea is there a way to have two lines one on top and one at the bottom but they will move together connecting the high (the top line) and low (the bottom line) for x number of previous bars. But they need to be straight (Like how you would draw a trendline by hand on a chart)
Thanks,
StrategyNode
Re: Fun with ThinkScript September 09, 2014 05:34PM |
Registered: 9 years ago Posts: 34 |
Re: Fun with ThinkScript September 10, 2014 06:30AM |
Registered: 10 years ago Posts: 464 |