Schaff Trend Cycle TOS to PRT Conversion

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #243766 quote
    gp38super
    Participant
    New

    Hi. I’ve spent hours trying to convert this code myself, but have a LOT more learning to do. I’ve tried MANY STCs, but the input variables of this one work best for my preferences. It works perfectly as is, however, the only thing I’ve seen different that might be great to add, was a screenshot I included of a protected pine script that appears to change line color at the break of the trend.  TOS image below shows variable settings (16,35,5,3,85,17,Wilders) and green indicator line. The pine script image is the red and white indicator line. Again, this one was protected, so I couldn’t get any more detail on it. Thanks, in advance!

    ___________________________________________________________________________________________

    Thinkscript:

    input fastLength = 23;
    input slowLength = 50;
    input KPeriod = 10;
    input DPeriod = 3;
    input over_bought = 75;
    input over_sold = 25;
    input averageType = AverageType.EXPONENTIAL;

    def macd = MovingAverage(averageType, close, fastLength) – MovingAverage(averageType, close, slowLength);
    def fastK1 = FastKCustom(macd, KPeriod);
    def fastD1 = MovingAverage(averageType, fastK1, DPeriod);
    def fastK2 = FastKCustom(fastD1, KPeriod);
    plot STC = MovingAverage(averageType, fastK2, DPeriod);
    plot OverBought = over_bought;
    plot OverSold = over_sold;

    STC.SetDefaultColor(GetColor(8));
    OverBought.SetDefaultColor(GetColor(7));
    OverSold.SetDefaultColor(GetColor(7));

    ________________________________________________________________________________________

    This is what I found to work with or define FastKCustom:

    FastKCustom


    FastKCustom ( IDataHolder data , int length );

    Default values:

    length: 14

    Description

    Returns values from 0 through 100 depending on a price. If the price is the lowest for the last length bars then 0 is returned. If the price is the highest for the last lengthbars then 100 is returned.

    The function is calculated according to the following algorithm:

    FastKCustom = if Highest(close, 12) - Lowest(close, 12) > 0 then (close - Lowest(close, 12)) / (Highest(close, 12) - Lowest(close, 12))*100 else 0

    #243768 quote
    gp38super
    Participant
    New

    Had trouble adding 2nd image of pinescript version referenced above

    #243776 quote
    JS
    Participant
    Senior

    Hi,
    Did you know that there is a “Schaff Trend Cycle” indicator available in the library…?
    https://www.prorealcode.com/prorealtime-indicators/schaff-trend-cycle2/
    If this one doesn’t meet your needs, what would you like to change (besides the possible color)…?

    #243777 quote
    gp38super
    Participant
    New
    Hi. Yes, i did see those. I played with whar limited variables they offered, and they are ver limited by comparison to the TOS version i use. As you can see in my image provided, I able to adjust to an almost exact match to other indicators(I know they use a lot of similar data in their makeup). Being able to adjust the various variables, I am also able to tune out “noise” in the signal. Additionally, the ease of tweaking settings to various timeframes is also critical to my trading preferences. But thank you for pointing that out.
    #243779 quote
    JS
    Participant
    Senior
    Hi, Hereby the conversion of the TOS script:
    //Settings
    fastLength = 23
    slowLength = 50
    KPeriod = 10
    DPeriod = 3
    overBought = 75
    overSold = 25
    AvgType=1 //Exponential Moving Average
    
    // Berekening van de MACD
    fastMA = Average[fastLength,1](close)
    slowMA = Average[slowLength,1](close)
    xmacd = fastMA - slowMA
    
    // STC-calculation
    If Highest[KPeriod](xmacd)-Lowest[KPeriod](xmacd)>0 then
    fastK1 = (xmacd - Lowest[KPeriod](xmacd)) / (Highest[KPeriod](xmacd) - Lowest[KPeriod](xmacd))*100
    else 
    fastK1=0
    EndIf
    fastD1 = Average[DPeriod,1](fastK1)
    If Highest[KPeriod](fastD1)-Lowest[KPeriod](fastD1)>0 then
    fastK2 = (fastD1 - Lowest[KPeriod](fastD1)) / (Highest[KPeriod](fastD1) - Lowest[KPeriod](fastD1))*100
    else
    fastK2=0
    EndIf
    STC = Average[DPeriod,1](fastK2)
    
    // Plotting
    RETURN STC AS "STC", overBought AS "OverBought", overSold AS "OverSold"
    robertogozzi and gp38super thanked this post
    #243780 quote
    JS
    Participant
    Senior
    with the colours:
    //Settings
    fastLength = 23
    slowLength = 50
    KPeriod = 10
    DPeriod = 3
    overBought = 75
    overSold = 25
    AvgType=1 //Exponential Moving Average
    
    // Berekening van de MACD
    fastMA = Average[fastLength,AvgType](close)
    slowMA = Average[slowLength,AvgType](close)
    xmacd = fastMA - slowMA
    
    // STC-calculation
    If Highest[KPeriod](xmacd)-Lowest[KPeriod](xmacd)>0 then
    fastK1 = (xmacd - Lowest[KPeriod](xmacd)) / (Highest[KPeriod](xmacd) - Lowest[KPeriod](xmacd))*100
    else
    fastK1=0
    EndIf
    fastD1 = Average[DPeriod,AvgType](fastK1)
    If Highest[KPeriod](fastD1)-Lowest[KPeriod](fastD1)>0 then
    fastK2 = (fastD1 - Lowest[KPeriod](fastD1)) / (Highest[KPeriod](fastD1) - Lowest[KPeriod](fastD1))*100
    else
    fastK2=0
    EndIf
    STC = Average[DPeriod,AvgType](fastK2)
    
    If STC>STC[1] then
    R=0
    G=255
    B=0
    Else
    R=255
    G=0
    B=0
    EndIf
     
    // Plotting
    RETURN STC AS "STC" Coloured(R,G,B), overBought AS "OverBought", overSold AS "OverSold"
    #243791 quote
    LaMaille
    Participant
    Junior
    Hi. I’ve spent hours trying to convert this code myself, but have a LOT more learning to do. I’ve tried MANY STCs, but the input variables of this one work best for my preferences. It works perfectly as is, however, the only thing I’ve seen different that might be great to add, was a screenshot I included of a protected pine script that appears to change line color at the break of the trend. TOS image below shows variable settings (16,35,5,3,85,17,Wilders) and green indicator line. The pine script image is the red and white indicator line. Again, this one was protected, so I couldn’t get any more detail on it. Thanks, in advance!
    Is it RocketScalper on the Price ? Do you have the code of it ?
    #243795 quote
    gp38super
    Participant
    New
    The Thinkorswim code I pasted above is the code I’m looking to duplicate. I’ve only played with it a few minutes so far, but the code provided by JS above, “with colours”, is about as SUPER close, and the color tweaks are GREAT. Just need to maybe set the variables up to be able to adjust minutely for different time frames and spen a little more time comparing the results. ALSO: THANK YOU ALL for the help. Your efforts are more than generous, and greatly appreciated.
    #243798 quote
    gp38super
    Participant
    New
    This is stellar! Thank you! I am working on getting those beginning settings  set up as changeable variables. I manually adjusted the settings to match my preferred settings, and they look super close to matching my current use with TOS script. I’m still very green with ProRealCode, so if you get to making those changes to adding the variables before I do, I won’t be upset. 🙂 Thanks again!
    #243800 quote
    JS
    Participant
    Senior
    When you import the “ITF file” (Indicators), you can then configure the parameters under “Settings”…
    gp38super thanked this post
    #243803 quote
    gp38super
    Participant
    New
    Awesome. I previously copied and pasted. Got it now.
    JS thanked this post
    #243804 quote
    gp38super
    Participant
    New
    EXCELLENT!! Thanks again.
    JS thanked this post
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Schaff Trend Cycle TOS to PRT Conversion


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
gp38super @gp38super Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by gp38super
11 months, 4 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/13/2025
Status: Active
Attachments: 4 files
Logo Logo
Loading...