Custom Mix Indicator

ysanchezmd

New member
VIP
I want to be able to finish this custom indicator that mix some of the indicators already in our web. The indicator is error is at 255, 255, and 263 lines. Thank you to all that help and provide their knowledge and time to us. Special respect and admiration to @Samer.

Ruby:
input displayOptions = {default "Oscillator", "Bar Chart", "Show Osc & Bar"};
input timeframe = {default "Chart", "Custom"};
input HorizontalOffset = 3;
input showMarketSentimentLabel = yes;
input show_Divergence = {"Regular", "Hidden", "All", default "None"};
input LookBackRight = 5;
input LookBackLeft = 5;
input MaxLookback = 60;
input MinLookback = 5;
input normalizationLength = 3;
input useVolumeZoneOscillator = yes;
input vzo_Length = 14;
input useRsi = yes;
input rsiSource = close;
input rsi_Length = 14;
input useStochastic = yes;
input stoch_LengthK = 14;
input stoch_SmoothK = 3;
input useStochasticRsi = yes;
input stochRsiSource = close;
input stochRSI_LengthRSI = 14;
input stochRSI_LengthK = 14;
input stochRSI_SmoothK = 3;
input useCci = yes;
input cciSource = hlc3;
input cci_Length = 20;
input useBullBearPower = yes;
input bbp_Length = 13;
input useMovingAverage = yes;
input maTypes = AverageType.SIMPLE;
input maSource = close;
input maLengths = 20;
input useVwap = yes;
input vwapAnchor = {default "Auto", "DAY", "WEEK", "MONTH", "YEAR"};
input vwapStDev = 2.0;
input useBollingerBands = yes;
input bb_Type = AverageType.SIMPLE;
input bbSource = close;
input bb_Length = 20;
input bb_Mult = 2.0;
input useSupertrend = yes;
input SupertrendSource = hl2;
input st_Period = 10;
input st_Factor = 3.0;
input useLinearRegression = yes;
input LinRegSource = close;
input lr_Length = 25;

def nas = Double.NaN;
def lasts = IsNaN(close);
def bar = BarNumber();
def both = displayOptions == displayOptions."Show Osc & Bar";
def candle = displayOptions == displayOptions."Bar Chart" or both;
def oscs = displayOptions == displayOptions."Oscillator" or both;

DefineGlobalColor("blue", CreateColor(8, 93, 239));

def agg = GetAggregationPeriod();
def Day = AggregationPeriod.DAY;
def week = AggregationPeriod.WEEK;
def islowDay = AggregationPeriod.FIFTEEN_MIN;
def AnchAuto = if agg <= islowDay then GetDay() else if agg < Day then GetWeek() else if agg < Week then GetMonth() else GetYear();
def Anchor = if vwapAnchor == vwapAnchor."DAY" then GetDay()
else if vwapAnchor == vwapAnchor."WEEK" then GetWeek()
else if vwapAnchor == vwapAnchor."MONTH" then GetMonth()
else if vwapAnchor == vwapAnchor."YEAR" then GetYear()
else AnchAuto;
def rsi_Source = if timeframe == timeframe."Chart" then close else nas;
def stochRSI_SourceRSI = if timeframe == timeframe."Chart" then close else nas;
def cci_Source = if timeframe == timeframe."Chart" then hlc3 else nas;
def ma_source = if timeframe == timeframe."Chart" then close else nas;
def vwap_Source = vwap;
def bb_Source = if timeframe == timeframe."Chart" then close else nas;
def st_source = if timeframe == timeframe."Chart" then hl2 else nas;
def lr_Source = if timeframe == timeframe."Chart" then close else nas;
def cs = close;
def c1 = close[1];
def hs = high;
def lls = low;
def vs = volume;

script stoch {
input src = close;
input h = high;
input l = low;
input len = 14;
def hh = Highest(h, len);
def ll = Lowest(l, len);
def c1 = src - ll;
def c2 = hh - ll;
def stoch = if c2 != 0 then c1 / c2 * 100 else 0;
plot return = stoch;
}

script Pivots {
input series = close;
input leftBars = 10;
input rightBars = 10;
input isHigh = yes;
def na = Double.NaN;
def HH = series == Highest(series, leftBars + 1);
def LL = series == Lowest(series, leftBars + 1);
def pivotRange = (leftBars + rightBars + 1);
def leftEdgeValue = if series[pivotRange] == 0 then na else series[pivotRange];
def pvtCond = !IsNaN(series) and leftBars > 0 and rightBars > 0 and !IsNaN(leftEdgeValue);
def barIndexH = if pvtCond then
fold i = 1 to rightBars + 1 with p=1 while p do
series > GetValue(series, -i) else na;
def barIndexL = if pvtCond then
fold j = 1 to rightBars + 1 with q=1 while q do
series < GetValue(series, -j) else na;
def PivotPoint;
if isHigh {
PivotPoint = if HH and barIndexH then series else na;
} else {
PivotPoint = if LL and barIndexL then series else na;
}
plot pvt = PivotPoint;
}

