Assignbackgroundcolor based on Stochastics Fullk greater than fullD


Category:
0
0

Pete

i am baffled.  I have tried and tried to assign the back ground color in a watchlist based on Stochastics fullk greater than FullD.   Should be simple.  Following is the code i used and i keep getting the message…Exaclty one plot expected.  Done everything i know….nothing works.  If you can help i will be glad to make a conribution.  Thanks much

 

Doug

 

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC – lowest_k;
def c2 = Highest(priceH, KPeriod) – lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;

FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));

AssignPriceColor (if Fullk > FullD then color.green else color.red);

 

RESOLVED
Marked as spam
Posted by (Questions: 10, Answers: 11)
Asked on March 7, 2017 7:49 am
1120 views
0
Private answer

You were very close. Great job. When you saw the error, “exactly one plot expected”, did you go through your code and count how many plots where there? I counted four. Only one is allowed for a watchlist but which one do you leave? To keep it simple, none of them.

I took the first two that are named FullK and FullD and changed them from plot to def. This is because we need those values so we can’t simply delete those lines or comment them out. Then I commented out the OverBought and OverSold because you are not using them. This creates a bunch of new errors, because for each plot there are style statements. Those style statements need to be taken out of the code. I used comment marks to turn them off so you can see what changes were required to get your code working.

There was also a problem with the method you used to set the background color. You were trying to set the price color, which is only applicable in a chart. So I commented out your AssignPriceColor statements and replaced it with AssignBackgroundColor. At the very end, we still need to have exactly one plot. So in the last line I create a plot, called value, and assign it’s value to the FullK.

Here is you code with these changes applied. Screenshot included to show what it looks like. Don’t forget to up-vote any answers the best solve your question!

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC – lowest_k;
def c2 = Highest(priceH, KPeriod) – lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
#plot OverBought = over_bought;
#plot OverSold = over_sold;
#FullK.SetDefaultColor(GetColor(5));
#FullD.SetDefaultColor(GetColor(0));
#OverBought.SetDefaultColor(GetColor(1));
#OverSold.SetDefaultColor(GetColor(1));
#AssignPriceColor (if Fullk > FullD then color.green else color.red);
AssignBackgroundColor(if Fullk > FullD then color.green else color.red);
plot value = FullK;

 

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 7, 2017 9:05 am
0
Hello, this is the exact script that I'm looking for but how do I change the text to black so it would be more visible on green background. Thanks
( at January 12, 2021 6:11 pm)
0
Add the following line to the solution I provide above: value.SetDefaultColor(Color.BLACK);
( at January 12, 2021 10:21 pm)
0
Private answer

Thank you…would never have figured that out.  I will be happy to make a contribution!

Marked as spam
Posted by (Questions: 10, Answers: 11)
Answered on March 7, 2017 10:46 am
0

Glad I could help. Thanks for your contribution!

( at March 7, 2017 10:53 am)