alert(AlertsOn && LTF from 1 bar ago >= 20 and LTF < 20 ,”Stochastic HPS Buy Setup”,alert.BAR,sound.Bell);
alert(AlertsOn && LTF from 1 bar ago <= 80 and LTF > 80 , ”Stochastic HPS Sell setup”, alert.BAR,sound.Ding);
...............................................................................................................................................................................................................................................................
plot Data = close;declare lower;
Input AlertsOn = yes;
Input ShowTodayOnly = yes;
Def Today = if !ShowTodayOnly then 1 else if getday() == getLastDay() then 1 else 0;
def over_bought = 75;
def over_sold = 25;
def priceH = high;
def priceL = low;
def priceC = (high + low) / 2;input ShortKPeriod = 14;
input ShortPercentK = 7;
input smoothing_period = 6;
input MidKPeriod = 24;
input MidPercentK = 8;
input LongKPeriod = 35;
input LongPercentK = 10;
def Sc1 = priceC - Lowest(priceL, ShortKPeriod);
def Sc2 = Highest(priceH, ShortKPeriod) - Lowest(priceL, ShortKPeriod);
def SFastK = Sc1 / Sc2 * 100;
def Mc1 = priceC - Lowest(priceL, MidKPeriod);
def Mc2 = Highest(priceH, MidKPeriod) - Lowest(priceL, MidKPeriod);
def MFastK = Mc1 / Mc2 * 100;
def Lc1 = priceC - Lowest(priceL, LongKPeriod);
def Lc2 = Highest(priceH, LongKPeriod) - Lowest(priceL, LongKPeriod);
def LFastK = Lc1 / Lc2 * 100;
plot STF;
plot STF2;
plot MTF;
plot MTF2;
plot LTF;
plot LTF2;
STF = Average(SFastK, ShortPercentK);
STF2 = Average(SFastK, ShortPercentK);
MTF = Average(MFastK, MidPercentK);
MTF2 = Average(MFastK, MidPercentK);
LTF = Average(LFastK, LongPercentK);
LTF2 = Average(LFastK, LongPercentK);
STF.SetDefaultColor(color.Light_Gray);
STF.SetLineWeight(1);
STF2.SetLineWeight(2);
MTF.SetDefaultColor(color.Light_Gray);
MTF.SetLineWeight(1);
MTF2.SetLineWeight(2);
LTF.SetDefaultColor(color.Light_Gray);
LTF.SetLineWeight(1);
LTF2.SetLineWeight(2);
STF.AssignValueColor(if STF < 25 then color.green else if STF > 80 then color.red else color.Light_Gray);
STF2.AssignValueColor(if STF2 < 50 and STF2 > 40 then color.yellow else if STF2 <= 40 and STF2 > 25 then color.Light_GREEN else if STF2 < 25 then color.green else if STF2 > 70 and STF2 < 75 then color.pink else if STF2 > 75 then color.red else if STF2 > 50 and STF2 < 60 then color.yellow else if STF2 >= 60 and STF2 < 75 then color.pink else color.Light_Gray );
MTF.AssignValueColor(if MTF < 20 then color.green else if MTF > 80 then color.red else color.Light_Gray);
MTF2.AssignValueColor(if MTF2 < 50 and MTF2 > 40 then color.yellow else if MTF2 <= 40 and MTF2 > 20 then color.Light_GREEN else if MTF2 < 20 then color.green else if MTF2 > 70 and MTF2 < 80 then color.pink else if MTF2 > 80 then color.red else if MTF2 > 50 and MTF2 < 60 then color.yellow else if MTF2 >= 60 and MTF2 < 80 then color.pink else color.Light_Gray );
LTF.AssignValueColor(if LTF < 20 then color.green else if LTF > 80 then color.red else color.Light_Gray);
LTF2.AssignValueColor(if LTF2 < 50 and LTF2 > 40 then color.yellow else if LTF2 <= 40 and LTF2 > 20 then color.Light_GREEN else if LTF2 < 20 then color.green else if LTF2 > 70 and LTF2 < 80 then color.pink else if LTF2 > 80 then color.red else if LTF2 > 50 and LTF2 < 60 then color.yellow else if LTF2 >= 60 and LTF2 < 80 then color.pink else color.Light_Gray );
# -- ALERTS --
alert(AlertsOn && LTF <= 25 and MTF <= 25 and STF from 1 bar ago <= 25 and STF > 25,”Stochastic Breaking Above 25”,alert.BAR,sound.Bell);
alert(AlertsOn && LTF >= 75 and MTF >= 75 and STF from 1 bar ago >= 75 and STF < 75 , ”Stochastic Breaking Below 75”, alert.BAR,sound.Ding);
alert(AlertsOn && LTF from 1 bar ago >= 20 and LTF < 20 ,”Stochastic HPS Buy Setup”,alert.BAR,sound.Bell);
alert(AlertsOn && LTF from 1 bar ago <= 80 and LTF > 80 , ”Stochastic HPS Sell setup”, alert.BAR,sound.Ding);
#---------------
plot OverBought = over_bought;
OverBought.SetDefaultColor(color.Green);
plot OverSold = over_sold;
OverSold.SetDefaultColor(color.Red);
plot MidLine = 50;
MidLine.SetDefaultColor(color.white);
# START CODE
def priceH = high;
def priceL = low;
def priceC = (high + low) / 2;
input ShortKPeriod = 14;
input ShortPercentK = 7;
input MidKPeriod = 24;
input MidPercentK = 8;
input LongKPeriod = 35;
input LongPercentK = 10;
def Sc1 = priceC - Lowest(priceL, ShortKPeriod);
def Sc2 = Highest(priceH, ShortKPeriod) - Lowest(priceL, ShortKPeriod);
def SFastK = Sc1 / Sc2 * 100;
def Mc1 = priceC - Lowest(priceL, MidKPeriod);
def Mc2 = Highest(priceH, MidKPeriod) - Lowest(priceL, MidKPeriod);
def MFastK = Mc1 / Mc2 * 100;
def Lc1 = priceC - Lowest(priceL, LongKPeriod);
def Lc2 = Highest(priceH, LongKPeriod) - Lowest(priceL, LongKPeriod);
def LFastK = Lc1 / Lc2 * 100;
def STF = Average(SFastK, ShortPercentK);
def MTF = Average(MFastK, MidPercentK);
def LTF = Average(LFastK, LongPercentK);
# Four scan conditions are defined.
# Make sure you only use one and the other 3 must be commented out
# The scanner only expects a single plot statement
# Choose the scan of your choice from one of the following
#plot cond1 = LTF <= 25 and MTF <= 25 and STF from 1 bar ago <= 25 and STF > 25; # Stochastic Breaking Above 25
#plot cond2 = LTF >= 75 and MTF >= 75 and STF from 1 bar ago >= 75 and STF < 75; # Stochastic Breaking Below 75
plot cond3 = LTF from 1 bar ago >= 20 and LTF < 20; # Stochastic HPS Buy
#plot cond4 = LTF from 1 bar ago <= 80 and LTF > 80; # Stochastic HPS Sell
# END CODE
plot Data = close;declare lower;
Input AlertsOn = yes;
Input ShowTodayOnly = yes;
Def Today = if !ShowTodayOnly then 1 else if getday() == getLastDay() then 1 else 0;
def over_bought = 75;
def over_sold = 25;
def priceH = high;
def priceL = low;
def priceC = (high + low) / 2;input ShortKPeriod = 14;
input ShortPercentK = 3;
input smoothing_period = 3;
input MidKPeriod = 10;
input MidPercentK = 10;
input LongKPeriod = 9;
input LongPercentK = 3;
def Sc1 = priceC - Lowest(priceL, ShortKPeriod);
def Sc2 = Highest(priceH, ShortKPeriod) - Lowest(priceL, ShortKPeriod);
def SFastK = Sc1 / Sc2 * 100;
def Mc1 = priceC - Lowest(priceL, MidKPeriod);
def Mc2 = Highest(priceH, MidKPeriod) - Lowest(priceL, MidKPeriod);
def MFastK = Mc1 / Mc2 * 100;
def Lc1 = priceC - Lowest(priceL, LongKPeriod);
def Lc2 = Highest(priceH, LongKPeriod) - Lowest(priceL, LongKPeriod);
def LFastK = Lc1 / Lc2 * 100;
plot STF;
plot STF2;
plot MTF;
plot MTF2;
plot LTF;
plot LTF2;
STF = Average(SFastK, ShortPercentK);
STF2 = Average(SFastK, ShortPercentK);
MTF = Average(MFastK, MidPercentK);
MTF2 = Average(MFastK, MidPercentK);
LTF = Average(LFastK, LongPercentK);
LTF2 = Average(LFastK, LongPercentK);
STF.SetDefaultColor(color.Light_Gray);
STF.SetLineWeight(1);
STF2.SetLineWeight(2);
MTF.SetDefaultColor(color.Light_Gray);
MTF.SetLineWeight(1);
MTF2.SetLineWeight(2);
LTF.SetDefaultColor(color.Light_Gray);
LTF.SetLineWeight(1);
LTF2.SetLineWeight(2);
STF.AssignValueColor(if STF < 25 then color.green else if STF > 80 then color.red else color.Light_Gray);
STF2.AssignValueColor(if STF2 < 50 and STF2 > 40 then color.yellow else if STF2 <= 40 and STF2 > 25 then color.Light_GREEN else if STF2 < 25 then color.green else if STF2 > 70 and STF2 < 75 then color.pink else if STF2 > 75 then color.red else if STF2 > 50 and STF2 < 60 then color.yellow else if STF2 >= 60 and STF2 < 75 then color.pink else color.Light_Gray );
MTF.AssignValueColor(if MTF < 20 then color.green else if MTF > 80 then color.red else color.Light_Gray);
MTF2.AssignValueColor(if MTF2 < 50 and MTF2 > 40 then color.yellow else if MTF2 <= 40 and MTF2 > 20 then color.Light_GREEN else if MTF2 < 20 then color.green else if MTF2 > 70 and MTF2 < 80 then color.pink else if MTF2 > 80 then color.red else if MTF2 > 50 and MTF2 < 60 then color.yellow else if MTF2 >= 60 and MTF2 < 80 then color.pink else color.Light_Gray );
LTF.AssignValueColor(if LTF < 20 then color.green else if LTF > 80 then color.red else color.Light_Gray);
LTF2.AssignValueColor(if LTF2 < 50 and LTF2 > 40 then color.yellow else if LTF2 <= 40 and LTF2 > 20 then color.Light_GREEN else if LTF2 < 20 then color.green else if LTF2 > 70 and LTF2 < 80 then color.pink else if LTF2 > 80 then color.red else if LTF2 > 50 and LTF2 < 60 then color.yellow else if LTF2 >= 60 and LTF2 < 80 then color.pink else color.Light_Gray );
# -- ALERTS --
alert(AlertsOn && LTF <= 25 and MTF <= 25 and STF from 1 bar ago <= 25 and STF > 25,”Stochastic Breaking Above 25”,alert.BAR,sound.Bell);
alert(AlertsOn && LTF >= 75 and MTF >= 75 and STF from 1 bar ago >= 75 and STF < 75 , ”Stochastic Breaking Below 75”, alert.BAR,sound.Ding);
alert(AlertsOn && LTF from 1 bar ago >= 20 and LTF < 20 ,”Stochastic HPS Buy Setup”,alert.BAR,sound.Bell);
alert(AlertsOn && LTF from 1 bar ago <= 80 and LTF > 80 , ”Stochastic HPS Sell setup”, alert.BAR,sound.Ding);
#---------------
plot OverBought = over_bought;
OverBought.SetDefaultColor(color.Green);
plot OverSold = over_sold;
OverSold.SetDefaultColor(color.Red);
plot MidLine = 50;
MidLine.SetDefaultColor(color.white);
To be honest, I am not sure what that even means. I know how to read charts and trade but when it comes to any type of coding, I can barely do a simple SQL search lol
That code was given to me from a friend and after a little back testing it looks like it could be helpful with scalping, which is what prompted me to try to turn it into a scan.
I was also given a similar indicator that I wanted to try to convert myself into a similar scan as you did and figured if I looked at your work I'd be able to figure it out but it is proving more difficult/time consuming that I had anticipated.
Below is the code to that new one; if you could help me with this it would be greatly appreciated. Otherwise I'll just keep taking stabs at it over the week to try to get it figured out haha.
Thanks again!
........................................
# Three different lengths of StochasticCrossover FullK
# Horserider 1/12/2020 requested by wsjiii
declare lower;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 7;
input KPeriod2 = 14;
input KPeriod3 = 21;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
# First K period
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;
# Second K period
def lowest_k2 = Lowest(priceL, KPeriod2);
def c12 = priceC - lowest_k2;
def c22 = Highest(priceH, KPeriod2) - lowest_k2;
def FastK2 = if c22 != 0 then c12 / c22 * 100 else 0;
# Third K period
def lowest_k3 = Lowest(priceL, KPeriod3);
def c13 = priceC - lowest_k3;
def c23 = Highest(priceH, KPeriod3) - lowest_k3;
def FastK3 = if c23 != 0 then c13 / c23 * 100 else 0;
# Plots
plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullK2 = MovingAverage(averageType, FastK2, slowing_period);
plot FullK3 = MovingAverage(averageType, FastK3, slowing_period);
plot OverBought = over_bought;
plot OverSold = over_sold;
FullK.SetDefaultColor(GetColor(2));
FullK2.SetDefaultColor(GetColor(3));
FullK3.SetDefaultColor(GetColor(4));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
![]() |
Elastic Stochastic for ThinkorSwim -Upper and Lower indicator | Indicators | 8 | |
![]() |
Stochastic Scalper for ThinkorSwim | Indicators | 12 | |
![]() |
Mobius Full Stochastic MTF for ThinkorSwim | Indicators | 4 | |
M | Premier Stochastic Oscillator | Indicators | 91 | |
![]() |
MoneyWave Stochastic Indicator for ThinkorSwim | Indicators | 8 |
Start a new thread and receive assistance from our community.
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.
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.