NexusFi: Find Your Edge


Home Menu

 





TOS DEMANDINDEX with Alerts


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,502 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

TOS DEMANDINDEX with Alerts

  #1 (permalink)
westgl
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));

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The choice of instruments to trade
Psychology and Money Management
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
20 thanks
My NQ Trading Journal
19 thanks
Just another trading journal: PA, Wyckoff & Trends
17 thanks
Tao te Trade: way of the WLD
13 thanks
Daytrading ES & NQ
9 thanks
  #2 (permalink)
westgl
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!


Reply With Quote
  #3 (permalink)
westgl
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!

Reply With Quote
  #4 (permalink)
futures777
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

Reply With Quote




Last Updated on October 2, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts