♥ 0 |
I have the code for a study/scan that will plot/find N bar highs/lows. It works well for plotting/finding instruments that have a N bar high/low in the last N bars. I can’t figure out how to modify the code to find the FIRST N bar high/low (in the last N bars). This would be useful for finding trend changes. At a high level I think the code would plot/find a N bar high/low (N bar high/low is true) in the last N bars and then look back several more bars (adjustable number?) to ensure there were no preceding N bar highs/lows. input nbar = 20; RESOLVED
Marked as spam
|
Private answer
The code you provided does not do this. Let me see if I have this correct. For n bars == 20. You want to find the highest bar in the previous 20, but you need there to be no “highest bar in 20”, within the previous 20 bars? If that is correct, the change you will make to the plot scan statement is as follows:
I will explain. We signal on a new highest close in x bars. We add to that a test to see if there has been any highest close in x bars in the previous x bars (excluding the current bar). Marked as spam
|
|
Private answer
If you want to run a scan to find stocks that have the highest close in x number of bars the solution is very simple. I won’t bother trying to figure out how to get your code to do it. However I will mention that your code looks for highest close in x bars and lowest close in x bars. It does not look for highest high or lowest low.
You should know this is very similar to a Donchian Channel. You may also find similar material posted here: https://www.hahn-tech.com/ans/donchian-long-entry-alert/ and here: https://www.hahn-tech.com/ans/dong-chian-channel-scan/
Marked as spam
|
Please log in to post questions.
Yeah, I can see how you might think that is correct. But this shows that you really don’t understand what is taking place for that second test. If you care to understand, I’ll try to provide more detail. If you only want the lowest scan to work, then use this:
plot scan = lowestCloseInXBars and Highest(lowestCloseInXBars[1], xBars) < 1;
Tip: the variable, lowestCloseInXBars is either true or false. In thinkscript, true == 1 and false == 0. So for every true/false statement we always evaluate to either a 1 or a 0. So we just check to see if that variable has remained below 1 (true) for the length of xBars. Stated another way. The highest true/false value in xBars is less than 1 (true).
“plot scan = lowestCloseInXBars and Highest(lowestCloseInXBars[1], xBars) < 1;" works great. Thank you for explaining!