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;
Hi Pete,
If condition ”a fresh cross” is not possible, then please ignore that condition.
Thanks!
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?
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?