Black Dog System Indicator for ThinkorSwim - Strategy

Billions

Billions

Active member
2019 Donor
VIP
Can anyone help when I add this to the study for an label I get an error (AddLabel(BD, concat("BD:", if UpCross then "UP" else if DnCross then "DOWN" else "NAN"), if UpCross then color.GREEN else if DnCross then color.RED else color.WHITE)
I get an error on addable BD
 
T

tomsk

Well-known member
VIP
Today's question (ha ha)... What's the code to have a text box in the top left of the chart that shows the direction of the last BDog arrow? I've discovered AddLabel but am unable to get it to work correctly. As always, thank you.
Can anyone help when I add this to the study for an label I get an error (AddLabel(BD, concat("BD:", if UpCross then "UP" else if DnCross then "DOWN" else "NAN"), if UpCross then color.GREEN else if DnCross then color.RED else color.WHITE)
I get an error on addable BD
I've noticed several requests to add a chart label on Black Dogs & SESs 5 minute study that displays the direction of the last BDog cross arrow. I've implemented this based on the original code to that @BenTen posted in March 2019 when this thread first started (see post #1). I have it tested and looks good to go. Remember according to Ben's original note this study is designed to work on a 5 minute chart

Here then is version 1.1 of the Blackdog study. I have color coded the label for the last BDog UP/DOWN direction

Code:
#   Black Dogs & SESs---For 5 minute chart ONLY
#   NAMED BlackDog_SES_5min
#   Originally posted by BenTen
#   Modifications by tomsk, 1.10.2020

# V1.0 - 03.29.2019 - BenTen - Initial release of Black Dogs & SESs (5 Minute Aggregation) study
# V1.1 - 01.10.2020 - tomsk  - Added state transition engine and label that displays direction of last BDog signal

#   Here, "Black Dogs" are WHITE for use on a dark background.

input Hprice = high;
input Lprice = low;
input price = close;
input Hlength = 50;
input Llength = 50;
input Hdisplace = 0;
input Ldisplace = 0;

def StateUp = 1;
def StateDn = 2;

#   High / Low Band for SES computations---------------------------
#   EMA of HIGHS-----------------------------------------------------------
plot HAvg = MovAvgExponential(Hprice[-Hdisplace], Hlength);

HAvg.SetDefaultColor(Color.WHITE);
HAvg.SetLineWeight(5);
HAvg.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
HAvg.SetStyle(Curve.FIRM);
HAvg.HideBubble();
HAvg.HideTitle();

HAvg.AssignValueColor(if HAvg< HAvg[1] then Color.VIOLET else (if HAvg == HAvg[1] then Color.YELLOW else Color.YELLOW));

#   EMA of LOWS------------------------------------------------------------
plot LAvg = MovAvgExponential(Lprice[-Ldisplace], LLength);

LAvg.SetDefaultColor(Color.WHITE);
LAvg.SetLineWeight(5);
LAvg.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
LAvg.SetStyle(Curve.FIRM);
LAvg.HideBubble();
LAvg.HideTitle();

LAvg.AssignValueColor(if LAvg< LAvg[1] then Color.VIOLET else (if LAvg == LAvg[1] then Color.YELLOW else Color.YELLOW));

#   Crosses for SES Arrows----------------------------------------------
#   SES = Standard Entry Signal

#   Cross above High Average -----------------------------------------
def CrossUp = if price > HAvg AND price[1] < HAvg then 1 else 0;
Plot SESup = if CrossUp then high else double.nan;

SESup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SESup.SetLineWeight(3);
SESup.SetDefaultColor(color.YELLOW);
SESup.HideBubble();
SESup.HideTitle();

#   Cross above Low Average --------------------------------------------
def CrossDn = if price < Lavg AND price[1] > LAvg then 1 else 0;
Plot SESdn = if CrossDn then low else double.nan;

SESdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SESdn.SetLineWeight(3);
SESdn.SetDefaultColor(color.VIOLET);
SESdn.HideBubble();
SESdn.HideTitle();

#   ================================================
#
#    Black Dog Arrows------------------------------------------------------

#   Change Aggregation Period to 20 minutes------------------------
def agg = AggregationPeriod.TWENTY_MIN;
def data = close(period = agg);

#   2 EMAs of Black Dogs--------------------------------------------------
def BDfastEMA=ExpAverage(DATA,20);
def BDslowEMA=ExpAverage(DATA,100);

#   Black Dog UP for EMA20 crossing ABOVE EMA100-------------
def UpCross = if BDfastEMA > BDslowEma AND BDfastEMA[1] < BDslowEMA then 1 else 0;
Plot BDup = if UpCross then high else double.nan;

BDup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BDup.SetLineWeight(5);
BDup.SetDefaultColor(color.WHITE);
BDup.HideBubble();
BDup.HideTitle();

#   Black Dog DN for EMA20 crossing BELOW EMA100-----------
def DnCross = if BDfastEMA < BDslowEma AND BDfastEMA[1] > BDslowEMA then 1 else 0;
Plot BDdn = if DnCross then low else double.nan;

BDdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BDdn.SetLineWeight(5);
BDdn.SetDefaultColor(color.WHITE);
BDdn.HideBubble();
BDdn.HideTitle();

#   ================================================
#
#    State Transitions------------------------------------------------------

def LastXState;

if UpCross {
    LastXState = StateUp;
} else if DnCross {
    LastXState = StateDn;
} else {
    LastXState = LastXState[1];
}

AddLabel(1, "Last Cross Direction = " + if LastXState == StateUp then "UP" else if LastXState == StateDn then "DOWN" else "NOP",
    if LastXState == StateUp then Color.Green else if LastXState == StateDn then Color.Red else Color.Yellow);

#   END==========================================
# End Black Dogs & SESs---For 5 minute chart ONLY
 
Last edited:
B

Buckbull

Member
Why when I copy and paste the script and save it in studies or copy the link and go to open shared items and save it in studies it plots nothing on my chart ?
 
Billions

Billions

Active member
2019 Donor
VIP
Can someone help I've been using Black Dog System On 5 min chart, however I never see the white black dog arrows. I don't know what's wrong
 
BenTen

BenTen

Administrative
Staff
VIP
@Billions On which ticker do you not see the white arrows?
 
Billions

Billions

Active member
2019 Donor
VIP
I wonder if I have the right script. What is the new script in post # 82
 
T

tomsk

Well-known member
VIP
I wonder if I have the right script. What is the new script in post # 82

That was a modification made following a request from @hashy to display a label that shows the direction of the last BDog arrow? Details in the modification history in the study
 
Billions

Billions

Active member
2019 Donor
VIP
That was a modification made following a request from @hashy to display a label that shows the direction of the last BDog arrow? Details in the modification history in the study
Oh yes I see do I add this to the script that Ben originally posted or can I replace that script to add this label. Also I am not seeing a white black dog arrow
 
T

tomsk

Well-known member
VIP
Oh yes I see do I add this to the script that Ben originally posted or can I replace that script to add this label. Also I am not seeing a white black dog arrow

@Billions You can either add my modifications to @BenTen originally posted study, or use post #82 which already has that functionality incorporated in. Either approach is fine. For more info, read the change log in that study. Was that not explicit enough? Regarding the White BlackDog arrow, if you load that study on a 5 minute chart of AMZN, you'll see the white arrows. Make sure you have your expansion space increased, I set mine to 22.
 
Billions

Billions

Active member
2019 Donor
VIP
@Billions You can either add my modifications to @BenTen originally posted study, or use post #82 which already has that functionality incorporated in. Either approach is fine. For more info, read the change log in that study. Was that not explicit enough? Regarding the White BlackDog arrow, if you load that study on a 5 minute chart of AMZN, you'll see the white arrows. Make sure you have your expansion space increased, I set mine to 22.
This may sound dumb But where do I find the expansion area?
 
T

tomsk

Well-known member
VIP
@Billions Go to Chart Settings > Time Axis. You can see the expansion area setting to the right.
 
T

tomsk

Well-known member
VIP
Since I had some free time earlier today I took a closer look at the WHITE arrows on the original study. I believe part of the confusion was that WHITE arrows were used for BOTH a BDog Cross Up as well as a BDog Cross Down situation. This might be the basis of some of the recent confusion that was caused. I have now updated the code to adjust the positioning of the cross up/down arrows and as well as modified the color schemes for signals.

BDog Cross Up - Green
BDog Cross Down - Pink

Here's version 1.2 of the study

Code:
#   Black Dogs & SESs---For 5 minute chart ONLY
#   NAMED BlackDog_SES_5min
#   Originally posted by BenTen
#   Modifications by tomsk, 1.17.2020

# V1.0 - 03.29.2019 - BenTen - Initial release of Black Dogs & SESs (5 Minute Aggregation) study
# V1.1 - 01.10.2020 - tomsk  - Added state transition engine and label that displays direction of last BDog signal
# V1.2 - 01.17.2020 - tomsk  - Adjusted positioning of arrows and updated color schemes for signals

#   Here, "Black Dogs" are WHITE for use on a dark background.

input Hprice = high;
input Lprice = low;
input price = close;
input Hlength = 50;
input Llength = 50;
input Hdisplace = 0;
input Ldisplace = 0;

def StateUp = 1;
def StateDn = 2;

#   High / Low Band for SES computations
#   EMA of HIGHS

plot HAvg = MovAvgExponential(Hprice[-Hdisplace], Hlength);
HAvg.SetLineWeight(5);
HAvg.SetStyle(Curve.FIRM);
HAvg.HideBubble();
HAvg.HideTitle();
HAvg.AssignValueColor(if HAvg > HAvg[1] then Color.YELLOW else if HAvg < HAvg[1] then Color.VIOLET else Color.YELLOW);

#   EMA of LOWS

plot LAvg = MovAvgExponential(Lprice[-Ldisplace], LLength);
LAvg.SetLineWeight(5);
LAvg.SetStyle(Curve.FIRM);
LAvg.HideBubble();
LAvg.HideTitle();
LAvg.AssignValueColor(if LAvg > LAvg[1] then Color.YELLOW else if LAvg < LAvg[1] then Color.VIOLET else Color.YELLOW);

#   Crosses for SES Arrows
#   SES = Standard Entry Signal

#   Cross above High Average
plot SESup = if price > HAvg AND price[1] < HAvg then low else Double.NaN;
SESup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SESup.SetLineWeight(3);
SESup.SetDefaultColor(Color.CYAN);
SESup.HideBubble();
SESup.HideTitle();

#   Cross below Low Average
Plot SESdn = if price < Lavg AND price[1] > LAvg then high else Double.NaN;
SESdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SESdn.SetLineWeight(3);
SESdn.SetDefaultColor(color.YELLOW);
SESdn.HideBubble();
SESdn.HideTitle();

#    Black Dog Arrows

#   Change Aggregation Period to 20 minutes
def agg = AggregationPeriod.TWENTY_MIN;
def data = close(period = agg);

#   2 EMAs of Black Dogs
def BDfastEMA = ExpAverage(data,20);
def BDslowEMA = ExpAverage(data,100);

#   Black Dog UP for EMA20 crossing ABOVE EMA100
def UpCross = BDfastEMA > BDslowEMA and BDfastEMA[1] < BDslowEMA;
plot BDup = if UpCross then low else Double.NaN;
BDup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BDup.SetLineWeight(5);
BDup.SetDefaultColor(color.GREEN);
BDup.HideBubble();
BDup.HideTitle();

#   Black Dog DN for EMA20 crossing BELOW EMA100
def DnCross = BDfastEMA < BDslowEMA and BDfastEMA[1] > BDslowEMA;
plot BDdn = if DnCross then high else Double.NaN;
BDdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BDdn.SetLineWeight(5);
BDdn.SetDefaultColor(color.PINK);
BDdn.HideBubble();
BDdn.HideTitle();

#    State Transitions

def LastXState = if UpCross then StateUp 
                 else if DnCross then StateDn
                 else LastXState[1];

AddLabel(1, "Last Cross Direction = " + if LastXState == StateUp then "UP" else if LastXState == StateDn then "DOWN" else "NOP", 
    if LastXState == StateUp then Color.Green else if LastXState == StateDn then Color.Red else Color.Yellow);

#
# End Black Dogs & SESs---For 5 minute chart ONLY
 
Billions

Billions

Active member
2019 Donor
VIP
Since I had some free time earlier today I took a closer look at the WHITE arrows on the original study. I believe part of the confusion was that WHITE arrows were used for BOTH a BDog Cross Up as well as a BDog Cross Down situation. This might be the basis of some of the recent confusion that was caused. I have now updated the code to adjust the positioning of the cross up/down arrows and as well as modified the color schemes for signals.

BDog Cross Up - Green
BDog Cross Down - Pink

Here's version 1.2 of the study

Code:
#   Black Dogs & SESs---For 5 minute chart ONLY
#   NAMED BlackDog_SES_5min
#   Originally posted by BenTen
#   Modifications by tomsk, 1.17.2020

# V1.0 - 03.29.2019 - BenTen - Initial release of Black Dogs & SESs (5 Minute Aggregation) study
# V1.1 - 01.10.2020 - tomsk  - Added state transition engine and label that displays direction of last BDog signal
# V1.2 - 01.17.2020 - tomsk  - Adjusted positioning of arrows and updated color schemes for signals

#   Here, "Black Dogs" are WHITE for use on a dark background.

input Hprice = high;
input Lprice = low;
input price = close;
input Hlength = 50;
input Llength = 50;
input Hdisplace = 0;
input Ldisplace = 0;

def StateUp = 1;
def StateDn = 2;

#   High / Low Band for SES computations
#   EMA of HIGHS

plot HAvg = MovAvgExponential(Hprice[-Hdisplace], Hlength);
HAvg.SetLineWeight(5);
HAvg.SetStyle(Curve.FIRM);
HAvg.HideBubble();
HAvg.HideTitle();
HAvg.AssignValueColor(if HAvg > HAvg[1] then Color.YELLOW else if HAvg < HAvg[1] then Color.VIOLET else Color.YELLOW);

#   EMA of LOWS

plot LAvg = MovAvgExponential(Lprice[-Ldisplace], LLength);
LAvg.SetLineWeight(5);
LAvg.SetStyle(Curve.FIRM);
LAvg.HideBubble();
LAvg.HideTitle();
LAvg.AssignValueColor(if LAvg > LAvg[1] then Color.YELLOW else if LAvg < LAvg[1] then Color.VIOLET else Color.YELLOW);

#   Crosses for SES Arrows
#   SES = Standard Entry Signal

#   Cross above High Average
plot SESup = if price > HAvg AND price[1] < HAvg then low else Double.NaN;
SESup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SESup.SetLineWeight(3);
SESup.SetDefaultColor(Color.CYAN);
SESup.HideBubble();
SESup.HideTitle();

#   Cross below Low Average
Plot SESdn = if price < Lavg AND price[1] > LAvg then high else Double.NaN;
SESdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SESdn.SetLineWeight(3);
SESdn.SetDefaultColor(color.YELLOW);
SESdn.HideBubble();
SESdn.HideTitle();

#    Black Dog Arrows

#   Change Aggregation Period to 20 minutes
def agg = AggregationPeriod.TWENTY_MIN;
def data = close(period = agg);

#   2 EMAs of Black Dogs
def BDfastEMA = ExpAverage(data,20);
def BDslowEMA = ExpAverage(data,100);

#   Black Dog UP for EMA20 crossing ABOVE EMA100
def UpCross = BDfastEMA > BDslowEMA and BDfastEMA[1] < BDslowEMA;
plot BDup = if UpCross then low else Double.NaN;
BDup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BDup.SetLineWeight(5);
BDup.SetDefaultColor(color.GREEN);
BDup.HideBubble();
BDup.HideTitle();

#   Black Dog DN for EMA20 crossing BELOW EMA100
def DnCross = BDfastEMA < BDslowEMA and BDfastEMA[1] > BDslowEMA;
plot BDdn = if DnCross then high else Double.NaN;
BDdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BDdn.SetLineWeight(5);
BDdn.SetDefaultColor(color.PINK);
BDdn.HideBubble();
BDdn.HideTitle();

#    State Transitions

def LastXState = if UpCross then StateUp
                 else if DnCross then StateDn
                 else LastXState[1];

AddLabel(1, "Last Cross Direction = " + if LastXState == StateUp then "UP" else if LastXState == StateDn then "DOWN" else "NOP",
    if LastXState == StateUp then Color.Green else if LastXState == StateDn then Color.Red else Color.Yellow);

#
# End Black Dogs & SESs---For 5 minute chart ONLY
Great gonna load it up and see if I get a signal. I was seeing the yellow and purple lines and arrows but no white black dog let’s see if this script works better. I will keep you posted Thanks for the update I appreciate it.
 
BenTen

BenTen

Administrative
Staff
VIP
@Billions Best way to test is to create a fresh new chart and re-add the indicator. It seems from that screenshot you have multiple indicators that plot arrows. Sometimes other arrows may be in the way of the white arrows.

OR...

The white arrows have been changed to a different color. I think that's what happening here.
 
Billions

Billions

Active member
2019 Donor
VIP
@Billions Best way to test is to create a fresh new chart and re-add the indicator. It seems from that screenshot you have multiple indicators that plot arrows. Sometimes other arrows may be in the way of the white arrows.

OR...

The white arrows have been changed to a different color. I think that's what happening here.
Gotcha will do Thank you
 
Billions

Billions

Active member
2019 Donor
VIP
@BenTen Sorry to bother you can you send a picture of the chart showing the black dog white arrows. Its driving me crazy. Thanks
 

Similar threads

Top