Stochastic, PRT vs Pine script

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #218287 quote
    pabo_swe
    Participant
    Junior

    Hi,

    Trying to understand how to convert pine script for stochastic to PRT code. Been checking documentation on both Pine Script and PRT, but PRT seems to demand an extra value as input, “K”.

    PRT:
    Stochastic[N,K](price1,price2,price3), (5 input values)

    Pine Script:
    ta.stoch(source, high, low, length), (4 input values)

    Does anyone here knows how to convert a Pine Script Stochastic line of code to PRT?
    (for example this)

    source = close
    lookback = input.int(25, minval=1)
    myStoch = ta.stoch(source, high, low, lookback)

    appreciate the help

    #218293 quote
    JS
    Participant
    Senior

    Hi,

    Calculation Stochastic as used in PRT

    hi = highest[14](high)

    lo = lowest[14](low)

    oscillator = (close – lo) / (hi – lo) * 100

    ProcentK = average[3,0](oscillator) // 0=SMA, 1=EMA, 2=WMA

    ProcentD = average[5,0](ProcentK) // 0=SMA, 1=EMA, 2=WMA

    RETURN ProcentK AS “%K MA”, ProcentD AS “%D MA”

    Formule Stochastics in PRT:

    Stochastic[14,3](close)

    Stochastic[N,K](price)

    N=(lookback)period

    K=period of the moving average for smoothing the oscillator

    Price=Close (source)

    In PRT, the Stochastics is always calculated by default with the “Close” but if you want to use other sources you can specify them in (price1, price2, price3).

    If you also want to use the %D (average of %K), you must use the following indicator:

    StochasticD[N,K,D](Close)

    With the input used in your post, the Stochastic looks like this:

    Stochastic[25,3](Close)
    #218295 quote
    pabo_swe
    Participant
    Junior
    That was a lot… Thanks… 🙂 So, by keeping K=3, then it’s comparable to how it’s calculated in Pine Script… did I get that right?
    #218300 quote
    JS
    Participant
    Senior

    ta.stoch(source, high, low, length)

    As you can see, the period for the average is not specified in the Pine Script formula…

    Normally you keep 1 for a fast stochastic and 3 or 5 for a slower…

    #218302 quote
    pabo_swe
    Participant
    Junior
    Thanks for the input! I think I found a Pine Script example that’s more compatible with the PRT way… …it looks like the smoothing is normally implemented this way in pine: periodK = 14 smoothK = 3 k = ta.sma(ta.stoch(close, high, low, periodK), smoothK) Could I then assume that using K=1 in the PRT code would “switch off” the smoothing, right?
    #218303 quote
    JS
    Participant
    Senior

    That’s right, when you use K=1 there is no “smoothing”…

    #218304 quote
    pabo_swe
    Participant
    Junior
    Thanks!
    JS thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Stochastic, PRT vs Pine script


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
pabo_swe @pabo_swe Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by pabo_swe
2 years, 6 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 07/29/2023
Status: Active
Attachments: No files
Logo Logo
Loading...