Midpoint of previous day close to high of day


Category:
0
0

Hello Pete,

I need help creating a simple chart label

  1. Condition 1 find % change from yesterdays close to todays high (include premarket)
  2. Calculate the mean  ((yesterdays close+todays high)/2))
  3. Find the % change from todays high of day to the mean.
  4. Plot step 3 as a chart label in %

Your help on this is much appreciated, I can do this on a calculator, but having TOS do it will save lots of time

Marked as spam
Posted by (Questions: 3, Answers: 3)
Asked on August 21, 2022 3:45 pm
64 views
0
Private answer

I updated the title of the question in the hopes it will make it easier for folks searching for this solution to find it. I was not able to include the full context of the request within the title without using 9 words or less. But I think I captured the main context of the request.

The following code will display both the high of day as well as the previous day close on the chart. And the label will show the percent change from the high of day to the midpoint. In cases where the high of day is less than previous day close, the label will display a positive value. Negative values display when the high of day is greater than greater than the previous day close.

def newDay = GetDay() <> GetDay()[1];
rec highOfDay = if newDay then high else if high > highOfDay[1] then high else highOfDay[1];
def previousClose = close(period = AggregationPeriod.DAY)[1];
plot intradayHigh = highOfDay;
intradayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot midpoint = previousClose + ((highOfDay - previousClose) / 2);
midpoint.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
def percentDifference = Round(100 * (midpoint / highOfDay - 1), 1);
AddLabel(yes, Concat("Percent Difference: ", percentDifference), Color.WHITE);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 21, 2022 5:16 pm
0
WOW this is amazing. Now how do I display this value as a "%"
( at August 21, 2022 6:03 pm)
0
I dont think code is factoring premarket highs exmaple $LODE 2/17/21
( at August 21, 2022 6:13 pm)
0
Premarket highs will only be included if you include extended hours on the chart. The value displayed has already been converted from a decimal to a percentage value.
( at August 21, 2022 6:52 pm)