define a desired painting strategy with a number , or an input

halcyonguy

Moderator - Expert
VIP
Lifetime
it is possible to use numbers to define a desired painting strategy, instead of the words listed here.
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/PaintingStrategy

can use this
. z2.SetPaintingStrategy(2);
instead of this
. z2.SetPaintingStrategy(PaintingStrategy.POINTS);

but i think the number has to be a constant. the number can't come from a formula.


this study plots out all 20 strategies, on the first 80 bars on the chart. ( 0 - 19 )

boolean strategy plots are plotted at the chart symbol price levels, even if the candles are turned off, and even if a different symbol is specified in a close().
so pick a stock with a price around $2, to better see the boolean plots.
like SNDL


this turns off the main chart candles with this,
input HidePrice = yes;
HidePricePlot(HidePrice);

------------------

it is also possible to choose a strategy based on an input and an if then.
look below, after the image for an example.


Code:
# template_plot_strategy_numbers_00

def na = double.nan;
def bn = barnumber();

# turn off price bars
input HidePrice = yes;
HidePricePlot(HidePrice);


# cnt by x group of numbers
input seq_qty = 4;
def seq_num = floor((bn-1) / seq_qty)+0;
def iseven = (seq_num % 2 == 0);

input p = 1.2;
plot zz = 0;
# can't spec a price level for booleans
#input sym1 = "SNDL";
#plot x = close(sym1);
plot x = close;
input size = 2;
def maxn = 19;
def groupfirst = if bn == 1 then 1
  else if seq_num > maxn then 0
  else if seq_num != seq_num[1] then seq_num
  else 0;

addchartbubble(groupfirst, p+0.5,
seq_num
, (if iseven then color.yellow else color.gray), yes);

#-----------------------------
# 0 LINE
plot z0 = if seq_num == 0 then p else na;
z0.SetPaintingStrategy(0);
z0.setlineweight(size);
#z0.SetPaintingStrategy(PaintingStrategy.LINE);

# 1 HISTOGRAM
plot z1 = if seq_num == 1 then p else na;
z1.SetPaintingStrategy(1);
z1.setlineweight(size);
#z1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

# 2 POINTS
plot z2 = if seq_num == 2 then p else na;
z2.SetPaintingStrategy(2);
z2.setlineweight(size);
#z2.SetPaintingStrategy(PaintingStrategy.POINTS);

# 3 LINE_VS_POINTS
plot z3 = if seq_num == 3 then p else na;
z3.SetPaintingStrategy(3);
# error, only constants
#z3.SetPaintingStrategy(seq_num);
z3.setlineweight(size);
#z3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

# 4 LINE_VS_SQUARES
plot z4 = if seq_num == 4 then p else na;
z4.SetPaintingStrategy(4);
z4.setlineweight(size);
#z4.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);

# 5 LINE_VS_TRIANGLES
plot z5 = if seq_num == 5 then p else na;
z5.SetPaintingStrategy(5);
z5.setlineweight(size);
#z5.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);

# 6 ARROW_DOWN
plot z6 = if seq_num == 6 then p else na;
z6.SetPaintingStrategy(6);
z6.setlineweight(size);
#z6.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# 7 ARROW_UP
plot z7 = if seq_num == 7 then p else na;
z7.SetPaintingStrategy(7);
z7.setlineweight(size);
#z7.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

# 8 BOOLEAN_POINTS
plot z8 = if seq_num == 8 then p else na;
z8.SetPaintingStrategy(8);
z8.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);

# 9 BOOLEAN_ARROW_DOWN
plot z9 = if seq_num == 9 then p else na;
z9.SetPaintingStrategy(9);
z9.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# 10 BOOLEAN_ARROW_UP
plot z10 = if seq_num == 10 then p else na;
z10.SetPaintingStrategy(10);
z10.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

# 11 DASHES
plot z11 = if seq_num == 11 then p else na;
z11.SetPaintingStrategy(11);
z11.setlineweight(size);
#z11.SetPaintingStrategy(PaintingStrategy.DASHES);

# 12 HORIZONTAL
plot z12 = if seq_num == 12 then p else na;
z12.SetPaintingStrategy(12);
z12.setlineweight(size);
#z12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# 13 VALUES_ABOVE
plot z13 = if seq_num == 13 then p else na;
z13.SetPaintingStrategy(13);
z13.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);  

# 14 VALUES_below
plot z14 = if seq_num == 14 then p else na;
z14.SetPaintingStrategy(14);
z14.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.VALUES_below); 

# TRIANGLES
plot z15 = if seq_num == 15 then p else na;
z15.SetPaintingStrategy(15);
z15.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

# SQUARES
plot z16 = if seq_num == 16 then p else na;
z16.SetPaintingStrategy(16);
z16.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.SQUARES);

# 17 SQUARED_HISTOGRAM
plot z17 = if seq_num == 17 then p else na;
z17.SetPaintingStrategy(17);
z17.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

# 18 BOOLEAN_WEDGE_DOWN
plot z18 = if seq_num == 18 then p else na;
z18.SetPaintingStrategy(18);
z18.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

# 19 BOOLEAN_WEDGE_up
plot z19 = if seq_num == 19 then p else na;
z19.SetPaintingStrategy(19);
z19.setlineweight(size);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);

#------------------------------
#x.SetDefaultColor(Color.red);
#x.hidebubble();

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

#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
#x.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);

#setlineweight() has no effect on values_above/ below
#x.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);  
#x.SetPaintingStrategy(PaintingStrategy.VALUES_below); 

#x.SetPaintingStrategy(PaintingStrategy.LINE);
#x.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
#x.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
#x.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
#x.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

#x.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

#  Strategy.DASHES: 1 dash per candle, no matter the zoom level
#x.SetPaintingStrategy(PaintingStrategy.DASHES);
#x.SetPaintingStrategy(PaintingStrategy.POINTS);
#x.SetPaintingStrategy(PaintingStrategy.SQUARES);
#x.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
#x.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#x.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

#x.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#x.SetStyle(Curve.MEDIUM_DASH);
#x.SetDefaultColor(Color.red);
#x.setlineweight(1);
#x.hidebubble();
#

SNDL
3wRwTKM.jpg


---------------------------


you can use an if then to choose a strategy.
the output of this, is at the bottom of the image, the 20 shapes at -1.


Code:
def v = -1;
 input line_type = {"invisible", "dots", default "dashes", "solid"};
# this works , but the PaintingStrategy.dashes  line looks like a solid line when zoomed out
# --------------------
input test_price_line1 = yes;
#plot line1x = if ( test_price_line1 and (crslin == 2 or crslin == 3 or crslin == 4)) then line1 else na;
plot line1x = if (test_price_line1 and bn < 20) then v else na;
line1x.SetDefaultColor(Color.LIGHT_GREEN);
line1x.HideBubble();
line1x.SetPaintingStrategy(if line_type == line_type."dots" then PaintingStrategy.points
  else if line_type == line_type."dashes" then PaintingStrategy.dashes
  else if line_type == line_type."solid" then PaintingStrategy.line
  else PaintingStrategy.squares);
# -------------------

addchartbubble(bn == 1, v,
line_type
, color.yellow, no);

ref,
https://usethinkscript.com/threads/...remove-it-once-price-hits-it.5257/#post-75706
notes at the end of the study
 

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