Join useThinkScript to post your question to a community of 21,000+ developers and traders.
declare lower;
input length = 5;
input DMIndx_averageType = AverageType.EXPONENTIAL;
input DMIndx_average_length = 10;
def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(high, 2) - Lowest(low, 2), length) * AbsValue(wCRatio);
def volumeRatio = volume / Average(volume, length);
def volumePerClose = volumeRatio / Exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
buyP = volumeRatio;
sellP = volumePerClose;
} else {
buyP = volumePerClose;
sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (length - 1)) + buyP) / length;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (length - 1)) + sellP) / length;
def tempDI;
if ((((sellPres[1] * (length - 1)) + sellP) / length - ((buyPres[1] * (length - 1)) + buyP) / length) > 0) {
tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}
plot DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
plot ZeroLine = 0;
plot DMIndx_Average = Movingaverage(DMIndx_averageType, DMIndx, DMIndx_average_length);
DMIndx.DefineColor("Above", Color.UPTICK);
DMIndx.DefineColor("Below", Color.DOWNTICK);
DMIndx.AssignValueColor(if DMIndx > DMIndx_Average then DMIndx.Color("Above") else DMIndx.Color("Below"));
#
# Charles Schwab & Co. (c) 2010-2025
#
declare lower;
input length = 5;
def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(High, 2) - Lowest(Low, 2), length) * AbsValue(wCRatio);
def volumeRatio = Volume / Average(Volume, length);
def volumePerClose = volumeRatio / exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
buyP = volumeRatio;
sellP = volumePerClose;
} else {
buyP = volumePerClose;
sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (length - 1)) + buyP) / length;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (length - 1)) + sellP) / length;
def tempDI;
if ((((sellPres[1] * (length - 1)) + sellP) / length - ((buyPres[1] * (length - 1)) + buyP) / length) > 0) {
tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}
plot DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
plot ZeroLine = 0;
DMIndx.setDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(5));
This is awesome! Thank you so much, @BenTen.
Would it be possible to help me customize the script so it becomes an “upper study” that shows the “vertical line” only?
#
# Charles Schwab & Co. (c) 2010-2025
#
input length = 5;
def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(High, 2) - Lowest(Low, 2), length) * AbsValue(wCRatio);
def volumeRatio = Volume / Average(Volume, length);
def volumePerClose = volumeRatio / exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
buyP = volumeRatio;
sellP = volumePerClose;
} else {
buyP = volumePerClose;
sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (length - 1)) + buyP) / length;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (length - 1)) + sellP) / length;
def tempDI;
if ((((sellPres[1] * (length - 1)) + sellP) / length - ((buyPres[1] * (length - 1)) + buyP) / length) > 0) {
tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}
def DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
def ZeroLine = 0;
AddverticalLine(DMIndx crosses Zeroline);
Is there away to differentiate between bull and bearish?
can we add an input for both UCL (upper control limit) and LCL (lower control limit) with red color upper and green color lower
input OB = .2;
input OS = -.2;
plot pOB = if IsNaN(close) then Double.NaN else OB;
pOB.SetDefaultColor(color.red);
plot pOS = if IsNaN(close) then Double.NaN else OS;
pOS.SetDefaultColor(color.green);
This is perfect! Thank you so much, @BenTen. Have a great weekend.Sure thing, here's the code
Code:# # Charles Schwab & Co. (c) 2010-2025 # input length = 5; def wClose = (high + low + 2 * close) * 0.25; def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]); def closeRatio = 3 * wClose / Average(Highest(High, 2) - Lowest(Low, 2), length) * AbsValue(wCRatio); def volumeRatio = Volume / Average(Volume, length); def volumePerClose = volumeRatio / exp(Min(88, closeRatio)); def buyP; def sellP; if (wCRatio > 0) { buyP = volumeRatio; sellP = volumePerClose; } else { buyP = volumePerClose; sellP = volumeRatio; } def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (length - 1)) + buyP) / length; def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (length - 1)) + sellP) / length; def tempDI; if ((((sellPres[1] * (length - 1)) + sellP) / length - ((buyPres[1] * (length - 1)) + buyP) / length) > 0) { tempDI = - if (sellPres != 0) then buyPres / sellPres else 1; } else { tempDI = if (buyPres != 0) then sellPres / buyPres else 1; } def DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI; def ZeroLine = 0; AddverticalLine(DMIndx crosses Zeroline);
THANK YOU!!!add this code snippet to your study:
Ruby:input OB = .2; input OS = -.2; plot pOB = if IsNaN(close) then Double.NaN else OB; pOB.SetDefaultColor(color.red); plot pOS = if IsNaN(close) then Double.NaN else OS; pOS.SetDefaultColor(color.green);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
![]() |
Dynamic Supply and Demand Zones [AlgoAlpha] for ThinkOrSwim | Custom | 21 | |
C | RSI Based Automatic Supply and Demand For ThinkOrSwim | Custom | 4 | |
J | Godmode 4.0.2 [Supply/Demand] For ThinkOrSwim | Custom | 10 | |
S | Previous HOD and LOD for Supply Demand for ThinkOrSwim | Custom | 1 | |
A | RSI Supply/Demand For ThinkOrSwim | Custom | 13 |
Start a new thread and receive assistance from our community.
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.
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.