Premier Stochastic Oscillator

Different study but use as an example;

Average(Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) / (Highest(high(period = AggregationPeriod1),
 

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

Please tell me i did it right ???

# // ==========================
#
# Technical Analysis of Stocks & Commodities
# August, 2008
# Premier Stochastic Oscillator by Lee Leibfarth
# pp 30 - 36
# ported by R Houser
# Changed to histogram display by Horserider 10/11/219

declare lower;

# inputs:
input Line1 = 0.9;
input Line2 = 0.2;
input StochLength = 8;
input Period = 25;
input agg = AggregationPeriod.DAY;



# variables:
# oFastK(0),100 * ( ( close (period = Agg)
# oFastD(0),100 * ( ( close (period = Agg)
# oSlowK(0),100 * ( ( close (period = Agg)
# oSlowD(0),100 * ( ( close (period = Agg)
# Length(0),100 * ( ( close (period = Agg)
# NormStoch(0),100 * ( ( close (period = Agg)
# SmoothStoch(0),100 * ( ( close (period = Agg)
# Premier(0);100 * ( ( close (period = Agg)


# Value1 = Stochastic( h, l, c, StochLength, 1, 3, 1, oFastK, oFastD, oSlowK, oSlowD);
def oFastK = 100 * ( ( close - Lowest( low, StochLength ) ) / ( Highest( high, StochLength ) - Lowest( low, StochLength ) ) );
def oFastD = Average( oFastK, 1 );
def oSlowK = oFastD;
def oSlowD = Average( oSlowK, 3 );


# Length = iff(Period < 0, 1, squareroot(Period));
def Length = if Period < 0 then 1 else Sqrt( Period );


# NormStoch = .1 * (oslowK - 50);
def NormStoch = 0.1 * ( oSlowK - 50 );


# SmoothStoch = xaverage(xaverage(NormStoch, Length), Length);
def SmoothStoch = ExpAverage( ExpAverage( NormStoch, Length ), Length );


plot Premier = ( Exp( 1 * SmoothStoch ) - 1 ) / ( Exp( 1 * SmoothStoch ) + 1 );


plot pLine1 = Line1;
pLine1.SetDefaultColor( Color.BLACK );
plot pLine2 = Line2;
pLine2.SetDefaultColor( Color.GRAY );
plot nLine1 = -1 * Line1;
nLine1.SetDefaultColor( Color.BLACK );
plot nLine2 = -1 * Line2;
nLine2.SetDefaultColor( Color.GRAY );

#Premier.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Premier.SetLineWeight(3);
Premier.DefineColor("Positive and Up", Color.GREEN);
Premier.DefineColor("Positive and Down", Color.DARK_GREEN);
Premier.DefineColor("Negative and Down", Color.RED);
Premier.DefineColor("Negative and Up", Color.DARK_RED);
Premier.AssignValueColor(if Premier >= 0 then if Premier >Premier[1] then Premier.color("Positive and Up") else Premier.color("Positive and Down") else if Premier < Premier[1] then Premier.color("Negative and Down") else Premier.color("Negative and Up"));
 
Missing link ??

# variables:
# oFastK(0),100 * ( ( close (period = Agg)
# oFastD(0),100 * ( ( close (period = Agg)
# oSlowK(0),100 * ( ( close (period = Agg)
# oSlowD(0),100 * ( ( close (period = Agg)
# Length(0),100 * ( ( close (period = Agg)
# NormStoch(0),100 * ( ( close (period = Agg)
# SmoothStoch(0),100 * ( ( close (period = Agg)
# Premier(0);100 * ( ( close (period = Agg)
 
Nope I just checked all the time frames I'm still off, I thought I had it, what else could it be? let me know thanks
 
I see you are not understanding my hints. Congratulations on not giving up. I do not know what else to tell you. I do not wish to do the code as I have no interest in it. I will give you an example of similar study.

Here is a stochastic one. Maybe that will help.

Code:
input KPeriod1 = 10;
input DPeriod1 = 10;
input slowing_period1 = 3;

input KPeriod2 = 10;
input DPeriod2 = 10;
input slowing_period2 = 3;


input AggregationPeriod1 = {"MONTH", "WEEK", "DAY", "4 HOURS", "1 HOUR", "30 MIN", Default "15 MIN","10 MIN", "5 MIN", "3 MIN"};
input AggregationPeriod2 = {"MONTH", "WEEK", "DAY", "4 HOURS", "1 HOUR", "30 MIN", Default "15 MIN","10 MIN", "5 MIN", "3 MIN"};

plot FullK1 = Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) / (Highest(high(period = AggregationPeriod1), KPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) * 100, slowing_period1);

plot FullD1 = Average(Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) / (Highest(high(period = AggregationPeriod1), KPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) * 100, slowing_period1), DPeriod1);


