I'm utilizing the following two studies on a single time frame's chart. I'm wondering if the first study can influence the colored line of the second study? If so, how do I accomplish that? More specifically, when the cloud from the first study is green, for example, can I make it so the line of second study stays green despite a pullback (where it would normally turn red) in the chart; and only change to red when the green cloud disappears? Many thanks.
First Study:
Second Study:
First Study:
Code:
#AAAStudyMyedits#
input ATRLength = 2;
input ATRMultiplier = 1;
input ShowLabels = yes;
input UseClose = no;
input HighlightState = yes;
input Alerts = yes;
def atr = ATRMultiplier * ATR(ATRLength);
def longStop = (if UseClose then Highest(close, ATRLength) else Highest(high, ATRLength)) - atr;
def longStopPrev = if IsNaN(longStop[1]) then longStop else longStop[1];
def LS = if close[1] > longStopPrev then Max(longStop, longStopPrev) else longStop;
def shortStop = (if UseClose then Lowest(close, ATRLength) else Lowest(low, ATRLength)) + atr;
def shortStopPrev = if IsNaN(shortStop[1]) then shortStop else shortStop[1];
def SS = if close[1] < shortStopPrev then Min(shortStop, shortStopPrev) else shortStop;
def dir = if close > shortStopPrev then 1 else if close < longStopPrev then -1 else dir[1];
def direction = dir;
plot LongStopPlot = if direction == 1 then LS else Double.NaN;
LongStopPlot.SetDefaultColor(Color.GREEN);
plot ShortStopPlot = if direction == -1 then SS else Double.NaN;
ShortStopPlot.SetDefaultColor(Color.RED);
def midPricePlot = OHLC4;
def callentrySignal = direction == 1 and direction[1] == -1;
def putentrySignal = direction == -1 and direction[1] == 1;
AddChartBubble(callentrySignal and ShowLabels, low, "C-In", Color.GREEN, no);
AddChartBubble(putentrySignal and ShowLabels, high, "P-In", Color.RED, yes);
AddCloud(if direction == 1 and HighlightState then LongStopPlot else Double.NaN, if direction == 1 and HighlightState then midPricePlot else Double.NaN, Color.LIGHT_GREEN , Color.LIGHT_GREEN, no);
AddCloud(if direction == -1 and HighlightState then ShortStopPlot else Double.NaN, if direction == -1 and HighlightState then midPricePlot else Double.NaN, Color.LIGHT_RED, Color.LIGHT_RED, no);
Alert(direction == 1 and direction[1] == -1 and Alerts, "Call", Alert.ONCE, Sound.Ding);
Alert(direction == -1 and direction[1] == 1 and Alerts, "Put", Alert.ONCE, Sound.Ding);
Second Study:
Code:
#thinkscript.com#
#by Ramesh16#
input displace = 0;
input length = 1;
input price = ohlc4;
input movingAverageType = {default Simple, Exponential, Weighted, Hull, Variable};
rec data;
switch (movingAverageType) {
case Simple:
data = CompoundValue(1, Average(price[-displace], length), price);
case Exponential:
data = CompoundValue(1, ExpAverage(price[-displace], length), price);
case Weighted:
data = CompoundValue(1, WMA(price[-displace], length), price);
case Hull:
data = CompoundValue(1, HullMovingAvg(price[-displace], length), price);
case Variable:
data = VariableMA(price = price, length = length);
}
plot ave = data;
ave.SetLineWeight(3);
ave.AssignValueColor(if ave > ave[1] then Color.GREEN else Color.RED);
ave.HideBubble();
def lastbar = IsNaN(close[-1]) and !IsNaN(close);
#AddChartBubble(lastbar, data, "MA" + Length, Color.DARK_ORANGE);
Last edited: