Scan for close crossing above LinearRegCurve


Category:
0
0

Pete,

I have a scan using some custom code which is not triggering as expected. Please see below:

input lnrLength = 40;
plot lnrReg = LinearRegCurve(0, lnrLength, Close);
def stkATR = ATR(14);

def myLevel = lnrReg + (2 * stkATR);

def signalAbove = Close crosses above myLevel;
plot scan = signalAbove;

I have set this scan against a custom watchlist and it sends an alert every time a stock in my list meets this criteria. The code is set at the hourly level. However, I get the alert even before the hourly candle has closed.

What is the appropriate way to handle this so that I get the alert only if the Close crossed above this line after the candle has closed.

Regards

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on December 7, 2022 4:28 pm
85 views
0
Private answer

In order to modify the scan so it waits for the bar to close you just need to update the last line as follows:

plot scan = signalAbove[1];

If you are using intraday time frames you need to do one of two things:

  1. Set the chart and scan to include extended hours session
  2. If you don't want to use extended hours session then you will need to update your chart settings and turn off the following: Settings --> Equities --> Start aggregations at market open
Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on December 7, 2022 5:25 pm
0
Thanks Pete. I enabled the scan but I am seeing some inconsistencies. Attached is a screenshot. As per the scan, the alert was generated at 12:32 for CAT. However when I went to the chart for CAT, I see that the price has not crossed the line (Gray line is the code for what I have used in the scan) Is there a setting I am missing? Regards
( at December 8, 2022 11:00 am)
0
Apologies. I found out that alert had a length of 5 and chart has length of 7
( at December 8, 2022 11:02 am)