Fun with ThinkScript December 17, 2013 04:53PM |
Registered: 11 years ago Posts: 615 |
# DI, ADX, and Trend Indicator (updated 12/18/13) declare lower; input DI_length = 5; input ADX_length = 13; input Strong_Trend = 25; def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0; plot ADX = WildersAverage(DX, adx_length);ADX.DefineColor("Stronger", Color.CYAN); ADX.DefineColor("Weaker", Color.PINK); ADX.AssignValueColor(if ADX > ADX[1] then ADX.Color("Stronger" ) else ADX.Color("Weaker" )); ADX.SetPaintingStrategy(PaintingStrategy.LINE); ADX.SetStyle(Curve.SHORT_DASH); AddCloud(ADX, 0, ADX.Color("stronger" )); def weaker = if ADX < ADX[1] then ADX else Double.NaN; AddCloud(weaker, 0, ADX.Color("weaker" )); plot "DI+" = DIPlus(DI_length); "DI+".SetDefaultColor(Color.RED); "DI+".SetLineWeight(2); plot "DI-" = DIMinus(DI_length); "DI-".SetDefaultColor(Color.GREEN); "DI-".SetLineWeight(2); plot StrongTrend = Strong_Trend; StrongTrend.SetDefaultColor(Color.LIGHT_GRAY);
Re: Fun with ThinkScript December 17, 2013 05:05PM |
Registered: 11 years ago Posts: 615 |
# Previous High, Low, Close declare upper; def Today = if GetLastDay() == GetDay() then 1 else 0; def DrawHighs = if (close < high(period="day" )[1] AND close > low(period="day" )[1]) OR high(period="day" ) > high(period="day" )[1] then 1 else 0; def DrawLows = if (close < high(period="day" )[1] AND close > low(period="day" )[1]) OR low(period="day" ) < low(period="day" )[1] then 1 else 0; plot OpenPivot = if Today then open(period = "day" )[0] else Double.NaN; OpenPivot.SetDefaultColor(Color.GRAY); OpenPivot.SetLineWeight(1); plot yClose = if Today then close(period = "day" )[1] else Double.NaN; yClose.SetDefaultColor(Color.LIGHT_GRAY); yClose.SetLineWeight(1); yClose.SetStyle(Curve.MEDIUM_DASH); plot yhi = if Today then high(period = "day" )[1] else Double.NaN; yhi.SetDefaultColor(Color.CYAN); yhi.SetLineWeight(2); plot sweethi = if Today then (if yhi * 1.01 > yhi + 0.75 then yhi + 0.75 else yhi * 1.01) else Double.NaN; sweethi.SetDefaultColor(Color.CYAN); sweethi.SetStyle(Curve.SHORT_DASH); plot ylo = if Today then low(period = "day" )[1] else Double.NaN; ylo.SetDefaultColor(Color.PINK); ylo.SetLineWeight(2); plot sweetlo = if Today then (if ylo * 0.99 < ylo - 0.75 then ylo - 0.75 else ylo * 0.99) else Double.NaN; sweetlo.SetDefaultColor(Color.PINK); sweetlo.SetStyle(Curve.SHORT_DASH);
Re: Fun with ThinkScript December 17, 2013 05:14PM |
Registered: 11 years ago Posts: 615 |
# E-Charts v2 declare upper; input short_average = 5; input medium_average = 10; input long_average = 20; input average_type = {default "SMA", "EMA"}; input show_vertical_line = no; input show_bubble_labels = 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); # Draw vertical line to indicate call and put signals AddVerticalLine(SignalUp && show_vertical_line, "Up", Color.UPTICK); AddVerticalLine(SignalDn && show_vertical_line, "Down", Color.LIGHT_RED); # Show Call / Put Signal in a Chart Bubble AddChartBubble(SignalUp && show_bubble_labels, low - 0.3, "Up", Color.UPTICK, no); AddChartBubble(SignalDn && show_bubble_labels, high + 0.3, "Dn", Color.LIGHT_RED); # Add label for Eup or Edn AddLabel(Eup, "E Up", Color.GREEN); AddLabel(Edn, "E Dn", Color.RED);
Re: Fun with ThinkScript December 17, 2013 05:21PM |
Registered: 11 years ago Posts: 615 |
# FP/HRFP Identifier # Robert Payne 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,13); 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 + C3 + C4; def Hup = if Count == 4 then 1 else 0; def Fup = if Count == 3 then 1 else 0; def Hdn = if Count == -4 then 1 else 0; def Fdn = if Count == -3 then 1 else 0; AddVerticalLine(Fup,"FP",color.light_green); AddVerticalLine(Hup,"HRFP",color.green); AddVerticalLine(Fdn,"FP",color.pink); AddVerticalLine(Hdn,"HRFP",color.red);
Re: Fun with ThinkScript December 17, 2013 09:23PM |
Registered: 11 years ago Posts: 108 |
Re: Fun with ThinkScript December 18, 2013 09:24AM |
Registered: 12 years ago Posts: 173 |
Re: Fun with ThinkScript December 18, 2013 11:59AM |
Registered: 11 years ago Posts: 615 |
#The Edge #Robert Payne #Plot 8 period moving average plot MA8 = Average(close, 8); MA8.SetDefaultColor(Color.YELLOW); MA8.SetLineWeight(2); #Trend Signal def TrendUp = if close > MA8 then 1 else Double.NaN; def TrendDn = if close < MA8 then 1 else Double.NaN; AddLabel(TrendUp, "UP", Color.GREEN); AddLabel(TrendDn, "DN", Color.RED); #Net Signal def NSup = if close - close(period = "day" )[1] > 0 then 1 else Double.NaN; def NSdn = if close - close(period = "day" )[1] <= 0 then 1 else Double.NaN; AddLabel(NSup, "NS", Color.GREEN); AddLabel(NSdn, "NS", Color.RED); #Open Signal def OSup = if close - open(period = "day" ) > 0 then 1 else Double.NaN; def OSdn = if close - open(period = "day" ) < 0 then 1 else Double.NaN; AddLabel(OSup, "OS", Color.GREEN); AddLabel(OSdn, "OS", Color.RED); #High / Low Signal def Higher = if close > high(period = "day" )[1] then 1 else Double.NaN; def Lower = if close < low(period = "day" )[1] then 1 else Double.NaN; def Neutral = if close <= high(period="day" )[1] and close >= low(period="day" )[1] then 1 else Double.NaN; AddLabel(Higher, "H/L", Color.GREEN); AddLabel(Lower, "H/L", Color.RED); AddLabel(Neutral, "H/L", Color.GRAY); #Out of Bounds def sDev = StDev(close, 21); def MidLine = Average(close, 21); def UpperBand = MidLine + 2 * sDev; def LowerBand = MidLine - 2 * sDev; def CloseAbove = if close > UpperBand then 1 else Double.NaN; def CloseBelow = if close < LowerBand then 1 else Double.NaN; AddLabel(CloseAbove, round(close - UpperBand,2), Color.WHITE); AddLabel(CloseBelow, round(close - LowerBand,2), Color.WHITE);
Re: Fun with ThinkScript December 19, 2013 10:58PM |
Registered: 11 years ago Posts: 615 |
# Billy Bob's Better Gap Indicator input Detect_Gaps_By = {default "percent", "dollars"}; input Min_Gap_Size = 1.0; input NumberOfGapsToTrack = {default "3", "2", "1"}; input ShowGapIndicatorBubbles = yes; input show_gap_mid_line = yes; input show_half_gap_move_up = yes; input show_half_gap_move_down = yes; input show_full_gap_move_up = yes; input show_full_gap_move_down = yes; # Decide how many simultaneous gaps to track def show_gap2; def show_gap3; switch (numberOfGapsToTrack) { case "3": show_gap2 = yes; show_gap3 = yes; case "2": show_gap2 = yes; show_gap3 = no; case "1": show_gap2 = no; show_gap3 = no; }; # Declare Global Colors DefineGlobalColor("gap top", CreateColor(165, 138, 193)); DefineGlobalColor("gap bottom", CreateColor(165, 138, 193)); DefineGlobalColor("gap middle", CreateColor(155, 206, 225)); DefineGlobalColor("gap half up", CreateColor(134, 202, 93)); DefineGlobalColor("gap full up", CreateColor(224, 243, 177)); DefineGlobalColor("gap half down", CreateColor(250, 141, 183)); DefineGlobalColor("gap full down", CreateColor(253, 222, 238)); # Define Candle Body def bodyTop = Max(open, close); def bodyBottom = Min(open, close); # Define Gap Lines def GapTop = Max(bodyBottom, bodyBottom[1]); def GapBottom = Min(bodyTop, bodyTop[1]); def GapMiddle = if show_gap_mid_line then (GapTop + GapBottom) / 2 else Double.NaN; def GapHalfUp = if show_half_gap_move_up then GapTop + (GapTop - GapBottom) / 2 else Double.NaN; def GapHalfDown = if show_half_gap_move_down then GapBottom - (GapTop - GapBottom) / 2 else Double.NaN; def GapFullUp = if show_full_gap_move_up then GapTop + (GapTop - GapBottom) else Double.NaN; def GapFullDown = if show_full_gap_move_down then GapBottom - (GapTop - GapBottom) else Double.NaN; # Define a gap and its direction def MinGapSize; switch (Detect_Gaps_By) { case "percent": MinGapSize = Min(close[1] * (Min_Gap_Size/100),5); case "dollars": MinGapSize = Min_Gap_Size; }; def GapUp = bodyBottom - bodyTop[1] >= MinGapSize; def GapDown = bodyTop - bodyBottom[1] <= -MinGapSize; def isGap = GapUp or GapDown; AddChartBubble(ShowGapIndicatorBubbles and GapUp[-1], bodyBottom[-1], bodyBottom[-1], GlobalColor("gap half up" ), no); AddChartBubble(ShowGapIndicatorBubbles and GapUp[-1], bodyTop, bodyTop, GlobalColor("gap half up" )); AddChartBubble(ShowGapIndicatorBubbles and GapDown[-1], bodyTop[-1], bodyTop[-1], GlobalColor("gap half down" )); AddChartBubble(ShowGapIndicatorBubbles and GapDown[-1], bodyBottom, bodyBottom, GlobalColor("gap half down" ),no); # Define recursive variables # Set variables for the first gap rec gt1 = if isGap then GapTop else gt1[1]; rec gb1 = if isGap then GapBottom else gb1[1]; rec gm1 = if isGap then GapMiddle else gm1[1]; rec ghu1 = if isGap then GapHalfUp else ghu1[1]; rec ghd1 = if isGap then GapHalfDown else ghd1[1]; rec gfu1 = if isGap then GapFullUp else gfu1[1]; rec gfd1 = if isGap then GapFullDown else gfd1[1]; # Set variables for the second gap rec gt2 = if isGap and gt2[1] <> gt1[1] then gt1[1] else gt2[1]; rec gb2 = if isGap and gb2[1] <> gb1[1] then gb1[1] else gb2[1]; rec gm2 = if isGap and gm2[1] <> gm1[1] then gm1[1] else gm2[1]; rec ghu2 = if isGap and ghu2[1] <> ghu1[1] then ghu1[1] else ghu2[1]; rec ghd2 = if isGap and ghd2[1] <> ghd1[1] then ghd1[1] else ghd2[1]; rec gfu2 = if isGap and gfu2[1] <> gfu1[1] then gfu1[1] else gfu2[1]; rec gfd2 = if isGap and gfd2[1] <> gfd1[1] then gfd1[1] else gfd2[1]; # Set variables for the third gap rec gt3 = if isGap and gt3[1] <> gt2[1] then gt2[1] else gt3[1]; rec gb3 = if isGap and gb3[1] <> gb2[1] then gb2[1] else gb3[1]; rec gm3 = if isGap and gm3[1] <> gm2[1] then gm2[1] else gm3[1]; rec ghu3 = if isGap and ghu3[1] <> ghu2[1] then ghu2[1] else ghu3[1]; rec ghd3 = if isGap and ghd3[1] <> ghd2[1] then ghd2[1] else ghd3[1]; rec gfu3 = if isGap and gfu3[1] <> gfu2[1] then gfu2[1] else gfu3[1]; rec gfd3 = if isGap and gfd3[1] <> gfd2[1] then gfd2[1] else gfd3[1]; # Plot Gap Lines # plot the first gap plot pgt1 = if gt1 == 0 then double.nan else gt1; plot pgb1 = if gb1 == 0 then double.nan else gb1; plot pgm1 = if gm1 == 0 then double.nan else gm1; plot pghu1 = if ghu1 == 0 then double.nan else ghu1; plot pghd1 = if ghd1 == 0 then double.nan else ghd1; plot pgfu1 = if gfu1 == 0 then double.nan else gfu1; plot pgfd1 = if gfd1 == 0 then double.nan else gfd1; pgt1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgb1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgm1.SetPaintingStrategy(PaintingStrategy.DASHES); pghu1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pghd1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgfu1.SetPaintingStrategy(PaintingStrategy.DASHES); pgfd1.SetPaintingStrategy(PaintingStrategy.DASHES); pgt1.SetLineWeight(2); pgb1.SetLineWeight(2); pghu1.SetLineWeight(2); pghd1.SetLineWeight(2); pgt1.AssignValueColor(GlobalColor("gap top" )); pgb1.AssignValueColor(GlobalColor("gap bottom" )); pgm1.AssignValueColor(GlobalColor("gap middle" )); pghu1.AssignValueColor(GlobalColor("gap half up" )); pghd1.AssignValueColor(GlobalColor("gap half down" )); pgfu1.AssignValueColor(GlobalColor("gap full up" )); pgfd1.AssignValueColor(GlobalColor("gap full down" )); # Plot the second gap plot pgt2 = if gt2 == 0 then double.nan else gt2; plot pgb2 = if gb2 == 0 then double.nan else gb2; plot pgm2 = if gm2 == 0 then double.nan else gm2; plot pghu2 = if ghu2 == 0 then double.nan else ghu2; plot pghd2 = if ghd2 == 0 then double.nan else ghd2; plot pgfu2 = if gfu2 == 0 then double.nan else gfu2; plot pgfd2 = if gfd2 == 0 then double.nan else gfd2; pgt2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgb2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgm2.SetPaintingStrategy(PaintingStrategy.DASHES); pghu2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pghd2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgfu2.SetPaintingStrategy(PaintingStrategy.DASHES); pgfd2.SetPaintingStrategy(PaintingStrategy.DASHES); pgt2.SetLineWeight(2); pgb2.SetLineWeight(2); pghu2.SetLineWeight(2); pghd2.SetLineWeight(2); pgt2.AssignValueColor(GlobalColor("gap top" )); pgb2.AssignValueColor(GlobalColor("gap bottom" )); pgm2.AssignValueColor(GlobalColor("gap middle" )); pghu2.AssignValueColor(GlobalColor("gap half up" )); pghd2.AssignValueColor(GlobalColor("gap half down" )); pgfu2.AssignValueColor(GlobalColor("gap full up" )); pgfd2.AssignValueColor(GlobalColor("gap full down" )); pgt2.sethiding(if show_gap2 then 0 else 1); pgb2.sethiding(if show_gap2 then 0 else 1); pgm2.sethiding(if show_gap2 then 0 else 1); pghu2.sethiding(if show_gap2 then 0 else 1); pghd2.sethiding(if show_gap2 then 0 else 1); pgfu2.sethiding(if show_gap2 then 0 else 1); pgfd2.sethiding(if show_gap2 then 0 else 1); # Plot the third gap plot pgt3 = if gt3 == 0 then double.nan else gt3; plot pgb3 = if gb3 == 0 then double.nan else gb3; plot pgm3 = if gm3 == 0 then double.nan else gm3; plot pghu3 = if ghu3 == 0 then double.nan else ghu3; plot pghd3 = if ghd3 == 0 then double.nan else ghd3; plot pgfu3 = if gfu3 == 0 then double.nan else gfu3; plot pgfd3 = if gfd3 == 0 then double.nan else gfd3; pgt3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgb3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgm3.SetPaintingStrategy(PaintingStrategy.DASHES); pghu3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pghd3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pgfu3.SetPaintingStrategy(PaintingStrategy.DASHES); pgfd3.SetPaintingStrategy(PaintingStrategy.DASHES); pgt3.SetLineWeight(3); pgb3.SetLineWeight(3); pghu3.SetLineWeight(3); pghd3.SetLineWeight(3); pgt3.AssignValueColor(GlobalColor("gap top" )); pgb3.AssignValueColor(GlobalColor("gap bottom" )); pgm3.AssignValueColor(GlobalColor("gap middle" )); pghu3.AssignValueColor(GlobalColor("gap half up" )); pghd3.AssignValueColor(GlobalColor("gap half down" )); pgfu3.AssignValueColor(GlobalColor("gap full up" )); pgfd3.AssignValueColor(GlobalColor("gap full down" )); pgt3.sethiding(if show_gap3 then 0 else 1); pgb3.sethiding(if show_gap3 then 0 else 1); pgm3.sethiding(if show_gap3 then 0 else 1); pghu3.sethiding(if show_gap3 then 0 else 1); pghd3.sethiding(if show_gap3 then 0 else 1); pgfu3.sethiding(if show_gap3 then 0 else 1); pgfd3.sethiding(if show_gap3 then 0 else 1);
Re: Fun with ThinkScript December 20, 2013 12:36PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript December 20, 2013 02:33PM |
Registered: 12 years ago Posts: 321 |
Re: Fun with ThinkScript December 20, 2013 03:32PM |
Registered: 11 years ago Posts: 615 |
Quote
RichieRick
These are all great!!
Now get to work on an AutoWave for TOS!!!
## START CODE ## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from Thinkorswim ZigZagSign Script input price = close; input priceH = high; # swing high input priceL = low; # swing low input ATRreversalfactor = 3.2; def ATR = ATRWilder("atr length" = 5); def reversalAmount = ATRreversalfactor * ATR; input showlines = yes; input displace = 1; input showBubbleschange = yes; def barNumber = BarNumber(); def barCount = HighestAll(If(IsNaN(price), 0, barNumber)); rec state = {default init, undefined, uptrend, downtrend}; rec minMaxPrice; if (GetValue(state, 1) == GetValue(state.init, 0)) { minMaxPrice = price; state = state.undefined; } else if (GetValue(state, 1) == GetValue(state.undefined, 0)) { if (price <= GetValue(minMaxPrice, 1) - reversalAmount) { state = state.downtrend; minMaxPrice = priceL; } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) { state = state.uptrend; minMaxPrice = priceH; } else { state = state.undefined; minMaxPrice = GetValue(minMaxPrice, 1); } } else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) { if (price <= GetValue(minMaxPrice, 1) - reversalAmount) { state = state.downtrend; minMaxPrice = priceL; } else { state = state.uptrend; minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1)); } } else { if (price >= GetValue(minMaxPrice, 1) + reversalAmount) { state = state.uptrend; minMaxPrice = priceH; } else { state = state.downtrend; minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1)); } } def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1; def futureDepth = barCount - barNumber; def tmpLastPeriodBar; if (isCalculated) { if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) { tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1 while lastPeriodBarAcc > 0 do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI)) then -lastPeriodBarAcc else lastPeriodBarAcc + 1; } else { tmpLastPeriodBar = 0; } } else { tmpLastPeriodBar = Double.NaN; } def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth; rec currentPriceLevel; rec currentPoints; if (state == state.uptrend and isCalculated) { currentPriceLevel = fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI)); currentPoints = fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN while IsNaN(maxPointOnPeriodAcc) do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel) then maxPointOnPeriodI else maxPointOnPeriodAcc; } else if (state == state.downtrend and isCalculated) { currentPriceLevel = fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI)); currentPoints = fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN while IsNaN(minPointOnPeriodAcc) do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel) then minPointOnPeriodI else minPointOnPeriodAcc; } else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) { currentPriceLevel = GetValue(currentPriceLevel, 1); currentPoints = GetValue(currentPoints, 1) + 1; } else { currentPoints = 1; currentPriceLevel = GetValue(price, currentPoints); } plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN; rec zzSave = if !IsNaN("ZZ$" ) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1); def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1); def isUp = chg >= 0; #Higher/Lower/Equal High, Higher/Lower/Equal Low def xxhigh = if zzSave == priceH then round(high,2) else round(xxhigh[1],2); def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2); def xxlow = if zzSave == priceL then round(low,2) else round(xxlow[1],2); def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2); rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1)); "ZZ$".EnableApproximation(); "ZZ$".DefineColor("Up Trend", Color.UPTICK); "ZZ$".DefineColor("Down Trend", Color.DOWNTICK); "ZZ$".DefineColor("Undefined", Color.WHITE); "ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined" ) else if isUp then "ZZ$".Color("Up Trend" ) else "ZZ$".Color("Down Trend" )); DefineGlobalColor("Unconfirmed", Color.WHITE); DefineGlobalColor("Up", Color.UPTICK); DefineGlobalColor("Down", Color.DOWNTICK); AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , round(chg,2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp); ## END CODE
Re: Fun with ThinkScript December 20, 2013 07:52PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript December 21, 2013 04:37PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript December 23, 2013 10:19AM |
Registered: 11 years ago Posts: 4 |
Re: Fun with ThinkScript December 23, 2013 05:43PM |
Registered: 11 years ago Posts: 615 |
Quote
JLT248
Qcharts is awesome, anyone here use tradingview.com been using to chart bitcoin, only problem is, no Autowave.... any suggestions?
Re: Fun with ThinkScript January 13, 2014 01:03PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript January 15, 2014 04:56PM |
Registered: 11 years ago Posts: 615 |
Quote
RichieRick
Concerning the Auto Wave indicator for TOS. Is there a way to tell it NOT to show the "undefined" section? Also, could there be a way to tell the script NOT to show the line until the trend is either ended or reversed?
It's kinda funny because the system seems to know when the change the color of the line, so it must know when the "trend" has ended or else it would just keep making the line red or green instead of the white for "undefined". What do ya think?
## START CODE ## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from Thinkorswim ZigZagSign Script input showBubbleschange = yes; def price = close; def priceH = high; # swing high def priceL = low; # swing low def ATRreversalfactor = 3.2; def ATR = ATRWilder("atr length" = 5); def reversalAmount = ATRreversalfactor * ATR; def displace = 1; def barNumber = BarNumber(); def barCount = HighestAll(If(IsNaN(price), 0, barNumber)); rec state = {default init, undefined, uptrend, downtrend}; rec minMaxPrice; if (GetValue(state, 1) == GetValue(state.init, 0)) { minMaxPrice = price; state = state.undefined; } else if (GetValue(state, 1) == GetValue(state.undefined, 0)) { if (price <= GetValue(minMaxPrice, 1) - reversalAmount) { state = state.downtrend; minMaxPrice = priceL; } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) { state = state.uptrend; minMaxPrice = priceH; } else { state = state.undefined; minMaxPrice = GetValue(minMaxPrice, 1); } } else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) { if (price <= GetValue(minMaxPrice, 1) - reversalAmount) { state = state.downtrend; minMaxPrice = priceL; } else { state = state.uptrend; minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1)); } } else { if (price >= GetValue(minMaxPrice, 1) + reversalAmount) { state = state.uptrend; minMaxPrice = priceH; } else { state = state.downtrend; minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1)); } } def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1; def futureDepth = barCount - barNumber; def tmpLastPeriodBar; if (isCalculated) { if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) { tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1 while lastPeriodBarAcc > 0 do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI)) then -lastPeriodBarAcc else lastPeriodBarAcc + 1; } else { tmpLastPeriodBar = 0; } } else { tmpLastPeriodBar = Double.NaN; } def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth; rec currentPriceLevel; rec currentPoints; if (state == state.uptrend and isCalculated) { currentPriceLevel = fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI)); currentPoints = fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN while IsNaN(maxPointOnPeriodAcc) do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel) then maxPointOnPeriodI else maxPointOnPeriodAcc; } else if (state == state.downtrend and isCalculated) { currentPriceLevel = fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI)); currentPoints = fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN while IsNaN(minPointOnPeriodAcc) do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel) then minPointOnPeriodI else minPointOnPeriodAcc; } else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) { currentPriceLevel = GetValue(currentPriceLevel, 1); currentPoints = GetValue(currentPoints, 1) + 1; } else { currentPoints = 1; currentPriceLevel = GetValue(price, currentPoints); } def data = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN; rec zzSave = if !IsNaN(data) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1); def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1); def isUp = chg >= 0; #Higher/Lower/Equal High, Higher/Lower/Equal Low def xxhigh = if zzSave == priceH then round(high,2) else round(xxhigh[1],2); def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2); def xxlow = if zzSave == priceL then round(low,2) else round(xxlow[1],2); def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2); rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(data, 1)) and GetValue(isConf, 1)); plot "ZZ$" = if isconf then data else double.nan; "ZZ$".EnableApproximation(); "ZZ$".setdefaultcolor(color.cyan); DefineGlobalColor("Unconfirmed", Color.WHITE); DefineGlobalColor("Up", Color.UPTICK); DefineGlobalColor("Down", Color.DOWNTICK); AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , round(chg,2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp); ## END CODE
Re: Fun with ThinkScript January 16, 2014 01:19PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript January 16, 2014 03:06PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript January 16, 2014 05:48PM |
Registered: 12 years ago Posts: 173 |
Re: Fun with ThinkScript January 16, 2014 06:03PM |
Registered: 11 years ago Posts: 615 |
Quote
TCB
May I ask what seems to be the differnce between your udated and the original modified zigzag3.2 besides the fact that then new code has a solid line now which could be done by changing the color in the original under the settings for the uptrend, downtrend, and unconfirmed trend to all be the same color. Just was wondering if I was missing something.
Re: Fun with ThinkScript January 16, 2014 06:05PM |
Registered: 11 years ago Posts: 615 |
Re: Fun with ThinkScript January 17, 2014 10:41AM |
Registered: 11 years ago Posts: 120 |
Re: Fun with ThinkScript January 17, 2014 11:33AM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript January 17, 2014 11:56AM |
Registered: 11 years ago Posts: 120 |
Re: Fun with ThinkScript January 17, 2014 12:30PM |
Registered: 11 years ago Posts: 615 |
Re: Fun with ThinkScript January 17, 2014 12:34PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript January 21, 2014 08:18PM |
Registered: 11 years ago Posts: 466 |
Re: Fun with ThinkScript January 21, 2014 11:20PM |
Registered: 11 years ago Posts: 615 |
Re: Fun with ThinkScript January 22, 2014 02:11AM |
Registered: 11 years ago Posts: 466 |