Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
TOS DEMANDINDEX with Alerts
Updated October 2, 2020
trending_up
2,512 views
thumb_up
0 thanks given
group
2 followers
forum
3 posts
attach_file
0 attachments
TOS DEMANDINDEX with Alerts
March 18th, 2019, 11:22 AM
Medford Oregon
Posts: 3 since Dec 2018
Thanks Given: 0
Thanks Received: 0
Hello, I am New to thinkscript and have searched for DemandIndex with Alerts But cannot find it already coded, Can someone help me.
I would like to have the alert trigger for Both above and below Zero line, which ever gets triggered.
Thanks
Here is the Demand Index Code
#
# TD Ameritrade IP Company, Inc. (c) 2010-2019
#
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));
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
March 18th, 2019, 12:11 PM
Medford Oregon
Posts: 3 since Dec 2018
Thanks Given: 0
Thanks Received: 0
I tried adding this alert code but it is Not working.
new code in the quoting bubble
#
# TD Ameritrade IP Company, Inc. (c) 2010-2019
#
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));
Quoting
#Thinkscript Tip: Alert Code Block for
Think or Swim
#Here’s a block of code that I am going to be implementing in scripts in future. It’s a generic alert configuration code. It assumes that you have another line in your code that defines what the alert trigger is, like so:
#def alerttrigger = high>high[1];
#The line above says I want an alert if the bar’s high is above the last bar’s high, for example. You can replace it with whatever you want to be alerted about.
#
# Alerts:
#
def alerttrigger = HIGH>0.0; #replace the 1 with your definition
# BLOCK CODE BELOW
input alerttext = “Alert Text”;
input UseAlerts = {false, default true};
input AlertType = {default “BAR”, “ONCE”, “TICK”};
def at=AlertType;
input AlertSound = {“Bell”, “Chimes”, default “Ding”, “NoSound”, “Ring”};
alert(alerttrigger AND UseAlerts, alerttext, if at==1 then Alert.ONCE else if at==2 then Alert.TICK else Alert.BAR, AlertSound);
#NOTES To use it in your scripts, change the “def alerttrigger = 1;” line in your code to what you want to alert about, and then drop the entire code block at the end of your script file. Instant configurable alerts!
March 19th, 2019, 11:44 AM
Medford Oregon
Posts: 3 since Dec 2018
Thanks Given: 0
Thanks Received: 0
This is what I have tried that is NOT working.
The
def alerttrigger = HIGH>0;
is Not sending any alert?
#
# TD Ameritrade IP Company, Inc. (c) 2010-2019
#
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));
#Thinkscript Tip: Alert Code Block for Think or Swim
#Here’s a block of code that I am going to be implementing in scripts in future. It’s a generic alert configuration code. It assumes that you have another line in your code that defines what the alert trigger is, like so:
#def alerttrigger = high>high[1];
#The line above says I want an alert if the bar’s high is above the last bar’s high, for example. You can replace it with whatever you want to be alerted about.
#
# Alerts:
#
def alerttrigger = HIGH>0; #replace the 1 with your definition
# BLOCK CODE BELOW
input alerttext = “Alert Text”;
input UseAlerts = {false, default true};
input AlertType = {default “BAR”, “ONCE”, “TICK”};
def at=AlertType;
input AlertSound = {“Bell”, “Chimes”, default “Ding”, “NoSound”, “Ring”};
alert(alerttrigger AND UseAlerts, alerttext, if at==1 then Alert.ONCE else if at==2 then Alert.TICK else Alert.BAR, AlertSound);
#NOTES To use it in your scripts, change the “def alerttrigger = 1;” line in your code to what you want to alert about, and then drop the entire code block at the end of your script file. Instant configurable alerts!
October 2nd, 2020, 04:56 PM
popayan + cauca/colombia
Posts: 4 since Aug 2020
Thanks Given: 0
Thanks Received: 0
hi there, I have this study script called DEMA Crossover with Heikin Ashi Candle Confirmation:
===
def demaSlow = DEMA(close, 8);#8
def demaFast = DEMA(close, 21);#21
plot demaFastlt = DEMA(close, 50);#50
demaFastlt.SetLineWeight(2);
plot demaFastvlt = DEMA(close, 200);#200
demaFastvlt.SetLineWeight(4);
def HAclose = ohlc4;
def HAopen = CompoundValue(1,(HAopen[1] + HAclose[1]) / 2,
(open[1] + close[1]) / 2);
def HAhigh = Max(Max(high, HAopen), HAclose);
def HAlow = Min(Min(low, HAopen), HAclose);
def demaCrossingOverGoingDown = demaSlow[1] > demaFast[1] and demaSlow < demaFast;
def demaCrossingOverGoingUp = demaSlow < demaFast and demaSlow[-1] > demaFast[-1];
def HARed = HAOpen > HAclose;
def HAGreen = !HARed;
def HADecidedRed = HARed and HAHigh == HAopen;
def HADecidedGreen = HAGreen and HAlow == HAOpen;
######################################################################################
######################################################################################
#def sellsignal = demaCrossingOverGoingDown and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);
def sellsignal = demaCrossingOverGoingDown and close < demaFastlt and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);
#def buysignal = demaCrossingOverGoingUp and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);
def buysignal = demaCrossingOverGoingUp and close > demaFastlt and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);
#When testing need to turn the comment "" off
AddOrder(OrderType.SELL_AUTO, sellsignal equals 1, close, 1, Color.RED, Color.RED, "DEMA Sell @" + close);
AddOrder(OrderType.BUY_AUTO, buysignal equals 1, close[-1], 1, Color.GREEN, Color.GREEN, "DEMA Buy @" + close);
#AddVerticalLine(close crosses demaFastvlt, close, Color.yellow, Curve.SHORT_DASH);
#AddVerticalLine(buysignal, close, Color.GREEN, Curve.SHORT_DASH);
AddChartBubble(demaCrossingOverGoingUp, low,"DEMA HA",Color.dark_green);
AddChartBubble(demaCrossingOverGoingDown, high,"DEMA HA",Color.dark_red);
#Alert
def alerttrigger1 = buysignal;
def alerttrigger2 = sellsignal;
input alerttext1 = " ++++++++++ DEMA + HA +++++++++++ ";
input alerttext2 = " ---------- DEMA - HA ---------- ";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};
def at = AlertType;
input AlertSound = {"Chimes", "Bell", default "Ring", "NoSound", "Ding"};
Alert (alerttrigger1 and UseAlerts, alerttext1, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
Alert (alerttrigger2 and UseAlerts, alerttext2, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
====
Can someone help us? Please, we need a script based on this study to scan stocks in the TOS scanner tool
thank you very much
Last Updated on October 2, 2020