Troubleshoot percent change signal


Category:
0
0

Hello Pete,

I have made a scanner in 4 hour aggregation based of heiken-aishi candles. To see if my scan works , I have defined an “alert” based of my study. The definition I used in heiken-aishi is as follows,

” def haClose_4h = (open(period=aggregationPeriod.FOUR_HOURS) + high(period=aggregationPeriod.FOUR_HOURS) + low(period=aggregationPeriod.FOUR_HOURS) + close(period=aggregationPeriod.FOUR_HOURS))/4 ;”

the signal that I intend to get is ,

plot signal = haClose_4h[0]>1.03*haClose_4h[1] ;

signal.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
signal.setdefaultColor(color.PLUM);
alert( signal, “Alert !!!”, alert.bar,sound.Ding); “

What I saw today (11/22/22) for a stock tickr “FENC” was it did not consider the 5:00 am candle in the 4 hour chart for running the condition at 9:30 am. I have attached the 4 hr and 1 min chart (with the alert) for reference.  Please help as where did I do wrong which caused not to capture the 5:00 am candle.

Thank you

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 23, 2022 9:05 am
42 views
0
Private answer

Your example code is not a scan, this is a chart study. So I moved your question out of the "Stock Scanners" topic and into the "Chart Studies" topic. I also updated the title of your question to reflect the context of your request.

You are wondering why your code did not trigger a signal at the 5 am bar of FENC. The answer is simple, that bar does not qualify as a valid signal. How can we know this for certain? How can we make that easier to see on the chart. That is my solution.

First thing to note. We do not need to use any of the secondary aggregation periods to plot this on a 4 hour chart. So I removed those entirely. And I removed the alert from this code to keep things simple. I then added an additional plot which displays the value your signal is based on, and displays that value above each bar of the chart.

This is just a diagnostic tool which is used to show what your code is doing:

def haClose = (open + high + low + close)/4 ;
plot signal = haClose[0] > 1.03 * haClose[1];
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.SetLineWeight(3);
signal.SetDefaultColor(Color.CYAN);
def percentDiff = 100 * (haClose / haClose[1] - 1);
plot test1 = percentDiff;
test1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
test1.SetDefaultColor(Color.WHITE);

Screenshot below shows this code plotted on a 4 hour chart of FENC as you described. Comments and drawings have been added to explain why the 5 am bar is not triggering your signal. The value is less than 3%, and your signal requires it be greater than 3%.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 23, 2022 12:25 pm