plot FullK2 = Average((close(period = AggregationPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) / (Highest(high(period = AggregationPeriod2), KPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) * 100, slowing_period2);

plot FullD2 = Average(Average((close(period = AggregationPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) / (Highest(high(period = AggregationPeriod2), KPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) * 100, slowing_period2), DPeriod2);
 
I see you are not understanding my hints. Congratulations on not giving up. I do not know what else to tell you. I do not wish to do the code as I have no interest in it. I will give you an example of similar study.

Here is a stochastic one. Maybe that will help.

Code:
input KPeriod1 = 10;
input DPeriod1 = 10;
input slowing_period1 = 3;

input KPeriod2 = 10;
input DPeriod2 = 10;
input slowing_period2 = 3;


input AggregationPeriod1 = {"MONTH", "WEEK", "DAY", "4 HOURS", "1 HOUR", "30 MIN", Default "15 MIN","10 MIN", "5 MIN", "3 MIN"};
input AggregationPeriod2 = {"MONTH", "WEEK", "DAY", "4 HOURS", "1 HOUR", "30 MIN", Default "15 MIN","10 MIN", "5 MIN", "3 MIN"};

plot FullK1 = Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) / (Highest(high(period = AggregationPeriod1), KPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) * 100, slowing_period1);

plot FullD1 = Average(Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) / (Highest(high(period = AggregationPeriod1), KPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) * 100, slowing_period1), DPeriod1);


plot FullK2 = Average((close(period = AggregationPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) / (Highest(high(period = AggregationPeriod2), KPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) * 100, slowing_period2);

plot FullD2 = Average(Average((close(period = AggregationPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) / (Highest(high(period = AggregationPeriod2), KPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) * 100, slowing_period2), DPeriod2);
This is what i have so far
 
Full code, when i look at the Inputs it has 3 differnt aggregations i only need one to switch to differnt time frames, its not complete this is what i have so far whats next ?

Code:
# // ==========================
#
# Technical Analysis of Stocks & Commodities
# August, 2008
# Premier Stochastic Oscillator by Lee Leibfarth
# pp 30 - 36
# ported by R Houser
# Changed to histogram display by Horserider 10/11/219

declare lower;

# inputs:
input Line1 = 0.9;
input Line2 = 0.2;
input StochLength = 8;
input Period = 25;
input agg = AggregationPeriod.HOUR;



input AggregationPeriod1 = {"MONTH", "WEEK", "DAY", "4 HOURS", "1 HOUR", "30 MIN", Default "15 MIN","10 MIN", "5 MIN", "3 MIN"};
input AggregationPeriod2 = {"MONTH", "WEEK", "DAY", "4 HOURS", "1 HOUR", "30 MIN", Default "15 MIN","10 MIN", "5 MIN", "3 MIN"};

# variables:
# oFastK(0)= Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) / (Highest(high(period = AggregationPeriod1), KPeriod1) - Lowest(low(period = AggregationPeriod1), KPeriod1)) * 100, slowing_period1);

# oFastD(0)= Average(Average((close(period = AggregationPeriod1) - Lowest(low(period = AggregationPeriod1), DPeriod1)) / (Highest(high(period = AggregationPeriod1), DPeriod1) - Lowest(low(period = AggregationPeriod1), DPeriod1)) * 100, slowing_period1), DPeriod1);

# oSlowK(0)= Average((close(period = AggregationPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) / (Highest(high(period = AggregationPeriod2), KPeriod2) - Lowest(low(period = AggregationPeriod2), KPeriod2)) * 100, slowing_period2);

# oSlowD(0)= Average(Average((close(period = AggregationPeriod2) - Lowest(low(period = AggregationPeriod2), DPeriod2)) / (Highest(high(period = AggregationPeriod2), DPeriod2) - Lowest(low(period = AggregationPeriod2), DPeriod2)) * 100, slowing_period2), DPeriod2);

# Length(0)

# NormStoch(0)

# SmoothStoch(0)

#Premier(0);


# Value1 = Stochastic( h, l, c, StochLength, 1, 3, 1, oFastK, oFastD, oSlowK, oSlowD);
def oFastK = 100 * ( ( close - Lowest( low, StochLength ) ) / ( Highest( high, StochLength ) - Lowest( low, StochLength ) ) );
def oFastD = Average( oFastK, 1 );
def oSlowK = oFastD;
def oSlowD = Average( oSlowK, 3 );


# Length = iff(Period < 0, 1, squareroot(Period));
def Length = if Period < 0 then 1 else Sqrt( Period );


# NormStoch = .1 * (oslowK - 50);
def NormStoch = 0.1 * ( oSlowK - 50 );


# SmoothStoch = xaverage(xaverage(NormStoch, Length), Length);
def SmoothStoch = ExpAverage( ExpAverage( NormStoch, Length ), Length );


plot Premier = ( Exp( 1 * SmoothStoch ) - 1 ) / ( Exp( 1 * SmoothStoch ) + 1 );


plot pLine1 = Line1;
pLine1.SetDefaultColor( Color.BLACK );
plot pLine2 = Line2;
pLine2.SetDefaultColor( Color.GRAY );
plot nLine1 = -1 * Line1;
nLine1.SetDefaultColor( Color.BLACK );
plot nLine2 = -1 * Line2;
nLine2.SetDefaultColor( Color.GRAY );

#Premier.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Premier.SetLineWeight(3);
Premier.DefineColor("Positive and Up", Color.GREEN);
Premier.DefineColor("Positive and Down", Color.DARK_GREEN);
Premier.DefineColor("Negative and Down", Color.RED);
Premier.DefineColor("Negative and Up", Color.DARK_RED);
Premier.AssignValueColor(if Premier >= 0 then if Premier >Premier[1] then Premier.color("Positive and Up") else Premier.color("Positive and Down") else if Premier < Premier[1] then Premier.color("Negative and Down") else Premier.color("Negative and Up"));
 
def oFastK1= 100 *( ( close(period = AggregationPeriod1) - Lowest( low(period = AggregationPeriod1), StochLength ) ) / ( Highest( high(period = AggregationPeriod1), StochLength ) - Lowest( low(period = AggregationPeriod1), StochLength ) ) );
 
def oFastK1= 100 *( ( close(period = AggregationPeriod1) - Lowest( low(period = AggregationPeriod1), StochLength ) ) / ( Highest( high(period = AggregationPeriod1), StochLength ) - Lowest( low(period = AggregationPeriod1), StochLength ) ) );
I updated and numbered each one, your example you have AggregationPeriod1), so would i number teh next one 2? i looked at post 44 again and i saw that the example was numbered so i was going off of that, let me know if im getting close thanks for helping
 
Code:
# // ==========================
# // PREMIER STOCHASTIC
# // Indicator
# // ==========================
#
# Technical Analysis of Stocks & Commodities
# August, 2008
# Premier Stochastic Oscillator by Lee Leibfarth
# pp 30 - 36
# ported by R Houser
#  Changed to histogram display by Horserider 10/11/219

declare lower; 

# inputs:
input Line1 = 0.9;
input Line2 = 0.2;
input StochLength = 8;
input Period = 25;


# variables:
# oFastK(0),
# oFastD(0),
# oSlowK(0),
# oSlowD(0),
# Length(0),
# NormStoch(0),
# SmoothStoch(0),
# Premier(0);


# Value1 = Stochastic( h, l, c, StochLength, 1, 3, 1, oFastK, oFastD, oSlowK, oSlowD);
def oFastK = 100 * ( ( close - Lowest( low, StochLength ) ) / ( Highest( high, StochLength ) - Lowest( low, StochLength ) ) );
def oFastD = Average( oFastK, 1 );
def oSlowK = oFastD;
def oSlowD = Average( oSlowK, 3 );


# Length = iff(Period < 0, 1, squareroot(Period));
def Length = if Period < 0 then 1 else Sqrt( Period );


# NormStoch = .1 * (oslowK - 50);
def NormStoch = 0.1 * ( oSlowK - 50 );


# SmoothStoch = xaverage(xaverage(NormStoch, Length), Length);
def SmoothStoch = ExpAverage( ExpAverage( NormStoch, Length ), Length );


plot Premier = ( Exp( 1 * SmoothStoch ) - 1 ) / ( Exp( 1 * SmoothStoch ) + 1 );
    

plot pLine1 = Line1;
        pLine1.SetDefaultColor( Color.BLACK );
plot pLine2 = Line2;
        pLine2.SetDefaultColor( Color.GRAY );
plot nLine1 = -1 * Line1;
        nLine1.SetDefaultColor( Color.BLACK );
plot nLine2 = -1 * Line2;
        nLine2.SetDefaultColor( Color.GRAY );

#Premier.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Premier.SetLineWeight(3);
Premier.DefineColor("Positive and Up", Color.GREEN);
Premier.DefineColor("Positive and Down", Color.DARK_GREEN);
Premier.DefineColor("Negative and Down", Color.RED);
Premier.DefineColor("Negative and Up", Color.DARK_RED);
Premier.AssignValueColor(if Premier >= 0 then if Premier >Premier[1] then Premier.color("Positive and Up") else Premier.color("Positive and Down") else if Premier < Premier[1] then Premier.color("Negative and Down") else Premier.color("Negative and Up"));

# Agg Period 1

input agg1 = AggregationPeriod.DAY;

def oFastK1= 100 *( ( close(period = Agg1) - Lowest( low(period = Agg1), StochLength ) ) / ( Highest( high(period = Agg1), StochLength ) - Lowest( low(period = Agg1), StochLength ) ) );
 
Ok tried to make it clearer. Start aggs after original code as shown. That is a start of the new agg calculation. Now just follow up with the rest of the code from the original and modify it to include the agg values calculated in the previous lines.
 
erase all that. And do not use comments, then ToS will color the code RED if it has errors and tell you what is incorrect
 
Ok tried to make it clearer. Start aggs after original code as shown. That is a start of the new agg calculation. Now just follow up with the rest of the code from the original and modify it to include the agg values calculated in the previous lines.
OK i just saw this
 
Ok I did this just to b sure my hints were ok. Did you get this yet?

Image-mtp.jpg
 
I can’t figure it out, I went back to the TMO code and see that the aggregation area code is small, not sure if these 2 are irrelevant, I know it’s simple but I can’t figure it out
 
Go to last code I posted. Below the # Agg period 1 is the first calculation. Copy the remaining code from the original study from below that calculation. Now go through and modify that code to the agg. Try it then show what you have. Think what those remaining calculations should be.
 
Go to last code I posted. Below the # Agg period 1 is the first calculation. Copy the remaining code from the original study from below that calculation. Now go through and modify that code to the agg. Try it then show what you have. Think what those remaining calculations should be.
you mean this one

def oFastK1= 100 *( ( close(period = AggregationPeriod1) - Lowest( low(period = AggregationPeriod1), StochLength ) ) / ( Highest( high(period = AggregationPeriod1), StochLength ) - Lowest( low(period = AggregationPeriod1), StochLength ) ) );
 
Hint: next line should be;
def oFastD = Average( oFastK, 1 );

Now how does this need to be changed for new agg to work
this is the line of code to start with, code number #72

# Agg Period 1

input agg1 = AggregationPeriod.DAY;

def oFastK1= 100 *( ( close(period = Agg1) - Lowest( low(period = Agg1), StochLength ) ) / ( Highest( high(period = Agg1), StochLength ) - Lowest( low(period = Agg1), StochLength ) ) );
 
Here is your note

That is the start of the new agg calculation. Now just follow up with the rest of the code from the original and modify it to include the agg values calculated in the previous lines.

how do i modify it to include in the values
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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