Low To High with Stochastic

Miamidog

New member
i need some help with this script. I'm trying to get the stochastic to plot on my upper chart. when Data is signaled I want it to find the high from the previous low and when Data2 is signaled I want it to find the low from the previous high. with a dot above the high and a dot below the low or connected with lines




Code:
input over_bought = 0;
input over_sold = 0;
input over_sold2 = 0;
input over_bought2 = 0;
def middle = 50;
def middle2 = 50;
input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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);



plot OverBought = over_bought;
plot OverSold = over_sold;
plot OverSold2 = over_sold2;
plot OverBought2 = over_bought2;


def upK = FullK crosses above OverSold;
def downK = FullK crosses below OverBought;

def upD = FullD crosses above OverSold;
def downD = FullD crosses below OverBought;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On FullK":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
    UpSignal = if upK or upD then OverSold else Double.NaN;
    DownSignal = if downK or downD then OverBought else Double.NaN;
}



plot data =(if FullD crosses above middle then 2 else 0);
plot data2 =(if FullD crosses below middle then 1 else 0);
 
i need some help with this script. I'm trying to get the stochastic to plot on my upper chart. when Data is signaled I want it to find the high from the previous low and when Data2 is signaled I want it to find the low from the previous high. with a dot above the high and a dot below the low or connected with lines

I modified your code to have flexibility to choose between your middle (50/50) criteria and other combinations of overbought/oversold (ob/os) ones. A mauve colored dot will appear at the highs and cyan at the lows associated with crosses at ob/os. A line can also be drawn connecting the dots.

Screenshot-2021-08-19-090412.jpg
Ruby:
input crossbasis = {default "50/50", "90/10",  "80/20", "70/30", "60/40"} ;
def os;
def ob;
switch (crossbasis) {
case "50/50":
os=50;
ob=50;
case "90/10":
os=90;
ob=10;
case "80/20":
os=80;
ob=20;
case "70/30":
os=70;
ob=30;
case "60/40":
os=60;
ob=40;
}

input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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 data  = (if FullD crosses above ob then 1 else 0);
def data2 = (if FullD crosses below os then 1 else 0);

plot xdata = if data[1] == 0 and data then low else double.nan;
xdata.SetPaintingStrategy(PaintingStrategy.POINTS);
xdata.SetLineWeight(5);

plot xdata2 = if data[1] == 0 and data2 then high else double.nan;
xdata2.SetPaintingStrategy(PaintingStrategy.POINTS);
xdata2.SetLineWeight(5);

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

def sh = if !IsNaN(xdata2) then high else Double.NaN;
def sl = if !IsNaN(xdata)  then low else Double.NaN;
input showhilowline = yes;
plot hilowline = if showhilowline == no then Double.NaN else if data2==1 then sh else sl;
hilowline.EnableApproximation();
hilowline.SetDefaultColor(Color.BLACK);
hilowline.HideBubble();
 
Last edited:

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

I modified your code to have flexibility to choose between your middle (50/50) criteria and other combinations of overbought/oversold (ob/os) ones. A mauve colored dot will appear at the highs and cyan at the lows associated with crosses at ob/os. A line can also be drawn connecting the dots.

I made an adjustment on the script. I plotting the sh/sl price , but how do you plot it on the SH/SL bar ?

https://i.postimg.cc/9MzHbCMY/tos-pic.png


Code:
input crossbasis = {default "50/50", "90/10",  "80/20", "70/30", "60/40"} ;
def os;
def ob;
switch (crossbasis) {
case "50/50":
os=50;
ob=50;
case "90/10":
os=90;
ob=10;
case "80/20":
os=80;
ob=20;
case "70/30":
os=70;
ob=30;
case "60/40":
os=60;
ob=40;
}

input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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 data  = (if FullD crosses above ob then 1 else 0);
def data2 = (if FullD crosses below os then 1 else 0);

plot xdata = if data[1] == 0 and data then (lowest(priceL[1], 5)) else double.nan;
xdata.SetPaintingStrategy(PaintingStrategy.POINTS);
xdata.SetLineWeight(5);

plot xdata2 = if data[1] == 0 and data2 then (Highest(priceH[1], 5)) else double.nan;
xdata2.SetPaintingStrategy(PaintingStrategy.POINTS);
xdata2.SetLineWeight(5);

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

