Help with painting on previous candles.

hinkognito

New member
Hello all,

Here is a simple script for finding a high or low based on certain criteria. There are two iterations: one with 2 candles and one with 3 candles.
How can I get it to paint on the first candle?

Thanks!


plot ch1 = if close[1]>open[1] and close<open and close<low[1] then high else double.nan;
plot ch2 = if close[2]>open[2] and close[1]<open[1] and close<low[1] then high else double.nan;


plot cl1 = if close[1]<open[1] and close>open and close>low[1] then low else double.nan;
plot cl2 = if close[2]<open[2] and close[1]>open[1] and close>low[1] then low else double.nan;
 
Solution
Hello all,

Here is a simple script for finding a high or low based on certain criteria. There are two iterations: one with 2 candles and one with 3 candles.
How can I get it to paint on the first candle?

Thanks!


plot ch1 = if close[1]>open[1] and close<open and close<low[1] then high else double.nan;
plot ch2 = if close[2]>open[2] and close[1]<open[1] and close<low[1] then high else double.nan;


plot cl1 = if close[1]<open[1] and close>open and close>low[1] then low else double.nan;
plot cl2 = if close[2]<open[2] and close[1]>open[1] and close>low[1] then low else double.nan;

The plots of the dots and count can be hidden. The dots denote ch1/ch2 and cl1/cl2. There are 2 scripts for clarity, with one for the highs...
Hello all,

Here is a simple script for finding a high or low based on certain criteria. There are two iterations: one with 2 candles and one with 3 candles.
How can I get it to paint on the first candle?

Thanks!


plot ch1 = if close[1]>open[1] and close<open and close<low[1] then high else double.nan;
plot ch2 = if close[2]>open[2] and close[1]<open[1] and close<low[1] then high else double.nan;


plot cl1 = if close[1]<open[1] and close>open and close>low[1] then low else double.nan;
plot cl2 = if close[2]<open[2] and close[1]>open[1] and close>low[1] then low else double.nan;

The plots of the dots and count can be hidden. The dots denote ch1/ch2 and cl1/cl2. There are 2 scripts for clarity, with one for the highs and the other the lows.

The logic currently starts the count for lows at cll and continues the count if cl1 or cl2 are true until cl1 and cl2 are not true. The count logic is similar for the highs.

A yellow arrow will appear for a count of 2 consecutive and the yellow arrow created at the 2 count will be replaced with a magenta arrow for 3 consecutive count of the highs/lows.


Code:
input hide_plots = no;
input hide_count = no;

plot ch1 = if close[1] > open[1] and close < open and close < low[1] then high else Double.NaN;
plot ch2 = if close[2] > open[2] and close[1] < open[1] and close < low[1] then high else Double.NaN;
ch1.SetHiding(hide_plots);
ch2.SetHiding(hide_plots);
ch1.SetPaintingStrategy(PaintingStrategy.POINTS);
ch2.SetPaintingStrategy(PaintingStrategy.POINTS);
ch1.SetDefaultColor(Color.CYAN);
ch2.SetDefaultColor(Color.WHITE);

def count = if (count[1]) == 0 and !IsNaN(ch1) then 1 else if count[1] >= 1 and (!IsNaN(ch1) or !IsNaN(ch2)) then count[1] + 1 else if IsNaN(ch1) and IsNaN(ch2) then 0 else count[1];
plot countconsecutive = count;
countconsecutive.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
countconsecutive.SetDefaultColor(Color.WHITE);
countconsecutive.SetHiding(hide_count);

plot x1of3 = if count == 1 and count[-1] > 1 and count[-2] > 1 then high else Double.NaN;
x1of3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
x1of3.SetDefaultColor(Color.MAGENTA);
x1of3.SetLineWeight(5);

plot x1of2 = if count == 1 and (count[-1] > 1 or count[-1] > 1) then high else Double.NaN;
x1of2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
x1of2.SetDefaultColor(Color.YELLOW);
x1of2.SetLineWeight(4);

Code:
input hide_plots = no;
input hide_count = no;

plot cl1 = if close[1] < open[1] and close > open and close > low[1] then low else Double.NaN;
plot cl2 = if close[2] < open[2] and close[1] > open[1] and close > low[1] then low else Double.NaN;
cl1.SetHiding(hide_plots);
cl2.SetHiding(hide_plots);
cl1.SetPaintingStrategy(PaintingStrategy.POINTS);
cl2.SetPaintingStrategy(PaintingStrategy.POINTS);
cl1.SetDefaultColor(Color.CYAN);
cl2.SetDefaultColor(Color.WHITE);

def count = if (count[1]) == 0 and !IsNaN(cl1) then 1 else if count[1] >= 1 and (!IsNaN(cl1) or !IsNaN(cl2)) then count[1] + 1 else if IsNaN(cl1) and IsNaN(cl2) then 0 else count[1];
plot countconsecutive = count;
countconsecutive.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
countconsecutive.SetDefaultColor(Color.WHITE);
countconsecutive.SetHiding(hide_count);

plot x1of3 = if count == 1 and count[-1] > 1 and count[-2] > 1 then low else Double.NaN;
x1of3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
x1of3.SetDefaultColor(Color.MAGENTA);
x1of3.SetLineWeight(5);

plot x1of2 = if count == 1 and (count[-1] > 1 or count[-1] > 1) then low else Double.NaN;
x1of2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
x1of2.SetDefaultColor(Color.YELLOW);
x1of2.SetLineWeight(4);

Screenshot 2023-12-25 161644.png
 
Solution

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

The plots of the dots and count can be hidden. The dots denote ch1/ch2 and cl1/cl2. There are 2 scripts for clarity, with one for the highs and the other the lows.

The logic currently starts the count for lows at cll and continues the count if cl1 or cl2 are true until cl1 and cl2 are not true. The count logic is similar for the highs.

A yellow arrow will appear for a count of 2 consecutive and the yellow arrow created at the 2 count will be replaced with a magenta arrow for 3 consecutive count of the highs/lows.
Thank you for the help. Appreciate you taking the time!
Will give this a shot.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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