Scan for SMA and StochasticFull?


Category:
0
0

Hi Pete,

Please help to set up scan for these conditions:

Scan for Buy
1) Price crosses above SMA 50 (must be a fresh cross)
2) StochasticFull (k period=8; d period=3) – k period must be below 40 at least; k period increases 5 points from the lowest point (i.e. k period at 10 and then move up to 15).

Scan for Sell
1) Price crosses below SMA 50 (must be a fresh cross)
2) StochasticFull (k period=8; d period=3) – k period must be higher than 60 at least; k period decreases 5 points from the highest point (i.e. k period at 90 and then move down to 85).

Thank you!

Marked as spam
Posted by (Questions: 23, Answers: 57)
Asked on July 30, 2017 9:51 pm
153 views
0

Hi Pete,
If condition ”a fresh cross” is not possible, then please ignore that condition.
Thanks!

( at July 30, 2017 11:18 pm)
0

Well the price crossing the 50 period SMA is supported by a built in filter so we don’t even need to code for that. Keeps things simple. Taking only the FullK into account, we simply check that it is less than 40. The tricky part is checking if it has risen 5 points from it’s lowest point. Lowest point in how many bars? 2-3 bars or 100 bars? Something in between?

( at July 31, 2017 8:02 am)
0

Since it’ll scan on daily time frame, I think lowest or highest compare to the previous peak low or peak high. Will that work?

( at July 31, 2017 10:03 am)
0
Private answer

In the screenshot below I show how to setup the scan to include the price crossing the 50 period simple moving average. The code below is then applied as a new study filter. Together, these signals conform to your specifications. So we don’t always have to use code to solve these. We can leverage the built in tools to reduce the amount of code required to reach the goal.


input over_bought = 80;
input over_sold = 20;
input KPeriod = 8;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
def FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, slowing_period, averageType).FullK;
def pivotLow = FullK[2] > FullK[1] and FullK[1] < FullK and FullK < 40; def test = FullK > FullK[1];
def pivotHigh = FullK[2] < FullK[1] and FullK[1] > FullK and FullK > 60;
def lastPivotLowPrice = if pivotLow then FullK[1] else if FullK < 40 then lastPivotLowPrice[1] else FullK; def lastPivotHighPrice = if pivotHigh then FullK[1] else if FullK > 60 then lastPivotLowPrice[1] else FullK;
# use this to scan for FullK pivot low rising 5 point or more but still below 40
plot scan = lastPivotLowPrice < (FullK - 5) and FullK < 40; # use this to scan for FullK pivot high occurring within the last 5 bars #plot scan = lastPivotHighPrice > (FullK + 5) and FullK > 60;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 1, 2017 9:45 am
0

Thank you, Pete! I’ll put it to the test.

( at August 2, 2017 5:26 pm)