Daily bar stays above after previous day crossover


Category:
0
0

Hi Pete,

I would like to add a rule to this watchlist code:

Colour the watchlist with if then

If the daily bar stays above/below the previous day cross over it turns purple for staying above and Yellow if it stays below.

Thank you so much for your help.

Frank

— This is the skeleton logic I have added as comments:

def clsAbove = SimpleMovingAvg(“length” = 22).”SMA” crosses below close;
def clsBelow = SimpleMovingAvg(“length” = 22).”SMA” crosses above close;
# def closeAboveSignal = crossed 22dma yesterday and still above the 22SMA
# def closeBelowSignal = crossed 22DMA yesterday and still above the 22SMA
declare once_per_bar;
#main code
plot signal = clsAbove or clsBelow ;
AssignBackgroundColor(if clsAbove > clsBelow then Color.UPTICK else if clsAbove < clsBelow then Color.DOWNTICK else Color.GRAY);

Marked as spam
Posted by (Questions: 4, Answers: 5)
Asked on January 25, 2021 7:21 pm
73 views
0
Private answer

I think we need to examine your request a bit closer.

stays above/below the previous day cross over

A crossover is an event. A crossover does not have any value accept true or false. It is therefore not possible for price to "above a crossover event". So you need to explain the missing component. Exactly what determines this value that the price needs to remain above or below in order to set the color to purple or yellow? HINT: At the point of the crossover event, that bar contains 5 data points:

  1. Open
  2. High
  3. Low
  4. Close
  5. Moving average

Once we understand which of these data points you intend to use we can attempt to solve this. This implies that at the crossover event there is a fixed value that is set and held for subsequent bars until the next crossover event occurs. The code would then use this fixed data point as the comparison for "remains above" or "remains below".

Depending on your response, the request may turn out to me more complex than I can solve in the limited amount of time I allow for free solutions in the Q&A Forum.

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on January 26, 2021 11:12 am
0
Hi Pete it's based on Price (close of high or low), so if the next day price is still above the 22DMA (optional: at time) it turns purple or yellow depending on the high vs low. The caveat is that it only calculates this price if the previous day's price closed above/below the 22dma. If it more than one bar away the scan is ignored altogether. This only scans on the DAILY charts and no other time frame are used. I hope this helps clarify it a bit. Frank
( at January 27, 2021 9:40 am)
0
Scan??? Now I am even more lost. This request is for a custom watchlist column and not a scan. I still don't have enough detail to do anything with this. And it is sounding more and more like this is going to take much longer time than I can afford to spend on a free solution in the Q&A Forum. Sorry but you did not clarify things at all, but have only added to the list of unknown elements that you have not yet found a way to describe.
( at January 27, 2021 11:44 am)