Darvas Box Indicator for ThinkorSwim

Good afternoon everyone! Before I get into my question, I spent some time trying to find my answer instead of just throwing it up here. I have been talking with my circle about finding a way to acquire an indicator on Thinkorswim for the Darvas Box. Versions of this question have been asked, and I saw a post for a consolidation box, but it was not what we were looking for.

Is there a way to develop a custom Darvas Box indicator?

Additionally, TOS has a darvas box study, but it too does not do what we are looking for.

This indicator that we are looking for would need to have the ability to draw a box that follows the definition/criteria of a Darvas Box.

I do not mean to ask in a vague way, but I just am at a road block. Any insight would be appreciated!

Code:
# DARVASBOX
# DREWGRIFFITH15 (C) 2014

def state = {default state_1, state_2, state_3, state_4, state_5};

def upper;
def lower;

def prevLower = CompoundValue(1, lower[1], low);
def prevUpper = CompoundValue(1, upper[1], high);

switch (state[1]) {
case state_1:
    lower = low;
    if (prevUpper >= high) {
        upper = high[1];
        state = state.state_2;
    } else {
        upper = high;
        state = state.state_1;
    }
case state_2:
    if (prevUpper >= high) {
        lower = low;
        upper = prevUpper;
        state = state.state_3;
    } else {
        lower = low;
        upper = high;
        state = state.state_1;
    }
case state_3:
    if (prevUpper < high) {
        lower = low;
        upper = high;
        state = state.state_1;
    } else if (prevLower > low) {
        lower = low;
        upper = prevUpper;
        state = state.state_3;
    } else {
        lower = prevLower;
        upper = prevUpper;
        state = state.state_4;
    }
case state_4:
    if (prevUpper < high) {
        lower = low;
        upper = high;
        state = state.state_1;
    } else if (prevLower > low) {
        lower = low;
        upper = prevUpper;
        state = state.state_3;
    } else {
        lower = prevLower;
        upper = prevUpper;
        state = state.state_5;
    }
case state_5:
    if (prevUpper < high) {
        lower = low;
        upper = high;
        state = state.state_1;
    } else if (prevLower > low) {
        lower = low;
        upper = high;
        state = state.state_1;
    } else {
        lower = prevLower;
        upper = prevUpper;
        state = state.state_5;
    }
}

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

plot "Upper Band";
plot "Lower Band";
plot "Buy Signal" = CompoundValue(1, state[1] == state.state_5 and prevUpper < close, no);
plot "Sell Signal" = CompoundValue(1, state[1] == state.state_5 and prevLower > close, no);
plot "Rating" = if CompoundValue(1, state[1] == state.state_5 and prevUpper < close, no) then 2
                else if CompoundValue(1, state[1] == state.state_5 and prevLower > close, no) then 1
                else 0;

if (IsNaN(close)) {
    boxNum = boxNum[1] + 1;
    boxUpperIndex = 0;
    "Upper Band" = Double.NaN;
    "Lower Band" = Double.NaN;
} else {
    boxNum = TotalSum("Buy Signal" or "Sell Signal");
    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;
    "Upper Band" = GetValue(upper, -boxUpperIndex + 1);
    "Lower Band" = GetValue(lower, -boxUpperIndex + 1);
}

"Upper Band".SetDefaultColor(Color.GREEN);
"Lower Band".SetDefaultColor(Color.RED);
"Sell Signal".SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
"Sell Signal".SetDefaultColor(Color.RED);
"Buy Signal".SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
"Buy Signal".SetDefaultColor(Color.GREEN);
"Rating".hide();
"Rating".HideBubble();
 
Solution
how to use
Are you asking me how to use the Darvas Box? Well I don't scan for it anymore, instead I have a very large watchlist. But I do still use the Darvas. It's a useful indicator, essentially it's a dynamic support/resistance indicator. So if the Darvas's lower and upper band get pushed upward, that's a sign of former resistance being broken.

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

@ProfessorAR15 Here is another version of the Darvas Box script...

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);
 
