Is it possible to have the date along with the arrow when using a study?

pymoondra

New member
Currently, I have a study that displays an arrow when conditions are met:

Code:
plot result = if condition then high else Double.NaN;

result.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

result.SetLineWeight(4);

result.AssignValueColor(Color.magenta);



However, since I am back testing, I would like the dates to be displayed as well (or instead of the arrows if both can't be displayed)

Is this possible? Currently I have to scroll the mouse to get the date, which is slowing down the process.
 
Solution
Currently, I have a study that displays an arrow when conditions are met:

Code:
plot result = if condition then high else Double.NaN;
result.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
result.SetLineWeight(4);
result.AssignValueColor(Color.magenta);

However, since I am back testing, I would like the dates to be displayed as well (or instead of the arrows if both can't be displayed)
Is this possible? Currently I have to scroll the mouse to get the date, which is slowing down the process.

this can display a date on a bar, 3 different ways,
bubble (2 versions),
vertical line,
numbers , month above / day below

the font size of the values above/below plot values can't be changed with .SetLineWeight(5).

i moved the arrow...
Currently, I have a study that displays an arrow when conditions are met:

Code:
plot result = if condition then high else Double.NaN;
result.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
result.SetLineWeight(4);
result.AssignValueColor(Color.magenta);

However, since I am back testing, I would like the dates to be displayed as well (or instead of the arrows if both can't be displayed)
Is this possible? Currently I have to scroll the mouse to get the date, which is slowing down the process.

this can display a date on a bar, 3 different ways,
bubble (2 versions),
vertical line,
numbers , month above / day below

the font size of the values above/below plot values can't be changed with .SetLineWeight(5).

i moved the arrow up because of the boolean plot number above. i tried to pick factor numbers to get the number, arrow, and bubble stacked and not overlapping most of the time. but some numbers might have to be changed, depending on which output you choose.

replace my 2 averages code with your code that creates the signal.

this took a little longer to do and verify, because you provided partial code. i had to add test code for the signals.


Code:
# show_date_on_signal_00

# https://usethinkscript.com/threads/is-it-possible-to-have-the-date-along-with-the-arrow-when-using-a-study.13745/
# Is it possible to have the date along with the arrow when using a study?

def na = double.nan;
def bn = barnumber();
#def lastbar = !isnan(close[0]) and isnan(close[-1]);

#-----------------------------------
#from tos chat - mobius
def data = getYYYYMMDD();
def year = Round(data/10000, 0);
def month = Round((data % 10000) / 100, 0);
def day = (data % 100);
input test_date = no;
addLabel(test_date, "date: " + month + "/" + day + "/" + AsPrice(year), color.white);


#-----------------------------------
# test signals - 2 avg crossing

def price = close;
input ma1_len = 22;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 44;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input show_lines = yes;
plot z1 = if show_lines then ma1 else na;
z1.setdefaultcolor(getcolor(1));
z1.hidebubble();
plot z2 = if show_lines then ma2 else na;
z2.setdefaultcolor(getcolor(2));
z2.hidebubble();
#----------------------------------

def condition = ma1 crosses ma2;

#---------------------------------

input arrow_factor = 0.003;
def dwn = if condition then high*(1+arrow_factor) else Double.NaN;
input show_down_arrow = yes;
input arrow_size = 4;
plot result = dwn;
result.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
result.SetLineWeight(arrow_size);
result.AssignValueColor(Color.MAGENTA);

#---------------------------------

# show date on signal bar, in different ways

# bubble
input date_bubble1 = yes;
def vert_factor = 0.001;
#def buby = ( high * (1 + (arrow_size * vert_factor)));
def buby = ( dwn +  (high *((arrow_size * vert_factor))));
addchartbubble(date_bubble1 and dwn, buby, month + "/" + day, color.yellow, yes);

input date_bubble2 = no;
addchartbubble(date_bubble2 and dwn, buby, month + "\n" + day, color.yellow, yes);



# vertical line
input vertical_line_with_date = no;
addverticalline(vertical_line_with_date and dwn,  month + " / " + day, result.takevaluecolor(), curve.SHORT_DASH);
#addverticalline(vertical_line_with_date and dwn,  month + " / " + day +  " / " + AsPrice(year), color.yellow);


# above/below
input date_above_below_candle = yes;
plot dwn_mo = if date_above_below_candle and condition then month else Double.NaN;
dwn_mo.SetPaintingStrategy(PaintingStrategy.values_above);
dwn_mo.AssignValueColor(Color.white);
plot dwn_day = if date_above_below_candle and condition then day else Double.NaN;
dwn_day.SetPaintingStrategy(PaintingStrategy.values_below);
dwn_day.AssignValueColor(Color.white);
#

dGSZq8L.jpg


https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddChartBubble
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddVerticalLine
https://tlc.thinkorswim.com/center/...aintingStrategy/PaintingStrategy-VALUES-ABOVE
 
Last edited:
Solution

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

this can display a date on a bar, 3 different ways,
bubble (2 versions),
vertical line,
numbers , month above / day below

the font size of the values above/below plot values can't be changed with .SetLineWeight(5).

i moved the arrow up because of the boolean plot number above. i tried to pick factor numbers to get the number, arrow, and bubble stacked and not overlapping most of the time. but some numbers might have to be changed, depending on which output you choose.

replace my 2 averages code with your code that creates the signal.

this took a little longer to do and verify, because you provided partial code. i had to add test code for the signals.


Code:
# show_date_on_signal_00

# https://usethinkscript.com/threads/is-it-possible-to-have-the-date-along-with-the-arrow-when-using-a-study.13745/
# Is it possible to have the date along with the arrow when using a study?

def na = double.nan;
def bn = barnumber();
#def lastbar = !isnan(close[0]) and isnan(close[-1]);

#-----------------------------------
#from tos chat - mobius
def data = getYYYYMMDD();
def year = Round(data/10000, 0);
def month = Round((data % 10000) / 100, 0);
def day = (data % 100);
input test_date = no;
addLabel(test_date, "date: " + month + "/" + day + "/" + AsPrice(year), color.white);


#-----------------------------------
# test signals - 2 avg crossing

def price = close;
input ma1_len = 22;
input ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);

input ma2_len = 44;
input ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

input show_lines = yes;
plot z1 = if show_lines then ma1 else na;
z1.setdefaultcolor(getcolor(1));
z1.hidebubble();
plot z2 = if show_lines then ma2 else na;
z2.setdefaultcolor(getcolor(2));
z2.hidebubble();
#----------------------------------

def condition = ma1 crosses ma2;

#---------------------------------

input arrow_factor = 0.003;
def dwn = if condition then high*(1+arrow_factor) else Double.NaN;
input show_down_arrow = yes;
input arrow_size = 4;
plot result = dwn;
result.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
result.SetLineWeight(arrow_size);
result.AssignValueColor(Color.MAGENTA);

#---------------------------------

# show date on signal bar, in different ways

# bubble
input date_bubble1 = yes;
def vert_factor = 0.001;
#def buby = ( high * (1 + (arrow_size * vert_factor)));
def buby = ( dwn +  (high *((arrow_size * vert_factor))));
addchartbubble(date_bubble1 and dwn, buby, month + "/" + day, color.yellow, yes);

input date_bubble2 = no;
addchartbubble(date_bubble2 and dwn, buby, month + "\n" + day, color.yellow, yes);



# vertical line
input vertical_line_with_date = no;
addverticalline(vertical_line_with_date and dwn,  month + " / " + day, result.takevaluecolor(), curve.SHORT_DASH);
#addverticalline(vertical_line_with_date and dwn,  month + " / " + day +  " / " + AsPrice(year), color.yellow);


# above/below
input date_above_below_candle = yes;
plot dwn_mo = if date_above_below_candle and condition then month else Double.NaN;
dwn_mo.SetPaintingStrategy(PaintingStrategy.values_above);
dwn_mo.AssignValueColor(Color.white);
plot dwn_day = if date_above_below_candle and condition then day else Double.NaN;
dwn_day.SetPaintingStrategy(PaintingStrategy.values_below);
dwn_day.AssignValueColor(Color.white);
#

dGSZq8L.jpg


https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddChartBubble
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddVerticalLine
https://tlc.thinkorswim.com/center/...aintingStrategy/PaintingStrategy-VALUES-ABOVE


Hi,

Thank you for this. I learned a few things. I am just getting around to play around with this code.

I don't quite understand how dnw works in this case despite using it in my code as well (as result)
Does dwn work as a placeholder for location if our condition results in True?

So in this part of the code:

addchartbubble(date_bubble1 and dwn


date_bubble1
needs to be True
dwn
need to just have a non Nan value as that will result in a True as well.

So True and True will equal True.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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