Darvas Box alert sound and arrow

rene6985

New member
VIP
Can somebody help me put an alert sound and arrow on the Darvas Box when it first print

Code:
# ************************************
#
# Simpler Trading Darvas Box
# By Eric Purdy
# Revision Date: 09/20/17
# (c) 2017 Simpler Trading, LLC
#
# ************************************

input plotBackwardsExtensions = yes;

DefineGlobalColor("HighFirstBox", color.yellow);
DefineGlobalColor("LowFirstBox", color.plum);

def state = {default init, one, two, three, four, five};

def boxHigh;
def boxLow;
def breakoutLong;
def breakoutShort;
def highFirst;
def lowFirst;

switch (state[1]) {

case init:

boxHigh = high;
boxLow = low;
state = state.one;
breakoutLong = no;
breakoutShort = no;
highFirst = yes;
lowFirst = no;

case one:

breakoutLong = no;
breakoutShort = no;
if highFirst[1]
then {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (high > boxHigh[1])
then {
boxHigh = high;
boxLow = boxLow[1];
state = state.one;
} else {
state = state.two;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
}
} else {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (low < boxLow[1])
then {
boxHigh = boxHigh[1];
boxLow = low;
state = state.one;
} else {
state = state.two;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
}
}
case two:

breakoutLong = no;
breakoutShort = no;
if highFirst[1]
then {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (high > boxHigh[1])
then {
boxHigh = high;
boxLow = boxLow[1];
state = state.one;
} else {
state = state.three;
boxHigh = boxHigh[1];
boxLow = low;
}
} else {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (low < boxLow[1])
then {
boxHigh = boxHigh[1];
boxLow = low;
state = state.one;
} else {
state = state.three;
boxHigh = high;
boxLow = boxLow[1];
}
}

case three:

breakoutLong = no;
breakoutShort = no;
if highFirst[1]
then {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (high > boxHigh[1])
then {
boxHigh = high;
boxLow = boxLow[1];
state = state.one;
} else if (low < boxLow[1]) {
state = state.three;
boxLow = low;
boxHigh = boxHigh[1];
} else {
state = state.four;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
}
} else {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (low < boxLow[1])
then {
boxHigh = boxHigh[1];
boxLow = low;
state = state.one;
} else if (high > boxHigh[1]) {
state = state.three;
boxLow = boxLow[1];
boxHigh = high;
} else {
state = state.four;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
}
}
case four:

breakoutLong = no;
breakoutShort = no;
if highFirst[1]
then {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (high > boxHigh[1])
then {
boxHigh = high;
boxLow = boxLow[1];
state = state.one;
} else if (low < boxLow[1]) {
state = state.three;
boxLow = low;
boxHigh = boxHigh[1];
} else {
state = state.five;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
}
} else {
highFirst = highFirst[1];
lowFirst = lowFirst[1];
if (low < boxLow[1])
then {
boxHigh = boxHigh[1];
boxLow = low;
state = state.one;
} else if (high > boxHigh[1]) {
state = state.three;
boxLow = boxLow[1];
boxHigh = high;
} else {
state = state.five;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
}
}
case five:

if (high > boxHigh[1] or low < boxLow[1])
then {
state = state.one;
breakoutLong = if (high > boxHigh[1]) then yes else no;
breakoutShort = if (low < boxLow[1]) then yes else no;
boxHigh = high;
boxLow = low;
highFirst = if breakoutLong then yes else no;
lowFirst = if breakoutShort then yes else no;
} else {
state = state.five;
boxHigh = boxHigh[1];
boxLow = boxLow[1];
highFirst = highFirst[1];
lowFirst = lowFirst[1];
breakoutLong = no;
breakoutShort = no;
}
}

def boxNumber = if state==state.five and state[1] != state.five then boxNumber[1]+1 else boxNumber[1];

plot boxHighPlot = if state == state.five and !isNan(close) then boxHigh else if ((breakoutLong or breakoutShort) and !isNan(close)) then boxHigh[1] else double.nan;
boxHighPlot.setLineWeight(3);
boxHighPlot.setPaintingStrategy(paintingStrategy.HORIZONTAL);
boxHighPlot.assignValueColor(if (highFirst and !(breakoutLong or breakoutShort)) or ((breakoutLong or breakOutShort) and highFirst[1]) then GlobalColor("HighFirstBox") else GlobalColor("LowFirstBox"));

plot boxLowPlot = if state == state.five and !isNan(close) then boxLow else if ((breakoutLong or breakoutShort) and !isNan(close)) then boxLow[1] else double.nan;
boxLowPlot.setLineWeight(3);
boxLowPlot.setPaintingStrategy(paintingStrategy.HORIZONTAL);
boxLowPlot.assignValueColor(if (highFirst and !(breakoutLong or breakoutShort)) or ((breakoutLong or breakOutShort) and highFirst[1]) then GlobalColor("HighFirstBox") else GlobalColor("LowFirstBox"));

plot longBoxBreak = if breakoutLong then 1 else double.nan;
longBoxBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
longBoxBreak.setLineWeight(2);
longBoxBreak.setDefaultColor(color.green);

plot shortBoxBreak = if breakoutShort then 1 else double.nan;
shortBoxBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
shortBoxBreak.setLineWeight(2);
shortBoxBreak.setDefaultColor(color.red);

boxHighPlot.hideBubble();
boxLowPlot.hideBubble();
longBoxBreak.hideBubble();
shortBoxBreak.hideBubble();

def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(close), 0, barNumber));
def boxNum;
def boxUpperIndex;

plot boxHighExtension;
plot boxLowExtension;

if (IsNaN(close)) {
boxNum = boxNum[1] + 1;
boxUpperIndex = 0;
boxHighExtension = Double.NaN;
boxLowExtension = Double.NaN;
} else {
boxNum = TotalSum(breakoutLong or breakoutShort);
boxUpperIndex = fold indx = 0 to barCount - barNumber + 2 with valInd = Double.NaN
while IsNaN(valInd)
do if (GetValue(boxNum, -indx) != boxNum)
then indx
else Double.NaN;
boxHighExtension = if plotBackwardsExtensions and !(breakoutLong or breakoutShort) then GetValue(boxHighPlot, -boxUpperIndex + 1) else double.nan;
boxLowExtension = if plotBackwardsExtensions and !(breakoutLong or breakoutShort) then GetValue(boxLowPlot, -boxUpperIndex + 1) else double.nan;
}

boxHighExtension.assignValueColor(if highFirst then GlobalColor("HighFirstBox") else GlobalColor("LowFirstBox") );
boxHighExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
boxHighExtension.hideBubble();
boxHighExtension.setLineWeight(2);
boxLowExtension.assignValueColor(if highFirst then GlobalColor("HighFirstBox") else GlobalColor("LowFirstBox") );
boxLowExtension.setpaintingStrategy(paintingStrategy.HORIZONTAL);
boxLowExtension.hideBubble();
boxLowExtension.setLineWeight(2);
 

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
403 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