Last edited:
@ProfessorAR15 Here is another version of the Darvas Box script...

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);
Hi Rad, thanks for the script. When combined with the MACD on a 5 minute chart it looks like a winner tool. Stay safe!
 
Hello guys. So I just finished talking to someone on the support chat and they tried for probably an hour to get my scanner to do what I want it to do but couldn't. They told me to try tomorrow because all the people who have a really deep understanding of how the scanner works left for home already.

So here's my issue. I'm working on a Darvas Box scanner with a 4h aggregate. What I want the scanner to do is scan for stocks that recently opened under the lower band of the Darvas. There are 2 issues currently. #1, sometimes (not super often but often enough) I get results where the price definitely is not below the lower band. #2 and mainly what I contacted support about, I want to know if there is a way to limit the results to only show stocks that are 1 to 3 candles deep into the below-band trend. I don't want results that are 6 or 10 candles into that trend.

Here are all my parameters:
0y1XLr8.png


Just as a quick example of what I'm talking about, here's one of the results:
whfZxLR.png


As you can see the candle with the red arrow on top is the first candle outside/below the lower band. I'd like for the screener to give me results where that is the case rather than when the trend has already developed.

Note: I also tried the "crosses under" parameter to no avail

So those are basically my issues. I don't get it man. If anyone can help me out PLEASE do.
 
Last edited:
have you tried,
.. turning off extended hours?
.. a smaller time, like hour or 15 min.
i'm wondering if looking for multiple 4hour candles, with some in extended hours, may have inconsistant results.
 
have you tried,
.. turning off extended hours?
.. a smaller time, like hour or 15 min.
i'm wondering if looking for multiple 4hour candles, with some in extended hours, may have inconsistant results.

I did both and it didn't really address my issue. I guess what I'm specifically looking for is a parameter that can look back to x number of previous candles and see if they already met my criteria to ignore that stock. For example if ABC has met my criteria for 8 candles already, I can set my screener to ignore results that have met my criteria for 3+ candles. This way I can only get stocks that have immediately entered my criteria.
 
@fungus12 You should be able to use indexing to check the trend direction of as many candles/bars back as you require...
Not exactly sure what that means but trend direction of previous candles wouldn't really help my situation. It's not always that it's strictly a downtrend leading into a candle being outside Darvas. Like here for example:
4npPBpt.png


There's an uptrend at least 6 candles back before it moves outside the Darvas Box, so trend direction of previous candles wouldn't really help. Isn't there some way to filter results if x number of previous candles also met the criteria? For example, if candles that met the critera have 4 or more candles prior that also met that critera, remove result.
 
Hello guys. So I just finished talking to someone on the support chat and they tried for probably an hour to get my scanner to do what I want it to do but couldn't. They told me to try tomorrow because all the people who have a really deep understanding of how the scanner works left for home already.

So here's my issue. I'm working on a Darvas Box scanner with a 4h aggregate. What I want the scanner to do is scan for stocks that recently opened under the lower band of the Darvas. There are 2 issues currently. #1, sometimes (not super often but often enough) I get results where the price definitely is not below the lower band. #2 and mainly what I contacted support about, I want to know if there is a way to limit the results to only show stocks that are 1 to 3 candles deep into the below-band trend. I don't want results that are 6 or 10 candles into that trend.

Here are all my parameters:
0y1XLr8.png


Just as a quick example of what I'm talking about, here's one of the results:
whfZxLR.png


As you can see the candle with the red arrow on top is the first candle outside/below the lower band. I'd like for the screener to give me results where that is the case rather than when the trend has already developed.

Note: I also tried the "crosses under" parameter to no avail

So those are basically my issues. I don't get it man. If anyone can help me out PLEASE do.
how to use
 
how to use
Are you asking me how to use the Darvas Box? Well I don't scan for it anymore, instead I have a very large watchlist. But I do still use the Darvas. It's a useful indicator, essentially it's a dynamic support/resistance indicator. So if the Darvas's lower and upper band get pushed upward, that's a sign of former resistance being broken.
 
