Relative Strength MA and Stochastic Conditions


Category:
0
0

Hi Pete,

I had a previous question on the following Relative Strenght MA in this post https://www.hahn-tech.com/ans/relative-strength-ma-buysell-order/

Your help was appreciated!

I’m trying to use it as a condition in a watchlist with the stochastic .

Bullish Relative Strength MA and Stochastic would be in green, bearish in red and neutral is current.

But i get a few “Can not call setDefaultColor” , could you help ?

Also, when should plot statement be replaced with def and if yes why ?

#Stochastic
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMacd = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMacd).Diff;

def slowMA = SimpleMovingAvg(“length” = 150).SMA[0];
def fastMA = SimpleMovingAvg(“length” = 10).SMA;

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

def SlowK = reference
StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def SlowD = reference
StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;

#Relative Strength
input CorrelationWithSecurity = “SPX”;
input averageType = AverageType.EXPONENTIAL;
input length = 21;
def close2 = close(CorrelationWithSecurity);
plot RS = if close2 == 0 then 0 else close/close2;
RS.setDefaultColor(GetColor(6));
def sr = CompoundValue(“historical data” = RS, “visible data” = if isNaN(sr[1]) then RS else sr[1]);
plot SRatio = sr;
SRatio.setDefaultColor(GetColor(5));
plot ma = MovingAverage(averageType, RS, length);

plot value= if ma [0]> ma [1] and (SlowK > SlowD) then 1 else if ma [0] < ma [1] and (SlowK < SlowD) then -1 else 0 ;

AssignBackgroundColor (if 1 then Color.GREEN else if -1 then Color.RED else color.current);

Thank’s  !

 

Marked as spam
Posted by (Questions: 5, Answers: 3)
Asked on April 17, 2020 3:23 am
134 views
0
Private answer

So you are trying to place this in a custom watchlist column, yes? Only one plot statement is permitted in a custom watchlist column. So pick the value you want to display and leave that one as the plot and change all the others to def. You will also need to remove all the style statements for those plots to change to def.

"...cannot call setDefaultColor...". This is also not supported in custom watchlist columns so you have to remove that too.

Your attempt to set the background color is completely non-functional:

AssignBackgroundColor (if 1 then Color.GREEN else if -1 then Color.RED else color.current);

(if 1 then color else if -1 then color)? That doesn't do anything at all. Perhaps you intended to say this:

AssignBackgroundColor (if value == 1 then Color.GREEN else if value == -1 then Color.RED else color.current);

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on April 17, 2020 7:43 am