def sh = if !IsNaN(xdata2) then (Highest(priceH[1], 5)) else Double.NaN;
def sl = if !IsNaN(xdata)  then (lowest(priceL[1], 5)) else Double.NaN;
input showhilowline = yes;
plot hilowline = if showhilowline == no then Double.NaN else if data2==1 then sh else sl;
hilowline.EnableApproximation();
hilowline.SetDefaultColor(Color.BLACK);
hilowline.HideBubble();
 
Last edited:
i need some help with this code. I want to plot points only on the highs and lows. Not on every bar


Code:
input Neutral = 50;
input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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 rdWave = Round(FullD, 1);

def rdFulld = Round(FullD, 1);

def stoc =  (if rdFulld < Neutral then -1 else 1);


plot sLow = if stoc == -1 then (low)  else Double.NaN;
sLow.SetPaintingStrategy(PaintingStrategy.POINTS);
sLow.SetLineWeight(5);

plot sHigh = if stoc == 1 then (high)  else Double.NaN;
sHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
sHigh.SetLineWeight(5);

#------------------------------------------------
 
i need some help with this code. I want to plot points only on the highs and lows. Not on every bar


Code:
input Neutral = 50;
input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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 rdWave = Round(FullD, 1);

def rdFulld = Round(FullD, 1);

def stoc =  (if rdFulld < Neutral then -1 else 1);


plot sLow = if stoc == -1 then (low)  else Double.NaN;
sLow.SetPaintingStrategy(PaintingStrategy.POINTS);
sLow.SetLineWeight(5);

plot sHigh = if stoc == 1 then (high)  else Double.NaN;
sHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
sHigh.SetLineWeight(5);

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

Try this

Capture.jpg
Ruby:
input Neutral = 50;
input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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 rdWave = Round(FullD, 1);

def rdFulld = Round(FullD, 1);

def stoc =   if rdFulld crosses below Neutral
             then -1
             else if rdfulld crosses above neutral
             then 1 else 0;


plot sLow = if stoc == -1 then (low)  else Double.NaN;
slow.setdefaultColor(color.white);
sLow.SetPaintingStrategy(PaintingStrategy.POINTS);
sLow.SetLineWeight(5);

plot sHigh = if stoc == 1 then (high)  else Double.NaN;
shigh.setdefaultColor(color.cyan);
sHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
sHigh.SetLineWeight(5);

#------------------------------------------------
 
That is not the script I provided, it is your original. Nonetheless, both scripts appear to plot at the high/low prices
yes it is. i have arrow pointing to where it should plot but its not. the original is printing at the highs and low but not on the candle that made the highs and lows. I was wondering how can I make it plot on the high and low candle?
 
yes it is. i have arrow pointing to where it should plot but its not. the original is printing at the highs and low but not on the candle that made the highs and lows. I was wondering how can I make it plot on the high and low candle?
You sent me a grid link with 3 charts with a lot of studies. I was referring to the AAPL 15D 5m chart. From what I can see, it does not have the script I gave you to use, but it appears to be your oriiginal. Here is the script I gave you from above.

In particular the script you provided in the link has:
Ruby:
def stoc =  (if rdFulld < Neutral then -1 else 1);

The script I provided above and below again has:
Ruby:
def stoc =   if rdFulld crosses below Neutral
             then -1
             else if rdfulld crosses above neutral
             then 1 else 0;

Here is the full code I provided
Ruby:
input Neutral = 50;
input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

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 rdWave = Round(FullD, 1);

def rdFulld = Round(FullD, 1);

def stoc =   if rdFulld crosses below Neutral
             then -1
             else if rdfulld crosses above neutral
             then 1 else 0;


plot sLow = if stoc == -1 then (low)  else Double.NaN;
slow.setdefaultColor(color.white);
sLow.SetPaintingStrategy(PaintingStrategy.POINTS);
sLow.SetLineWeight(5);

plot sHigh = if stoc == 1 then (high)  else Double.NaN;
shigh.setdefaultColor(color.cyan);
sHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
sHigh.SetLineWeight(5);

#---------------------------------------------
 
Love the Flexible Grid you posted. I have only one question which is only on the MOM/DAD. The red and green dots are plotting momentum (?) but I have not be able to define it as well as the think color line or the histogram etc. I am familiar with the Barry Burns method which I believe this is deprived from.

Can you tell me what the green and red dot on mom is defining? TIA Gio
Sorry, that was not my flexgrid, but a copyrighted script by someone else as part of Meldog's post. Hopefully, Meldog will assist you.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
467 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