Schaff Trend Cycle TOS to PRT Conversion
Forums › ProRealTime English forum › ProBuilder support › Schaff Trend Cycle TOS to PRT Conversion
- This topic has 11 replies, 3 voices, and was last updated 1 week ago by
gp38super.
-
-
02/13/2025 at 12:05 PM #243766
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
through100
depending on a price. If the price is the lowest for the lastlength
bars then0
is returned. If the price is the highest for the lastlength
bars then100
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
02/13/2025 at 12:07 PM #24376802/13/2025 at 12:43 PM #243776Hi,
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)…?02/13/2025 at 1:01 PM #243777Hi. 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.
02/13/2025 at 2:49 PM #243779Hi,
Hereby the conversion of the TOS script:
Schaff Trend Cycle TOS123456789101112131415161718192021222324252627282930//SettingsfastLength = 23slowLength = 50KPeriod = 10DPeriod = 3overBought = 75overSold = 25AvgType=1 //Exponential Moving Average// Berekening van de MACDfastMA = Average[fastLength,1](close)slowMA = Average[slowLength,1](close)xmacd = fastMA - slowMA// STC-calculationIf Highest[KPeriod](xmacd)-Lowest[KPeriod](xmacd)>0 thenfastK1 = (xmacd - Lowest[KPeriod](xmacd)) / (Highest[KPeriod](xmacd) - Lowest[KPeriod](xmacd))*100elsefastK1=0EndIffastD1 = Average[DPeriod,1](fastK1)If Highest[KPeriod](fastD1)-Lowest[KPeriod](fastD1)>0 thenfastK2 = (fastD1 - Lowest[KPeriod](fastD1)) / (Highest[KPeriod](fastD1) - Lowest[KPeriod](fastD1))*100elsefastK2=0EndIfSTC = Average[DPeriod,1](fastK2)// PlottingRETURN STC AS "STC", overBought AS "OverBought", overSold AS "OverSold"2 users thanked author for this post.
02/13/2025 at 3:04 PM #243780with the colours:
Schaff TOS12345678910111213141516171819202122232425262728293031323334353637383940//SettingsfastLength = 23slowLength = 50KPeriod = 10DPeriod = 3overBought = 75overSold = 25AvgType=1 //Exponential Moving Average// Berekening van de MACDfastMA = Average[fastLength,AvgType](close)slowMA = Average[slowLength,AvgType](close)xmacd = fastMA - slowMA// STC-calculationIf Highest[KPeriod](xmacd)-Lowest[KPeriod](xmacd)>0 thenfastK1 = (xmacd - Lowest[KPeriod](xmacd)) / (Highest[KPeriod](xmacd) - Lowest[KPeriod](xmacd))*100elsefastK1=0EndIffastD1 = Average[DPeriod,AvgType](fastK1)If Highest[KPeriod](fastD1)-Lowest[KPeriod](fastD1)>0 thenfastK2 = (fastD1 - Lowest[KPeriod](fastD1)) / (Highest[KPeriod](fastD1) - Lowest[KPeriod](fastD1))*100elsefastK2=0EndIfSTC = Average[DPeriod,AvgType](fastK2)If STC>STC[1] thenR=0G=255B=0ElseR=255G=0B=0EndIf// PlottingRETURN STC AS "STC" Coloured(R,G,B), overBought AS "OverBought", overSold AS "OverSold"02/13/2025 at 5:59 PM #243791Hi. 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 ?02/13/2025 at 6:07 PM #243795The 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.
02/13/2025 at 6:58 PM #243798This 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!
02/13/2025 at 7:22 PM #24380002/13/2025 at 7:34 PM #24380302/13/2025 at 8:11 PM #243804 -
AuthorPosts
Find exclusive trading pro-tools on