Scan Code Request

4TOS

New member
Hello All,
First post/request since joining. I have spent hours both seaching here and elsewhere trying to find a code/script to suit my needs and thoughts. I have even tried to change other scripts that seemed close with no sucess. So if it already exsist, it wont be because lack of effort,so here we go.
Wherever "X" is ; Im hoping I can just input that value as needed.

*Minimum price at close is X and max price at close is X
Price of above X is X % above the current years low, within X amount of trading days
Minimum daily volume is X
Current volume is X % above X minimum daily volume
In spoken terms: Looking for stocks that have risen above their yearly lows by X % over a specified timeframe (Trading Days). Also has a X % of volume over the minimum daily volume specified.
Theory is to find stock that are rising off their lows but not to the point of missing the early trend upward. Then look track for those stocks for the start of a developing Wave 1 or the turning down into Wave 2 of the Elliott Wave Theory. Then if all goes as plan be ready for Wave 3 and impliment the Fibonachi Ration for conformation, stop loss, and exit strategy. If this is either already available as a script, or is easily accessible by just building it with whats already available on TOS; I apologize in advance. Thannks for reading.
 
Solution
In spoken terms: Looking for stocks that have risen above their yearly lows by X % over a specified timeframe (Trading Days). Also has a X % of volume over the minimum daily volume specified.

this is a lower study

i don't scan. but if i did, i would create a lower study like this first, to test the input signals, on several stocks.
with a scan code, it is hard to test, to verify. i guess you could enable 1 rule at a time and see if it works, then combine the rules.

experiment with this, to see if it what you want.
when you find settings that seem to work, change the variable values in the code.

to make a scan code, copy the code and paste it in as a scan code.
then look at about 60% through the code and change 1 line and...
In spoken terms: Looking for stocks that have risen above their yearly lows by X % over a specified timeframe (Trading Days). Also has a X % of volume over the minimum daily volume specified.

this is a lower study

i don't scan. but if i did, i would create a lower study like this first, to test the input signals, on several stocks.
with a scan code, it is hard to test, to verify. i guess you could enable 1 rule at a time and see if it works, then combine the rules.

experiment with this, to see if it what you want.
when you find settings that seem to work, change the variable values in the code.

to make a scan code, copy the code and paste it in as a scan code.
then look at about 60% through the code and change 1 line and delete everything after it.
there are comments in the code to tell you what to do.
i'm not sure if the first line, declare lower; has to be disabled , to work as a scan.


this shows,
. the 2 output pulse signals above the zero line.
. the 4 inputs pulse signals below the zero line.

output2 , true if output1 was true within x bars , 10
output1 , true when the 4 inputs are true

rule #1 price range
rule #2 price rise > x %
rule #3 price rise within x days
rule #4 vol gain


Ruby:
# lower_scan_within_x_per_0

# https://usethinkscript.com/threads/scan-code-request.10682/

declare lower;

def bn = barnumber();
def na = double.nan;

# ---------------------------------
# rule #1 price

input price_min = 10;
input price_max = 200;

def isprice = if (close > price_min and close < price_max) then 1 else 0;

#at close is X and max price at close is X
#Price of above X is X % above the current years low, within X amount of trading days
#Minimum daily volume is X
#Current volume is X % above X minimum daily volume

#=========================================
# rule #2 price rise x %

#have risen above their yearly lows by X %
def days = 252;
def err1 = if isnan(close[-days]) then 1 else 0;

# look at future bars to find the lowest price
def yearly_lo =
  if err1 then yearly_lo[1]
  else lowest(low[-(252-1)], 252);

def lowestbn = if yearly_lo == low then bn else lowestbn[1];
def lowestlo = if bn == 1 then na else if lowestbn == bn then low else lowestlo[1];


def lodiff = close - lowestlo;
def riseper = round((lodiff/lowestlo)*100,1);

input mingainperfromlowest = 3.0;
def minper = mingainperfromlowest;

def isup_per = if riseper > minper then 1 else 0;

# =============================
# rule #3 price rise within x days

#over a specified timeframe (Trading Days).  max

input max_days_to_rise = 90;
def mdr = max_days_to_rise;

def barsafterlo = bn - lowestbn;
def isdays = if barsafterlo <= mdr then 1 else 0;

# ==============================
# rule #4 vol gain

# has  X % of volume gain over the minimum daily volume specified.

# vol in millions
input min_day_vol_mil = 1.1;
input vol_gain_per = 50;
def minvol = (min_day_vol_mil * 1000000) * ( 1 + (vol_gain_per/100));
def isvol = if volume > minvol then 1 else 0;


# ============================================
# ============================================
# ============================================

def output1 = isprice and isup_per and isdays and isvol;

#----------------------------
# an output trigger within x bars

input output_within_x_bars = 10;
def output2 = sum(output1,output_within_x_bars) > 0;

#----------------------------



# =============================
# output - scan output-------------

#  enable this line if this code is copied to a scan study
# plot zo2 = output2;


# ====================================
# ====================================
# ====================================
# ====================================

#   if this code is copied to a scan study,
#   delete everything after this line


# outputs - lower study ------------------
# plot signal pulses
plot zo2 = output2+3;
zo2.setdefaultcolor(color.yellow);

# ------------------------

plot zo1 = output1+1;
zo1.setdefaultcolor(color.yellow);

# inputs-------------------
plot z1 = isprice-2;
plot z2 = isup_per-4;
plot z3 = isdays-6;
plot z4 = isvol-8;

# ----------------------------
# lines

# valid bars
def xx = if !isnan(close) then 1 else 0;

plot z = if xx then 0 else na;
z.setdefaultcolor(color.cyan);
z.setlineweight(3);

plot zh = if xx then 2.50 else na;
zh.setdefaultcolor(color.gray);

plot za = if xx then -2.50 else na;
plot zb = if xx then -4.50 else na;
plot zc = if xx then -6.50 else na;
plot zd = if xx then -8.50 else na;

za.setdefaultcolor(color.gray);
zb.setdefaultcolor(color.gray);
zc.setdefaultcolor(color.gray);
zd.setdefaultcolor(color.gray);

# -------------------------------

# bubbles
input buboff = 10;
def bubx = ( !isnan(close[buboff]) and isnan(close[buboff-1]));

input bubbles2 = yes;
addchartbubble(bubbles2 and bubx, 2.5, "output2 = out1 within " + output_within_x_bars + " bars", color.yellow, yes);
addchartbubble(bubbles2 and bubx, 0.5, "output1", color.yellow, yes);

addchartbubble(bubbles2 and bubx, za[buboff], "isprice", color.cyan, yes);
addchartbubble(bubbles2 and bubx, zb[buboff], "isup", color.cyan, yes);
addchartbubble(bubbles2 and bubx, zc[buboff], "isdays", color.cyan, yes);
addchartbubble(bubbles2 and bubx, zd[buboff], "isvol", color.cyan, yes);

# ==========================
#  test stuff

input test1_vert_low_lines = yes;
addverticalline( test1_vert_low_lines and lowestbn == bn, "year low", color.cyan);

addchartbubble(0,0,
 bn + "\n" +
 yearly_lo + " lo\n" +
 lowestbn + " bn\n" +
 lowestlo + "lo"
, color.yellow, yes);
#


PM 3yr Day chart
l4rE6k7.jpg
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thanks much halcyonguy!!
I will try it over the weekend the way you suggest for both the study and scan. Will report back. Appreciate it.
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
300 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top