Dear Friends,
The script appended below continuously assigns bullish/bearish colors to stocks in a watch list (the script is an amalgamation of ideas gleaned from posts and conversions by the legendary Sam4Cok@Samer800).
I would like to record the date and time in the fifth column of the watch list each time a color change occurs for a given stock (kindly see the empty fifth column in the attached picture). This way, I can tell how long the current color has been active. Any assistance would be highly appreciated.
God bless you all!
The script appended below continuously assigns bullish/bearish colors to stocks in a watch list (the script is an amalgamation of ideas gleaned from posts and conversions by the legendary Sam4Cok@Samer800).
I would like to record the date and time in the fifth column of the watch list each time a color change occurs for a given stock (kindly see the empty fifth column in the attached picture). This way, I can tell how long the current color has been active. Any assistance would be highly appreciated.
God bless you all!
Ruby:
Declare lower;
input BarColor = yes;
input showSignals = yes;
input MovAvgType = AverageType.EXPONENTIAL;
input length = 5;
input lookback = 5;
input ema1_len = 3;
input ema2_len = 8;
input ema3_len = 13;
def na = Double.NaN;
def ys1 = (high + low + close * 2) / 4;
def rk3 = MovingAverage(MovAvgType, ys1, length);
def rk4 = stdev(ys1, length);
def rk5 = (ys1 - rk3) * 100 / rk4;
def rk6 = MovingAverage(MovAvgType, rk5, length);
def up = MovingAverage(MovAvgType, rk6, length);
def down = MovingAverage(MovAvgType, up, length);
def Buy = Crosses(up, down, CrossingDirection.ABOVE);
def Sell = Crosses(up, down, CrossingDirection.BELOW);
def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);
def ema3 = MovAvgExponential(length=ema3_len);
#def ema1 = SimpleMovingAvg(length=ema1_len);
#def ema2 = SimpleMovingAvg(length=ema2_len);
#def ema3 = SimpleMovingAvg(length=ema3_len);
def bull_cross = ema1 crosses above ema2 and ema1 crosses above ema3 and ema2 crosses above ema3;
def bear_cross = ema1 crosses below ema2 and ema1 crosses below ema3 and ema2 crosses below ema3;
def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);
def S1 = Buy and bull_lookback;
def S2 = Buy and !bull_lookback;
def S3 = Sell and bear_lookback;
def S4 = Sell and !bear_lookback;
plot signal = if S1 then 4 else if S2 then 3 else if S3 then 2 else if S1 then 1 else 0;
signal.AssignValueColor(if signal == 4 then Color.Dark_Green else if signal == 3 then Color.Green else if signal == 1 then Color.Red else if signal == 2 then Color.Dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if signal == 4 then Color.Dark_Green else if signal == 3 then Color.Green else if signal == 1 then Color.Red else if signal == 2 then Color.Dark_Red else Color.Dark_Orange);
Last edited by a moderator: