an arrow after close above the previous high

appplejack003

New member
Hi guys,
I'm trying to create an indicator that meets the following criteria but so far it hasn't worked.

Conditions:
1.Current close must be higher than the high of the previous bar.
2.Current close must be higher than the high of any of the last 3 bars.
3.Paint an arrow when these conditions are met.

Nothing happens on my chart and I don't know why.

Here is the code below:


#Declare variables
declare lower;

input numBars = 3;

#Define conditions
def currClose = close;
def prevHigh = high[1];
def pastHigh = highest(high, numBars);

#Paint arrow when conditions are met
plot arrowUp = if currClose > prevHigh and currClose > pastHigh then low - 1 else double.nan;
arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowUp.SetDefaultColor(Color.GREEN);
arrowUp.SetLineWeight(2);


Thanks!
 
Solution
Hi guys,
I'm trying to create an indicator that meets the following criteria but so far it hasn't worked.

Conditions:
1.Current close must be higher than the high of the previous bar.
2.Current close must be higher than the high of any of the last 3 bars.
3.Paint an arrow when these conditions are met.

Nothing happens on my chart and I don't know why.

Here is the code below:


#Declare variables
declare lower;

input numBars = 3;

#Define conditions
def currClose = close;
def prevHigh = high[1];
def pastHigh = highest(high, numBars);

#Paint arrow when conditions are met
plot arrowUp = if currClose > prevHigh and currClose > pastHigh then low - 1 else double.nan;
arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP)...
Hi guys,
I'm trying to create an indicator that meets the following criteria but so far it hasn't worked.

Conditions:
1.Current close must be higher than the high of the previous bar.
2.Current close must be higher than the high of any of the last 3 bars.
3.Paint an arrow when these conditions are met.

Nothing happens on my chart and I don't know why.

Here is the code below:


#Declare variables
declare lower;

input numBars = 3;

#Define conditions
def currClose = close;
def prevHigh = high[1];
def pastHigh = highest(high, numBars);

#Paint arrow when conditions are met
plot arrowUp = if currClose > prevHigh and currClose > pastHigh then low - 1 else double.nan;
arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowUp.SetDefaultColor(Color.GREEN);
arrowUp.SetLineWeight(2);


Thanks!
zoom way out ( click and drag on price axis) and look for arrows near 0 line.

your plot specified a price level, but you used boolean arrows.
remove 'boolean_' from arrow code line

or
change the plot line formula to be of a true/false value

plot arrowUp = if currClose > prevHigh and currClose > pastHigh then 1 else 0;
 
Last edited:
Solution
Hi guys,
I'm trying to create an indicator that meets the following criteria but so far it hasn't worked.

Conditions:
1.Current close must be higher than the high of the previous bar.
2.Current close must be higher than the high of any of the last 3 bars.
3.Paint an arrow when these conditions are met.

Nothing happens on my chart and I don't know why.

Here is the code below:


#Declare variables
declare lower;

input numBars = 3;

#Define conditions
def currClose = close;
def prevHigh = high[1];
def pastHigh = highest(high, numBars);

#Paint arrow when conditions are met
plot arrowUp = if currClose > prevHigh and currClose > pastHigh then low - 1 else double.nan;
arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowUp.SetDefaultColor(Color.GREEN);
arrowUp.SetLineWeight(2);


Thanks!


Applejack,

I worked on the code with and without the corrections suggested above and couldn't get it to work no matter what I did for a couple of minutes. Then I realized that requiring the currClose to be higher than pastHigh involved requiring the current candle's close to be higher than the current candle's high, which is impossible. In addition, since pastHigh is included in prevHigh those two definitions are redundant.

Another thought is that the original code says "declare lower" and I couldn't make an arrow-based indicator work properly in the indicator box below the chart.

I wrote a script that I think meets your requirements. A picture is shown below.

I wanted to make your 3 previous candles definition an input-adjustable number so that, for example, one could easily change it to require a close to be higher than the highs of the past 5 or 10 bars, etc., instead of 3 bars. I think it will be possible by including "displace" in the code appropriately, but I need to do a little more work on it to be sure it's right and that it excludes the high of the current bar. I'm posting the code below because it certainly seems to work correctly.



applejack003-chart-4-1-23.png


Code:
# CloseAbove3Highs
# applejack003 question

#Define conditions
def currClose = close;

#Paint arrow when conditions are met
plot arrowUp = currClose > high[1] and currClose > high[2] and currClose > high[3];

arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowUp.SetDefaultColor(Color.GREEN);
arrowUp.SetLineWeight(2);
 
Okay, this is working. I normally associate the displace command with simply shifting moving averages forwards or backwards by some number of bars on a chart, but it is more useful than I realized.

Here is version 2. The current close can be required to be higher than the highs of any number of previous bars that is desired by changing the input length, and the current bar's high will be excluded from the calculation. I changed the number of previous bar highs from 3 to 10 in the chart below and it changed properly to be different from the chart that was posted earlier.

applejack003-chart-4-1-23-2.png



Code:
# CloseAbove3Highs_v2
# applejack003 question

input length = 3;
input displace = 1;

def currClose = close;

plot arrowUp = currClose > highest(high[displace], length);

arrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowUp.SetDefaultColor(Color.GREEN);
arrowUp.SetLineWeight(2);
 

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