script supertrend {
input factor = 3;
input src = close;
input atr = close;
def upBand = src + factor * atr;
def loBand = src - factor * atr;
def lowerBand; def upperBand;
def prevLowerBand = if IsNaN(lowerBand[1]) then prevLowerBand[1] else lowerBand[1];
def prevUpperBand = if IsNaN(upperBand[1]) then prevUpperBand[1] else upperBand[1];
lowerBand = if loBand > prevLowerBand or close[1] < prevLowerBand then loBand else prevLowerBand;
upperBand = if upBand < prevUpperBand or close[1] > prevUpperBand then upBand else prevUpperBand;
def _direction;
def superTrend;
def prevSuperTrend = superTrend[1];
if IsNaN(atr[1]) {
_direction = 1;
} else if prevSuperTrend == prevUpperBand {
_direction = if close > upperBand then -1 else 1;
} else {
_direction = if close < lowerBand then 1 else -1;
}
superTrend = if _direction == -1 then lowerBand else upperBand;
plot st = if IsNaN(superTrend) then Double.NaN else superTrend;
plot dir = if IsNaN(_direction) then Double.NaN else _direction;
}

script f_Vwap {
input src = close;
input tf = close;
input mult = 2;
input src_v = volume;
def isPeriodRolled = compoundValue(1, tf != tf[1], yes);
def sumSrc0 = src * src_v;
def sumVol0 = src_v ;
def sumSrc2 = src_v * Sqr(src);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if isPeriodRolled {
volumeSum = src_v;
volumeVwapSum = src_v * src;
volumeVwap2Sum = src_v * Sqr(src);
} else {
volumeSum = compoundValue(1, volumeSum[1] + src_v, src_v);
volumeVwapSum = compoundValue(1, volumeVwapSum[1] + src_v * src, src_v * src);
volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + src_v * Sqr(src), src_v * Sqr(src));
}
def Vwap = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(Vwap), 0));
def vwapBand = Vwap + deviation * mult;
plot wap = Vwap;
plot dev = vwapBand;
}

script interpolate {
input value = close;
input valueHigh = high;
input valueLow = low;
input rangeHigh = 100;
input rangeLow = 0;
def diff1 = valueHigh - valueLow;
def diff2 = rangeHigh - rangeLow;
plot return = if diff1 != 0 then ((value - valueLow) / diff1 * diff2) + rangeLow else 0;
}

script SimpleMovingAvg {
input avg_length = 9;
input src = close;
def data = if IsNaN(src) then 0 else src;
plot SMA = Average(data, avg_length);
}

script normalize {
input src = close;
input len = 50;
input buy = yes;
plot return = if IsNaN(src) then Double.NaN else if buy then (src - Lowest(src, len)) / (Highest(src, len) - Lowest(src, len)) else (Highest(src, len) - src) / (Highest(src, len) - Lowest(src, len));
}

script divergence {
input normalizeLength = 5;
input osc = close;
input high = close;
input low = close;
input signalLine = yes;
input priceStructure = close;
input divergenceType = {default "None", "Regular", "Hidden", "All"};
input lengthBackRight = 5;
input lengthBackLeft = 5;
def na = Double.NaN;
def top = if divergenceType != divergenceType."Hidden" then Pivots(priceStructure, lengthBackLeft, lengthBackRight, yes) else na;
def bottom = if divergenceType != divergenceType."Hidden" then Pivots(priceStructure, lengthBackLeft, lengthBackRight, no) else na;
def lastTop = if !IsNaN(top) then top else lastTop[1];
def lastBottom = if !IsNaN(bottom) then bottom else lastBottom[1];
def hiddenBottom = if divergenceType != divergenceType."Regular" then Pivots(priceStructure, lengthBackLeft, lengthBackRight, no) else na;
def hiddenTop = if divergenceType != divergenceType."Regular" then Pivots(priceStructure, lengthBackLeft, lengthBackRight, yes) else na;
def lastHiddenBottom = if !IsNaN(hiddenBottom) then hiddenBottom else lastHiddenBottom[1];
def lastHiddenTop = if !IsNaN(hiddenTop) then hiddenTop else lastHiddenTop[1];
def nosc = normalize(osc, normalizeLength, yes);
def topOsc = if divergenceType != divergenceType."Hidden" then Pivots(nosc, lengthBackLeft, lengthBackRight, yes) else na;
def bottomOsc = if divergenceType != divergenceType."Hidden" then Pivots(nosc, lengthBackLeft, lengthBackRight, no) else na;
def lastTopOsc = if !IsNaN(topOsc) then topOsc else lastTopOsc[1];
def lastBottomOsc = if !IsNaN(bottomOsc) then bottomOsc else lastBottomOsc[1];
def hiddenBottomOsc = if divergenceType != divergenceType."Regular" then Pivots(nosc, lengthBackLeft, lengthBackRight, no) else na;
def hiddenTopOsc = if divergenceType != divergenceType."Regular" then Pivots(nosc, lengthBackLeft, lengthBackRight, yes) else na;
def lastHiddenBottomOsc = if !IsNaN(hiddenBottomOsc) then hiddenBottomOsc else lastHiddenBottomOsc[1];
def lastHiddenTopOsc = if !IsNaN(hiddenTopOsc) then hiddenTopOsc else lastHiddenTopOsc[1];
def sl = if signalLine then if !IsNaN(topOsc) then topOsc else if !IsNaN(bottomOsc) then bottomOsc else sl[1] else Double.NaN;
def priceDiv = if divergenceType == divergenceType."Regular" or divergenceType == divergenceType."All" then
if !IsNaN(top) and !IsNaN(lastTop) and !IsNaN(lastTopOsc) and lastTopOsc > lastTopOsc[1] then 1 else
if !IsNaN(bottom) and !IsNaN(lastBottom) and !IsNaN(lastBottomOsc) and lastBottomOsc < lastBottomOsc[1] then -1 else 0
else 0;
def hiddenDiv = if divergenceType == divergenceType."Hidden" or divergenceType == divergenceType."All" then
if !IsNaN(hiddenBottom) and !IsNaN(lastHiddenBottom) and !IsNaN(lastHiddenBottomOsc) and lastHiddenBottomOsc > lastHiddenBottomOsc[1] then 1 else
if !IsNaN(hiddenTop) and !IsNaN(lastHiddenTop) and !IsNaN(lastHiddenTopOsc) and lastHiddenTopOsc < lastHiddenTopOsc[1] then -1 else 0
else 0;
plot div = priceDiv + hiddenDiv;
plot line = sl;
}

