@Kellyd I'm glad you are finding the code useful... I will give a short review regarding scans...
Some scan code can actually be saved as a Study and then referenced from within the Stock/Option Scan Hacker... The scan code for Heikin_Ashi_Trend_Dots_Scan happens to be one of those... Other code does not cooperate when it comes to saving as a study and must be coded in its entirety within the Stock/Option Scan Hacker...
This scan, being fairly short compared to some, I chose to post the initial code for direct Copy & Paste into the scanner... Therefore, to switch from a scan for Longs to a scan for Shorts requires simple editing... The following plot lines are the ones that require the edits... I'll show both snippets here for clarity... Note the change of location of the hashtag between the Long and Short scans...
Long Trend Scan
Ruby:
# Long trend transition
plot long = haSignal[1] == 0 and haSignal == 1;
# Short trend transition
#plot short = haSignal[1] == 0 and haSignal == -1;
Short Trend Scan
Ruby:
# Long trend transition
#plot long = haSignal[1] == 0 and haSignal == 1;
# Short trend transition
plot short = haSignal[1] == 0 and haSignal == -1;
Now that we have that out of the way I'll cover saving the code as a Study and then referencing the Study from within a Scan... The code below should be saved using the name at the top of the script, minus the leading hashtag and blank space...
Ruby:
# Heikin_Ashi_Trend_Dots_Scan
# Finds potential trend reversals based on Heikin Ashi trend transition direction.
# Created by rad14733 for usethinkscript.com
# v1.0 : 2021-08-13 : Initial release
def haClose = ohlc4;
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
if haTrendUp == 1 and haTrendUp[1] == 1 then 1
else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
else 0
;
# NOTE: ONLY ONE PLOT ALLOWED PER SCAN.
# Comment out the unwanted plot and Un-Comment the desired plot
# Long trend transition
plot long = haSignal[1] == 0 and haSignal == 1;
# Short trend transition
plot short = haSignal[1] == 0 and haSignal == -1;
# END - Heikin_Ashi_Trend_Dots_Scan
As you can see, both plots are active which is not allowed directly within the scanner which only allows a single active plot
per scan filter... But we can reference the Study and desired plot from within the Stock Scan Hacker, or even both if we create two separate scan filters - one for Longs and on for Shorts... Trust me, once you get the hang of the Scan Hackers it'll make sense...
The image below shows how you would reference the Study and select the Long plot for scanning...
The next image shows how you would reference the Study and select the Long plot for scanning...
And, finally, this last image shows how you can reference the Study to scan for both Long and Short triggers...
What you see above is two resulting scan conditions within a single filter, which works because we switch the default
Check if all of the following conditions are met to
any... This is how I scan because I want to see both Long and Short trend reversal signals that I then check on my chart...
Hopefully this makes some sense to you... If not, voice any further concerns and I'll do my best to help further... I probably covered a lot of ground in this post but if you play around you can't break anything by experimenting...