Scan For Price Within A Percentage Of Moving Average
Copy the above code
In Studies, click Create
Paste the above study
Name the study: Pct_From_MA
Save
Click on the scanner.
Where price is below ma
Where price is rising (hl2 is greater than hl2 from 1 bars ago)
Where price is within -2% of the ma
Remember: Change the aggregation of each filter to what you want
Here is a Shared Link: http://tos.mx/kXoe4Db
The shared link will only work if you copy and pasted the above study and named it: Pct_From_MA
A poster was having difficulty scanning for within a percentage of ma so I wrote this brief tutorial. I don't use moving average studies so I can not assist w/ how people are utilizing this in their strategies.
- Where price is below 100 ma
- Where price is rising (hl2 is greater than hl2 from 1 bars ago)
- Where price is within -2% of the 100 ma
Ruby:
# MA Distance Percentage
# Paris
# 4.13.2018
# Computes percentage the current close is above/below the 200 DSMA
# Displays on a lower chart
declare lower;
input length = 200;
def data = close;
def avg = Average(data, length);
def pct = (data/avg) - 1;
plot dist = pct;
plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.SetLineWeight(2);
AddLabel(1, "Percentage from " + length + " MA: " + AsPercent(pct), if pct > 0 then Color.GREEN else Color.PINK);
In Studies, click Create
Paste the above study
Name the study: Pct_From_MA
Save
Click on the scanner.
Where price is below ma
- Click on +Add filter
- Click on the pencil icon next to the filter you just added
- Click edit
- In the left column, click on the 1st pull-down window, click study
- Type in Pct_From_MA
- Under Plot, click on the pull-down window, choose dist
- In length change the 200 ma length to 100 ma length .... (or whatever moving average length that you want)
- In the middle column, choose Less than or equal to .... (if scanning for above ma change this to Greater than)
- In the right column, click on the pull-down window, click value
- Change 100 in the next box to 0
- Save
Where price is rising (hl2 is greater than hl2 from 1 bars ago)
- Click on +Add filter
- Click on the pencil icon next to the filter you just added
- Click edit
- In the left column, click on the 1st pull-down window, click price
- Click hl2 .... (or what ever representation of price that floats your boat)
- In the middle column, choose greater than or equal to
- In the right column, click on the pull-down window, click price
- Click hl2 .... (or what ever representation of price that floats your boat)
- In the box under hl2, change the 0 to 1 offset
- Save
Where price is within -2% of the ma
- Click on +Add filter
- Click on the pencil icon next to the filter you just added
- Click edit
- In the left column, click on the 1st pull-down window, click study
- Type in Pct_From_MA
- Under Plot, click on the pull-down window, choose dist
- In length change the 200 ma length to 100 ma length .... (or whatever moving average length that you want)
- In the middle column, choose greater than or equal to .... (or Less than if scanning for above ma)
- In the right column, click on the pull-down window, click value
- In the box under value, change the value from 100 to -0.02 .... (negative values represent under ma; positive values for above ma)
- Save .... (change the percentage to anything you want)
Remember: Change the aggregation of each filter to what you want
Here is a Shared Link: http://tos.mx/kXoe4Db
The shared link will only work if you copy and pasted the above study and named it: Pct_From_MA
A poster was having difficulty scanning for within a percentage of ma so I wrote this brief tutorial. I don't use moving average studies so I can not assist w/ how people are utilizing this in their strategies.
Last edited: