Schaff Trend Cycle


0
0

Hi Pete is there a way i can get a signal on Schaff Trend Cycle oversold below 25 from flat then move slight bend upward then overbought 75 flat then move slight bend downward? the picture is included thank you

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 27, 2018 10:22 pm
900 views
0

declare lower;

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));

( at June 27, 2018 10:30 pm)
0
Private answer

We don’t need any code to build this. Very simple things like this can almost always be constructed using the Condition Wizard. Three screenshots below show how to construct “STC greater than 75 then turning lower”

You should be able to construct the other signal once you understand how to build this one.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 28, 2018 7:34 am
0

Hi Pete it works perfect! thank you so much.

( at June 28, 2018 9:34 am)
0

Hi Pete can i add a color if the custom watchlist turn “1” into green? i tried to put color but im getting invalid.

SchaffTrendCycle(“over bought” = 80, “over sold” = 20).”STC”
is greater than SchaffTrendCycle(“over bought” = 80, “over sold” = 20).
“STC” from 1 bars ago and SchaffTrendCycle(“over bought” = 80, “over sold” = 20).
“STC” from 1 bars ago is less than 20

assignbackgroundcolor(if plot data = 1 then color.GREEN else);

( at August 10, 2018 12:17 pm)
0

Wow, I am glad you made the attempt but you are long way off. Let’s cover each point of failure so you can learn and understand how to accomplish this on your own.

1. The code you pulled from the condition wizard. That needs to be the value displayed in the watchlist column. Your code has no way to achieve that. So you need to apply that code to a plot statement. Something along lines of:

plot data = SchaffTrendCycle(“over bought” = 80, “over sold” = 20).”STC”
is greater than SchaffTrendCycle(“over bought” = 80, “over sold” = 20).
“STC” from 1 bars ago and SchaffTrendCycle(“over bought” = 80, “over sold” = 20).
“STC” from 1 bars ago is less than 20;

Pay close attention to what I did. I added “plot data = ” to the beginning of your code. Then I added a semicolon ‘;’ at the end. That makes it a complete statement, and assigns the output of your condition to the value displayed in the watchlist column.

2. Next, you need to fix more than one error in the statement that assigns the background color:

AssignBackgroundColor(if data == 1 then Color.GREEN else Color.CURRENT);

First step was to change “assignbackgroundcolor” to “AssignBackgroundColor”. Your version of that was not causing any errors. And would have worked fine if all the other items had been fixed. But it is very important you follow the style guidelines. This is called “camel case”. This is when you capitalize the first letter of each word in a method or variable name. This makes your code easier to read and reduces chances of one item being mistaken for another. Since this is a system method the first character is capitalized too. User defined variables always begin with a lower case letter.

Next, we need to use double equal signs in the if condition. Single equal sign is for assignments, such as “set variable x is equal to 1”: def x = 1;
Double equal signs are required when checking for equality between two elements. Such as “If variable x equal to 1”: if x == 1

Lastly, your if/then/else statement was missing the final value. Which in this case I have used Color.CURRENT. (notice the word color in this case begins with a capital letter because it is a system Constant).

Hope that all makes sense.

( at August 10, 2018 12:44 pm)
0

Thank you Pete. You’re the best

( at August 10, 2018 1:23 pm)