script ValueChange {
input src = close;
def data1 = src[1];
def change = (src - data1);
def percentage = if data1 != 0 then change / data1 else 0;
plot return = if IsNaN(percentage) then 0 else percentage;
}

def ma = if useMovingAverage then MovingAverage(maTypes, ma_source, maLengths) else nas;
def rsi = if useRsi then RSI(rsiSource, rsi_Length) else nas;
def cci = if useCci then CCI(cciSource, cci_Length) else nas;
def bb_Upper = if useBollingerBands then BollingerBands(bbSource, bb_Length, bb_Mult, bb_Type)."UpperBand" else nas;
def bb_Lower = if useBollingerBands then BollingerBands(bbSource, bb_Length, bb_Mult, bb_Type)."LowerBand" else nas;
def Supertrend = if useSupertrend then supertrend(st_Factor, st_source, Average(TrueRange(high, close, low), st_Period)).st else nas;
def vwap_Dev = if useVwap then f_Vwap(cs, Anchor, vwapStDev, vs).dev else nas;
def lr = if useLinearRegression then Inertia(lr_Source, lr_Length) else nas;
def vzo = if useVolumeZoneOscillator then VolumeZoneOscillator(vzo_Length) else nas;
def stochValue = if useStochastic then stoch(cs, hs, lls, stoch_LengthK).return else nas;
def stochRSIValue = if useStochasticRsi then stoch(RSI(stochRSI_SourceRSI, stochRSI_LengthRSI), hs, lls, stochRSI_LengthK).return else nas;
def bbPower = if useBullBearPower then (cs - MovingAverage(maTypes, ma_source, bbp_Length)) * 100 else nas;
def bbPowerOS = if useBullBearPower then normalize(bbPower, yes) else nas;

def oscillators = rsi + cci + vzo + stochValue + stochRSIValue + bbPowerOS + ma + bb_Lower + Supertrend + vwap_Dev + lr;
def marketSentiment = interpolate(oscillators, 100, 0, 100, 0);
def signalLine = SimpleMovingAvg(3, marketSentiment);
def divSignal = divergence(normalizationLength, marketSentiment, hs, lls, show_Divergence, cs, show_Divergence, LookBackRight, LookBackLeft);

plot msOsc = if oscs then marketSentiment else Double.NaN;
msOsc.SetLineWeight(2);
msOsc.SetDefaultColor(GetColor(3));
msOsc.SetPaintingStrategy(PaintingStrategy.LINE);

plot signal = if oscs then signalLine else Double.NaN;
signal.SetDefaultColor(GetColor(4));
signal.SetPaintingStrategy(PaintingStrategy.LINE);
signal.SetLineWeight(2);

AssignPriceColor(if marketSentiment > 50 then Color.UPTICK else if marketSentiment < 50 then Color.DOWNTICK else Color.CURRENT);
 
Last edited by a moderator:
Solution
Your oscillators have inputs in the wrong order inside the parentheses.

When not familiar with the order of the settings, it is suggested that
1. open the script
2. click on the function (for example, put your cursor on RSI)
3. click on Inspector
4. you can now, fill in the settings in the correct fields
CLpiy3W.png



Suggestion:
Research collinear:
https://usethinkscript.com/threads/...nt-to-successful-trading-in-thinkorswim.6114/

And google "overfitting trading indicators".
Your oscillators have inputs in the wrong order inside the parentheses.

When not familiar with the order of the settings, it is suggested that
1. open the script
2. click on the function (for example, put your cursor on RSI)
3. click on Inspector
4. you can now, fill in the settings in the correct fields
CLpiy3W.png



Suggestion:
Research collinear:
https://usethinkscript.com/threads/...nt-to-successful-trading-in-thinkorswim.6114/

And google "overfitting trading indicators".
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
593 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top