Re: double.NaN alternative February 01, 2019 02:36PM |
Registered: 9 years ago Posts: 13 |
Re: double.NaN alternative February 01, 2019 04:05PM |
Registered: 7 years ago Posts: 126 |
AddLabel(buy,((close[length]-open[length])*.25)+open[length] ,color.lighT_GREEN); AddLabel(sell, ((open[length]-close[length])*.75)+close[length] ,color.pink);
Re: double.NaN alternative February 01, 2019 05:11PM |
Registered: 9 years ago Posts: 13 |
Re: Fun with ThinkScript February 06, 2019 07:21AM |
Registered: 5 years ago Posts: 5 |
#Plots InsideDay Bars 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(Createcolor(240, 98, 146)); signal.SetLineWeight(3); Alert(signal, getsymbol() + " inside & narrow range day.", alert.bar, sound.noSound); ## following code doesn't plot where I want to it. Have to work on it. def SignalBar= IsNaN(close[-1]) and !IsNaN(close); AddChartBubble(SignalBar[-2], signal, "IB",CreateColor(41, 182, 246));
Re: chartbubble position February 06, 2019 11:53AM |
Registered: 7 years ago Posts: 126 |
#Plots InsideDay Bars 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; ## following code doesn't plot where I want to it. Have to work on it. def SignalBar= IsNaN(close) and !IsNaN(close); AddChartBubble(signal, high, "IB",CreateColor(41, 182, 246),yes); signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); signal.SetDefaultColor(Createcolor(240, 98, 146)); signal.SetLineWeight(3); Alert(signal, getsymbol() + " inside & narrow range day.", alert.bar, sound.noSound);
Re: chartbubble position February 06, 2019 02:52PM |
Registered: 5 years ago Posts: 5 |
Re: chartbubble position February 06, 2019 03:39PM |
Registered: 7 years ago Posts: 126 |
ThinkScript question February 12, 2019 06:51PM |
Registered: 10 years ago Posts: 465 |
Re: ThinkScript question February 12, 2019 08:44PM |
Registered: 12 years ago Posts: 172 |
Re: Fun with ThinkScript February 14, 2019 01:25PM |
Registered: 5 years ago Posts: 2 |
script OpenRange { input ORtime = 5; def FirstBar = GetDay() != GetDay()[1]; def RangeTime = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime; def Rhigh = if FirstBar then high else if RangeTime and high > Rhigh[1] then high else Rhigh[1]; def Rlow = if FirstBar then low else if RangeTime and low < Rlow[1] then low else Rlow[1]; plot h = if RangeTime then Double.NaN else Rhigh; plot l = if RangeTime then Double.NaN else Rlow; } def first30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) >= 0; def today = GetLastDay() == GetDay(); def ATR = AvgTrueRange(high, close, low, 10); plot yHigh = if !today then Double.NaN else high(period = "day" )[1]; yHigh.SetDefaultColor(Color.CYAN); plot yLow = if !today then Double.NaN else low(period = "day" )[1]; yLow.SetDefaultColor(Color.PINK); plot h5 = if !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).h; h5.SetDefaultColor(Color.YELLOW); plot l5 = if !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).l; l5.SetDefaultColor(Color.YELLOW); plot h30 = if !today then Double.NaN else OpenRange(30).h; h30.SetDefaultColor(Color.YELLOW); plot l30 = if !today then Double.NaN else OpenRange(30).l; l30.SetDefaultColor(Color.YELLOW); def lowConf = if first30 then Min(yLow, l5) - ATR else Min(yLow, l30) - ATR; def highConf = if first30 then Max(yHigh, h5) + ATR else Max(yHigh, h30) + ATR; plot lc1 = if first30 then lowConf else Double.NaN; lc1.SetDefaultColor(Color.ORANGE); plot lc2 = if !first30 then lowConf else Double.NaN; lc2.SetDefaultColor(Color.ORANGE); plot hc1 = if first30 then highConf else Double.NaN; hc1.SetDefaultColor(Color.ORANGE); plot hc2 = if !first30 then highConf else Double.NaN; hc2.SetDefaultColor(Color.ORANGE); def decisionL = if close > lowConf then Double.NaN else if close crosses below lowConf then low else decisionL[1]; def decisionH = if close < highConf then Double.NaN else if close crosses above highConf then high else decisionH[1]; plot dL = if !today then Double.NaN else decisionL; dL.SetDefaultColor(Color.WHITE); plot dH = if !today then Double.NaN else decisionH; dH.SetDefaultColor(Color.WHITE); def TL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(TL[1]) then TL[1] else if close crosses below dL then dL - 2 * ATR else Double.NaN, Double.NaN); def SL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(SL[1]) then SL[1] else if close crosses below dL then dL + 2 * ATR else Double.NaN, Double.NaN); plot Target1Low = if !today then Double.NaN else TL; Target1Low.SetDefaultColor(Color.GREEN); Target1Low.SetStyle(Curve.SHORT_DASH); plot Stop1Low = if !today then Double.NaN else SL; Stop1Low.SetDefaultColor(Color.RED); Stop1Low.SetLineWeight(2); AddChartBubble(IsNaN(TL[1]) and !IsNaN(TL), TL, "Target 1\n" + Round(TL, 2), Color.GREEN, no); AddChartBubble(IsNaN(SL[1]) and !IsNaN(SL), SL, "Stop\n" + Round(SL, 2), Color.RED); def TH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(TH[1]) then TH[1] else if close crosses above dH then dH + 2 * ATR else Double.NaN, Double.NaN); def SH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(SH[1]) then SH[1] else if close crosses above dH then dH - 2 * ATR else Double.NaN, Double.NaN); plot Target1High = if !today then Double.NaN else TH; Target1High.SetDefaultColor(Color.GREEN); Target1High.SetStyle(Curve.SHORT_DASH); plot Stop1High = if !today then Double.NaN else SH; Stop1High.SetDefaultColor(Color.RED); Stop1High.SetLineWeight(2); AddChartBubble(IsNaN(TH[1]) and !IsNaN(TH), TH, "Target 1\n" + Round(TH, 2), Color.GREEN); AddChartBubble(IsNaN(SH[1]) and !IsNaN(SH), SH, "Stop\n" + Round(SH, 2), Color.RED, no);
Re: Fun with ThinkScript February 15, 2019 09:13PM |
Registered: 9 years ago Posts: 38 |
Re: Fun with ThinkScript February 17, 2019 03:09PM |
Registered: 7 years ago Posts: 6 |
declare lower; input over_bought = 80.0; input over_sold = 20.0; input percentDLength = 3; input percentKLength = 14; input AudibleAlert = yes; def min_low = Lowest(low, percentKLength); def max_high = Highest(high, percentKLength); def rel_diff = close - (max_high + min_low) / 2; def diff = max_high - min_low; def avgrel = Average(Average(rel_diff, percentDLength), percentDLength); def avgdiff = Average(Average(diff, percentDLength), percentDLength); def SMIData = (avgrel / (avgdiff / 2) + 1) * 50; def isLow = If (SMIData < SMIData[-1] and SMIData < SMIData[1], 1, 0); def isHigh = If (SMIData > SMIData[-1] and SMIData > SMIData[1], 1, 0); rec prevLowSMI = CompoundValue(1, If(isLow[1], SMIData[1], prevLowSMI[1]), 0); rec prevHighSMI = CompoundValue(1, If(isHigh[1], SMIData[1], prevHighSMI [1]), 0); rec prevLow = CompoundValue(1, If(isLow[1], low, prevLow[1]), low); rec prevHigh = CompoundValue(1, If(isHigh[1], high, prevHigh[1]), high); def positiveDivergenceReg = If (SMIData > prevLowSMI and low < prevLow, 1, 0); def positiveDivergenceHid = If (SMIData < prevLowSMI and low > prevLow, 1, 0); plot posDiv = If(isLow and (positiveDivergenceReg or positiveDivergenceHid), SMIData, Double.NaN); posDiv.AssignValueColor(if positiveDivergenceReg then Color.GREEN else Color.black); posDiv.SetPaintingStrategy(PaintingStrategy.ARROW_UP); posDiv.SetLineWeight(2); def negativeDivergenceReg = If (SMIData < prevHighSMI and high > prevHigh, 1, 0); def negativeDivergenceHid = If (SMIData > prevHighSMI and high < prevHigh, 1, 0); plot negDiv = If(isHigh and ( negativeDivergenceReg or negativeDivergenceHid), SMIData, Double.NaN); negDiv.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); negDiv.AssignValueColor(if negativeDivergenceReg then Color.RED else Color.black); negDiv.SetLineWeight(2); plot AvgSMI = Average(SMIData, percentDLength); AvgSMI.SetDefaultColor(Color.GRAY); plot overbought = over_bought; overbought.SetDefaultColor(Color.WHITE); overbought.SetStyle(Curve.SHORT_DASH); plot oversold = over_sold; oversold.SetDefaultColor(Color.WHITE); oversold.SetStyle(Curve.SHORT_DASH); plot SMI = SMIData; SMI.AssignValueColor(if SMI > SMI[1] then Color.GREEN else Color.RED); SMI.SetLineWeight(2); # Sound alerts Alert(AudibleAlert and positiveDivergenceReg, "Time TO Buy", Alert.BAR, Sound.Ring); Alert(AudibleAlert and negativeDivergenceReg, "Time TO Sell", Alert.BAR, Sound.Ring);
Re: Fun with ThinkScript February 18, 2019 03:37PM |
Registered: 9 years ago Posts: 67 |
def percentDLength = 3; def percentKLength = 14; def min_low = Lowest(low, percentKLength); def max_high = Highest(high, percentKLength); def rel_diff = close - (max_high + min_low) / 2; def diff = max_high - min_low; def avgrel = Average(Average(rel_diff, percentDLength), percentDLength); def avgdiff = Average(Average(diff, percentDLength), percentDLength); def SMIData = (avgrel / (avgdiff / 2) + 1) * 50; def isLow = If (SMIData < SMIData[-1] and SMIData < SMIData[1], 1, 0); def isHigh = If (SMIData > SMIData[-1] and SMIData > SMIData[1], 1, 0); rec prevLowSMI = CompoundValue(1, If(isLow[1], SMIData[1], prevLowSMI[1]), 0); rec prevHighSMI = CompoundValue(1, If(isHigh[1], SMIData[1], prevHighSMI[1]), 0); rec prevLow = CompoundValue(1, If(isLow[1], low, prevLow[1]), low); rec prevHigh = CompoundValue(1, If(isHigh[1], high, prevHigh[1]), high); def positiveDivergenceReg = If (SMIData > prevLowSMI and low < prevLow, 1, 0); def positiveDivergenceHid = If (SMIData < prevLowSMI and low > prevLow, 1, 0); plot posDiv = If(isLow and (positiveDivergenceReg or positiveDivergenceHid), SMIData, Double.NaN); def negativeDivergenceReg = If (SMIData < prevHighSMI and high > prevHigh, 1, 0); def negativeDivergenceHid = If (SMIData > prevHighSMI and high < prevHigh, 1, 0); #plot negDiv = If(isHigh and ( negativeDivergenceReg or negativeDivergenceHid), SMIData, Double.NaN);
Re: Fun with ThinkScript February 19, 2019 08:58AM |
Registered: 7 years ago Posts: 6 |
Re: Fun with ThinkScript February 19, 2019 05:46PM |
Registered: 5 years ago Posts: 2 |
input ORtime = 5; def FirstBar = secondsfromtime(0930) >= 0 and secondsfromtime(0930) < 60; def RangeTime = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime; def Rhigh = if FirstBar then high else if RangeTime and high > Rhigh[1] then high else Rhigh[1]; def Rlow = if FirstBar then low else if RangeTime and low < Rlow[1] then low else Rlow[1]; def h = if RangeTime or secondstilltime(0930) > 0 then Double.NaN else Rhigh; def l = if RangeTime or secondstilltime(0930) > 0 then Double.NaN else Rlow; input ORtime30 = 30; def RangeTime30 = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime30; def Rhigh30 = if FirstBar then high else if RangeTime30 and high > Rhigh30[1] then high else Rhigh30[1]; def Rlow30 = if FirstBar then low else if RangeTime30 and low < Rlow30[1] then low else Rlow30[1]; def h301 = if RangeTime30 or secondstilltime(0930) > 0 then Double.NaN else Rhigh30; def l301 = if RangeTime30 or secondstilltime(0930) > 0 then Double.NaN else Rlow30; def first30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) >= 0; def today = GetLastDay() == GetDay(); def ATR = Average(TrueRange(high, close, low), 10); #def yHigh = if !today then Double.NaN else high(period = "day" )[1]; #def yLow = if !today then Double.NaN else low(period = "day" )[1]; def yHigh = if !today then Double.NaN else highest(today[1]); def yLow = if !today then Double.NaN else lowest(today[1]); def h5 = if !today then Double.NaN else if !first30 then Double.NaN else h; def l5 = if !today then Double.NaN else if !first30 then Double.NaN else l; def h30 = if !today then Double.NaN else h301; def l30 = if !today then Double.NaN else l301; def lowConf = if first30 then Min(yLow, l5) - ATR else Min(yLow, l30) - ATR; def highConf = if first30 then Max(yHigh, h5) + ATR else Max(yHigh, h30) + ATR; def lc1 = if first30 then lowConf else Double.NaN; def lc2 = if !first30 then lowConf else Double.NaN; def hc1 = if first30 then highConf else Double.NaN; def hc2 = if !first30 then highConf else Double.NaN; def decisionL = if close > lowConf then Double.NaN else if close crosses below lowConf then low else decisionL[1]; def decisionH = if close < highConf then Double.NaN else if close crosses above highConf then high else decisionH[1]; def dL = if !today then Double.NaN else decisionL; def dH = if !today then Double.NaN else decisionH; def TL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(TL[1]) then TL[1] else if close crosses below dL then dL - 2 * ATR else Double.NaN, Double.NaN); def SL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(SL[1]) then SL[1] else if close crosses below dL then dL + 2 * ATR else Double.NaN, Double.NaN); def priceDiff = dL - TL; def Target1Low = if !today then Double.NaN else TL; def Stop1Low = if !today then Double.NaN else SL; def TH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(TH[1]) then TH[1] else if close crosses above dH then dH + 2 * ATR else Double.NaN, Double.NaN); def SH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(SH[1]) then SH[1] else if close crosses above dH then dH - 2 * ATR else Double.NaN, Double.NaN); def Target1High = if !today then Double.NaN else TH; def Stop1High = if !today then Double.NaN else SH; plot scan = dH; # plot scan = dL;
def yHigh = if !today then Double.NaN else highest(today[1]); def yLow = if !today then Double.NaN else lowest(today[1]);
Re: Fun with ThinkScript February 21, 2019 01:51PM |
Registered: 8 years ago Posts: 15 |
Re: Fun with ThinkScript February 21, 2019 02:00PM |
Registered: 8 years ago Posts: 15 |
Re: Fun with ThinkScript February 21, 2019 09:07PM |
Registered: 9 years ago Posts: 67 |
input magnitude = 3; input peak_spacer = 8; input valley_spacer = 8; # define and plot the most recent peak def peak = high >= Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude); def peakvalue = if BarNumber() < magnitude then Double.NaN else if peak then high else Double.NaN; #plot peakline = peakvalue; plot peakline = if peakvalue[0] then (high + peak_spacer * tickSize()) else Double.NAN; #peakline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); peakline.SetPaintingStrategy(PaintingStrategy.POINTS); peakline.SetDefaultColor(Color.DOWNTICK); peakline.SetLineWeight(1); # define and plot the most recent valley def valley = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude); def valleyvalue = if BarNumber() < magnitude then Double.NaN else if valley then low else Double.NaN; #plot valleyline = valleyvalue; plot valleyline = if valleyvalue[0] then (low - valley_spacer * tickSize()) else Double.NAN; #valleyline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); valleyline.SetPaintingStrategy(PaintingStrategy.POINTS); valleyline.SetDefaultColor(Color.UPTICK); valleyline.SetLineWeight(1);
Re: Fun with ThinkScript February 22, 2019 01:04PM |
Registered: 5 years ago Posts: 3 |
Re: Fun with ThinkScript February 22, 2019 08:05PM |
Registered: 5 years ago Posts: 9 |
Re: Fun with ThinkScript February 22, 2019 11:51PM |
Registered: 8 years ago Posts: 15 |
Re: ThinkScript question February 23, 2019 03:05PM |
Registered: 10 years ago Posts: 465 |
Re: ThinkScript question February 23, 2019 06:43PM |
Registered: 9 years ago Posts: 67 |
Re: Fun with ThinkScript February 24, 2019 09:19PM |
Registered: 10 years ago Posts: 465 |
Re: Fun with ThinkScript March 02, 2019 09:13PM |
Registered: 5 years ago Posts: 1 |
Re: Fun with ThinkScript March 13, 2019 06:45PM |
Registered: 5 years ago Posts: 2 |
Study filter - hourly intraday - condition met for any of 7 candles March 17, 2019 07:40AM |
Registered: 5 years ago Posts: 2 |
count highs and lows March 17, 2019 08:54PM |
Registered: 5 years ago Posts: 2 |
input numBars = 5; input showLines = no; input showValues = yes; input showBarNumbers = no; def currentHigh = high; def currentLow = low; def currentBar = BarNumber(); def PH; def PL; def isHigherThanNextBars = fold i = 1 to numBars + 1 with p = 1 while p do currentHigh > GetValue(high, -i); ########################### PH = if ( currentBar == 0) then currentHigh else if (currentBar > numBars and currentHigh == Highest(currentHigh, numBars) and isHigherThanNextBars) then currentHigh else Double.NaN; ################################# def isLowerThanNextBars = fold j = 1 to numBars + 1 with q = 1 while q do currentLow < GetValue(low, -j); PL = if ( currentBar == 0 ) then currentLow else if (currentBar > numBars and currentLow == Lowest(currentLow, numBars) and isLowerThanNextBars) then currentLow else Double.NaN; #rec PHBar = if UserSetResistance then TrendResistanceEnd else if !IsNaN(PH) then currentBar else PHBar[1]; rec PHBar = if !IsNaN(PH) then currentBar else PHBar[1]; rec PLBar = if !IsNaN(PL) then currentBar else PLBar[1]; rec PHL = if !IsNaN(PH) then PH else PHL[1]; rec priorPHBar = if PHL != PHL[1] then PHBar[1] else priorPHBar[1]; rec PLL = if !IsNaN(PL) then PL else PLL[1]; rec priorPLBar = if PLL != PLL[1] then PLBar[1] else priorPLBar[1]; def isFinalTwoHighPivots = currentBar >= HighestAll(priorPHBar); def isFinalTwoLowPivots = currentBar >= HighestAll(priorPLBar); def ResistanceFinishOffset = if isFinalTwoHighPivots then currentBar - PHBar else 0; def ResistanceStartOffset = if isFinalTwoHighPivots then currentBar - priorPHBar else 0; def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) - GetValue(PH, ResistanceStartOffset)) / (PHBar - priorPHBar); def SupportFinishOffset = if isFinalTwoLowPivots then currentBar - PLBar else 0; def SupportStartOffset = if isFinalTwoLowPivots then currentBar - priorPLBar else 0; def SupportSlope = (GetValue(PL, SupportFinishOffset) - GetValue(PL, SupportStartOffset)) / (PLBar - priorPLBar); rec ResistanceExtend = if currentBar == HighestAll(PHBar) then 1 else ResistanceExtend[1]; rec SupportExtend = if currentBar == HighestAll(PLBar) then 1 else SupportExtend[1]; ######################################## plot pivotHigh = if PH > 0 then PH else Double.NaN; plot pivotLow = if PL > 0 then PL else Double.NaN; ##################################################################### pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE); #pivotHigh.SetHiding(!showValues); pivotLow.SetDefaultColor(GetColor(4)); pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW); def countUp = Sum(pivotHigh, 100); def peakValue = ph; def valleyValue = pl; def diff = peakValue - valleyValue; def count = if pivotHigh[1] then 1 else count[1] + 1; ## needed?? plot peakArrow = pivotHigh; peakArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); plot valleyArrow = pivotLow; valleyArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); def theDiff = peakValue - valleyValue[1]; # the problem is here?? def sumPeak = sum(pivotHigh,100); def sumValley = sum(pivotLow,100); AddChartBubble(peakValue, high + .01, high + " " + sumPeak , Color.WHITE); def nextPeak = peakValue; def thisLow = valleyValue[1]; #def lowPlusdiff = thisLow + theDiff; def lowPlusdiff = thisLow + Diff; AddChartBubble(valleyValue[1], thisLow[1] - 2, lowPlusDiff + "\n"+ diff + "\n"+ thisLow, Color.green, no ); AddLabel(sumPeak, "p"+sumPeak, Color.green); AddLabel(sumPeak, "v"+sumValley, Color.RED);
Re: Fun with ThinkScript RMO questions? March 18, 2019 09:32AM |
Registered: 8 years ago Posts: 15 |