Plot first candle crosses prev week high.


Category:
0
0

I’m basically looking to put a white arrow on my daily chart where the high of the first candle passes the previous week high.  THis study doesn’t work the way I expected as it’s placing a arrow under every candle.

#
input aggregationPeriod = AggregationPeriod.WEEK;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
def PrevDayClose = Highest(high(period = aggregationPeriod)[-displace], length);

plot did = PrevDayClose;
did.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
did.SetLineWeight(3);
did.AssignValueColor(Color.WHITE);

Marked as spam
Posted by (Questions: 10, Answers: 15)
Asked on January 8, 2022 1:54 pm
186 views
0
Private answer

The code you provided could not be salvaged so I started from scratch.

I had to make some assumptions to fill in details you did not include.

  1. The code will plot the previous weekly high so you can see it on the chart. Turn that plot off once it is no longer needed.
  2. Signals are set to occur only on the very first cross above the previous week high. This may occur on the first bar of the new week or any bar that comes after.
  3. The qualification for a a valid signal is based on the high of the first bar that crosses the previous week high.
  4. Some may choose to select the first bar that closes above the previous week high but this code does not perform that way.
  5. This code will work on any time based intraday time frame.

Here it is:

plot previousWeekHigh = high(period = AggregationPeriod.WEEK)[1];
def newWeek = GetWeek() <> GetWeek()[1];
rec firstCrossAbove = if newWeek and high < previousWeekHigh then 0 else if high > previousWeekHigh then 1 else firstCrossAbove[1];
plot crossingWeeklyHigh = firstCrossAbove and !firstCrossAbove[1];
crossingWeeklyHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossingWeeklyHigh.SetLineWeight(3);
crossingWeeklyHigh.AssignValueColor(Color.WHITE);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 9, 2022 9:46 am