Solution
Kinda late, but do you mean something like this? (This was given to me a few years ago)
Code:
declare upper;
Input ArrowsOn = Yes;
Input BoxesOn = Yes;
Input ColorPrice = No;
input SoundOn = No;
Input InternalBoxes = No;
Input IntArrowsOn = No;


rec internalUp = if High[3] < High[2] then 1 else 0;
rec Topint = if InternalUp && High <= High[1] then High[1] else if High > TopInt[1] then High else Topint[1];
plot TopInternal = if !InternalBoxes then Double.NaN else Topint;

rec internalDn = if Low[3] > Low[1] then 1 else 0;
rec Bottomint = if internalDn && Low >= Low[1] then Low[1] else if Low < Bottomint[1] then Low else Bottomint[1];
plot BottomInternal = if !InternalBoxes then Double.NaN else Bottomint;

AssignPriceColor(
if ColorPrice then
if high > Topint[1] then color.Uptick else
if low < Bottomint[1] then color.Downtick
else color.gray
else color.current);

rec flop = if low < Bottomint[1] && flop[1] != -1 then -1 else if high > Topint[1] && flop[1] != 1 then 1 else flop[1];

plot signalDnint = if !IntArrowsOn or flop[1] == -1 then Double.NaN else if low < Bottomint[1] then Topint else Double.NaN;
SignalDnint.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SignalDnint.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

plot signalUpint = if !IntArrowsOn or flop[1] == 1 then Double.NaN else if high > Topint[1] then Bottomint else Double.NaN;
SignalUpint.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SignalUpint.SetPaintingStrategy(PaintingStrategy.ARROW_UP);



rec ThreeUp = if High[2] < High then 1 else 0;
rec Topline = if ThreeUp && High <= High[1] then High[1] else if High > TopLine[1] then High else Topline[1];
plot top = if !BoxesOn then Double.NaN else Topline;

rec ThreeDn = if Low[2] > Low then 1 else 0;
rec Bottomline = if ThreeDn && Low >= Low[1] then Low[1] else if Low < BottomLine[1] then Low else Bottomline[1];
plot Bottom = if !BoxesOn then Double.NaN else Bottomline;

AssignPriceColor(
if ColorPrice then
if high > topline[1] then color.Uptick else
if low < Bottomline[1] then color.Downtick
else color.gray
else color.current);


rec flip = if low < BottomLine[1] && flip[1] != -1 then -1 else if high > TopLine[1] && flip[1] != 1 then 1 else flip[1];


plot SignalDn = if !ArrowsOn or flip[1] == -1 then Double.NaN else if low < Bottomline[1] then TopLine else Double.NaN;
SignalDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SignalDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

plot SignalUp = if !ArrowsOn or flip[1] == 1 then Double.NaN else if high > topline[1] then BottomLine else Double.NaN;
SignalUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SignalUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

topInternal.SetDefaultColor( Color.Magenta);
BottomInternal.SetDefaultColor( Color.Magenta);
SignalDnint.SetDefaultColor( Color.Magenta);
SignalUpint.SetDefaultColor( Color.Magenta);
Top.SetDefaultColor( Color.Yellow);
Bottom.SetDefaultColor( Color.Yellow);
SignalDn.SetDefaultColor( Color.Yellow);
SignalUp.SetDefaultColor( Color.Yellow);

#plot signalDn = if !ArrowsOn then Double.NaN else if low < Bottomline[1] then High + ((High - Low) / 3) else Double.NaN;
#plot signalUp = if !ArrowsOn then Double.NaN else if high > topline[1] then Low - ((high - low) / 3) else Double.NaN;

def osc = if high > topline[1] then 1 else if low < Bottomline[1] then -1 else 0;
alert(osc == -1 and SoundOn , "Darvas Alert", alert.bar, sound.Ring);
alert(osc == 1 and SoundOn , "Darvas Alert", alert.bar, sound.Ring);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
365 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