Cycle High/Low Stoch


0
0

Mr. Pete, I’m glad you are recovering well.

I’m trying to write a script that uses the full stochastic to mark cycle highs and lows. The definition of the high is %D crosses above 45 and then back below 55 and the low is marked by %D crossing below 45 and back above 55. I’m pretty much stuck, all I’m getting are red and green arrows accross the bottom of the chart. Please take a look at the script below, one glance and you can tell I don’t know what I’m doing 🙂 Any help or suggestions would be greatly appreciated.

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 5;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC – lowest_k;
def c2 = Highest(priceH, KPeriod) – lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);

def OverBought = over_bought;
def OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above 55;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below 45;
def cycleLow = if downd then low < low[1] and low < low[-1] else 0;
def cyclehigh = if upd then high > high[1] and high > high[-1] else 0;

plot UpSignal = cycleLow;
plot DownSignal = cyclehigh ;

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on September 14, 2019 2:21 pm
21 views
0
Private answer

Try changing the painting strategy to boolean arrows instead of just plan arrows.

Change these lines:

UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

To this:

UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Marked as spam
Posted by (Questions: 36, Answers: 2121)
Answered on September 14, 2019 3:32 pm
Well that definitely solved that issue. It's catching the lows pretty well but missing the highs. I'll keep at it, thank you very much!
( at September 14, 2019 4:06 pm)
i'm trying to simplify the code of the swing high and low, I can get it to mark the determined highs and lows but I can't get it to use the stochastic filter named cycle1, the levels of 40 up cross and 60 down cross that trigger the signal. I added the code below, please take a look when you have a chance. Thank you sir! def cycle1 = IF StochasticFull()."FullD" crosses above 40 and StochasticFull()."FullD" crosses below 60 THEN 1 ELSE 0; def swinghigh = if cycle1 is true then high > high[1] and high > high[2] and high > high[-1] and high > high[-2] else 0; #def swinglow = if low < low[1] and low < low[2] and low < low[-1] and low < low[-2]then 1 else 0; plot DownSignal = if swinghigh then high else double.nan; DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); #plot UpSignal = if swinglow then low else double.nan; #UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
( at September 15, 2019 7:28 pm)
The statement for cycle1 variable is never true. It is not possible for the FullD to cross above 40 and cross below 60 on the same candle. As I understand it you would not want to change the word "and" to "or" so that it can be true for either event. Seems you would want to split that out into separate variables so you can use on for the cycle highs and one for cycle lows.
( at September 16, 2019 11:13 am)