stoneybucks
New member
Hi All, I've been working on customizing some of the included TOS candlestick patterns (option to add alerts and modifying the identifiers) and would like to try to get them all into one study instead of individual ones. I'm still a bit new to coding in TOS, and have been able to make the desired customizations in 25 individual studies. Currently stuck at how to map the duplicate inputs, candle conditions, and assert factors properly once they are all put into 1 study. Below are the 25 individual studies listed as one. Wondering if any could take the lead/guide the way as to how to best mash this all together for an All-in-One study? Thanks in advance for any help! - Stoneybucks
For reference, here are the 25 patterns listed:
	
		
	
		
			
		
		
	
				
			For reference, here are the 25 patterns listed:
- Hammer
- Shooting Star
- Doji
- Long-Legged Doji
- Bullish Engulfing
- Bearish Engulfing
- Bullish Piercing
- Dark Cloud Cover
- Two Crows
- In Neck
- On Neck
- One White Soldier
- One Black Crow
- Morning Star
- Evening Star
- Morning Doji Star
- Evening Doji Star
- Three White Soldiers
- Three Black Crows
- Three Inside Up
- Three Inside Down
- Three Outside Up
- Three Outside Down
- Identical Three Crows
- Stick Sandwich
		Code:
	
	###################################################
############ One Candlestick ##################
###################################################
##Hammer - Bullish Reversal, Red Circle Under ##
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input shadowFactor = 2.0;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);
def BodyHeight = BodyHeight();
def AverageBodyHeight = Average(BodyHeight, length);
def ErrMargin = 0.05 * AverageBodyHeight;
def IsShort = BodyHeight < bodyFactor * AverageBodyHeight;
def Bullish = IsDescending(close, 3) and
    IsShort and
    high - Max(open, close) <= ErrMargin and
    Min(open, close) - low > 2.0 * BodyHeight;
plot BullishPlot = if Bullish then (low) else Double.NAN;
BullishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
BullishPlot.SetDefaultColor(color.light_red);
BullishPlot.SetLineWeight(1);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “HAMMER", Alert.BAR, Sound.Bell);
##Shooting Star - Bearish Reversal, Red Circle Above ##
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input shadowFactor = 2.0;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);
def BodyHeight = BodyHeight();
def AverageBodyHeight = Average(BodyHeight, length);
def ErrMargin = 0.05 * AverageBodyHeight;
def IsShort = BodyHeight < bodyFactor * AverageBodyHeight;
def Bearish = IsAscending(close, trendSetup)[1] and
    open[1] < close[1] and
    low > high[1] and
    IsShort and
    Min(open, close) - low <= ErrMargin and
    high - Max(open, close) > shadowFactor * BodyHeight;
plot BearishPlot = if Bearish then (high + 0.3) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “SHOOTING STAR", Alert.BAR, Sound.Bell);
## Doji - Indecision/Trend Exhaustion, Purple Circle at Close ##
input length = 20;
input bodyFactor = 0.05;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
plot Doji = IsDoji(length, bodyFactor);
Doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Doji.SetDefaultColor(CreateColor(153, 153, 255));
Doji.SetLineWeight(3);
Doji.hidebubble();
Doji.hidetitle();
Alert(Doji && !TurnAlertOff, "DOJI", Alert.Bar, Sound.Bell);
## Long-legged Doji - Indecision/Trend Exhaustion, Purple Circle at Close ##
input length = 20;
input trendSetup = 2;
input shadowFactor = 0.75;
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);
def ShadowHeight = shadowFactor * Average(BodyHeight(), length);
def IsLongShadows = high - Max(open, close) > ShadowHeight and
    Min(open, close) - low > ShadowHeight;
def IsDoji = IsDoji(length);
plot Bearish = IsAscending(MidBodyVal(), trendSetup) and
    IsDoji and
    IsLongShadows;
plot Bullish = IsDescending(MidBodyVal(), trendSetup) and
    IsDoji and
    IsLongShadows;
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Bearish.SetDefaultColor(color.dark_red);
Bearish.SetLineWeight(2);
Bearish.hidebubble();
Bearish.hidetitle();
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Bullish.SetDefaultColor(color.dark_green);
Bullish.SetLineWeight(2);
Bullish.hidebubble();
Bullish.hidetitle();
###################################################
############ Two Candlesticks ##################
###################################################
##Bullish & Bearish Engulfing - Bullish/BearishReversal, Paint Magenta/Violet ##
input length = 20;
input trendSetup = 3;
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];
plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;
plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;
assignpriceColor(if Bearish then Color.VIOLET else if Bullish then Color.MAGENTA else Color.Current);
AddLabel(yes,"Bu_Engulf",color.MAGENTA);
AddLabel(yes,"Be_Engulf",color.VIOLET);
Alert(Bullish or Bearish, if Bullish then "BULL" else "BEAR", Alert.BAR, Sound.Ding);
##Bullish Piercing - Bullish Reversal, Red Boolean Wedge Under ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bullish = IsDescending(close, trendSetup)[1] and
    IsLongBlack(length)[1] and
    open < low[1] and
    close > MidBodyVal()[1] and
    close < open[1];
plot BullishPlot = if Bullish then (low) else Double.Nan;
BullishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
BullishPlot.SetDefaultColor(COLOR.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “BULLISH PIERCING", Alert.BAR, Sound.Bell);
##Dark Cloud Cover - Bearish Reversal, Red Boolean Wedge Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bearish = IsAscending(close, trendSetup)[1] and
    IsLongWhite(length)[1] and
    open > high[1] and
    close < MidBodyVal()[1] and
    close > open[1];
plot BearishPlot = if bearish then (high) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “DARK CLOUD COVER", Alert.BAR, Sound.Bell);
##Two Crows - Bearish Reversal, Red Boolean Wedge Above ##
input length = 20;
input trendSetup = 2;
input TurnAlertOff = yes;
def Bearish = IsAscending(close, trendSetup)[2] and
    IsLongWhite(length)[2] and
    low[1] > high[2] and
    open < open[1] and
    open > close[1] and
    close < close[2] and
    close > open[2];
plot BearishPlot = if bearish then (high) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “TWO CROWS", Alert.BAR, Sound.Bell);
##In Neck - Bearish Continuation, Cyan Boolean Wedge Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def ErrMargin = 0.05 * Average(BodyHeight(), length);
def closeDiff = close - close[1];
def Bearish = isDescending(close, trendSetup)[1] and
    IsLongBlack(length)[1] and
    open < low[1] and
    closeDiff >= 0 and
    closeDiff <= ErrMargin;
plot BearishPlot = if bearish then (high) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BearishPlot.SetDefaultColor(color.cyan);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “IN NECK", Alert.BAR, Sound.Bell);
##On Neck - Bearish Continuation, Cyan Boolean Wedge Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def ErrMargin = 0.05 * Average(BodyHeight(), length);
def Bearish = IsDescending(close, trendSetup)[1] and
    IsLongBlack(length)[1] and
    open < close and
    open < low[1] and
    AbsValue(close - low[1]) <= ErrMargin;
plot BearishPlot = if bearish then (high) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BearishPlot.SetDefaultColor(color.cyan);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “ON NECK", Alert.BAR, Sound.Bell);
##One White Soldier - Bullish Reversal, Red Boolean Wedge Under ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bullish = IsDescending(open, trendSetup)[1] and
    IsLongBlack(length)[1] and
    IsLongWhite(length) and
    open > close[1] and
    open < open[1] and
    close > open[1];
plot BullishPlot = if Bullish then (low) else Double.Nan;
BullishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
BullishPlot.SetDefaultColor(COLOR.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “ONE WHITE SOLDIER", Alert.BAR, Sound.Bell);
##One Black Crow - Bearish Reversal, Red Boolean Wedge Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bearish = IsAscending(open, trendSetup)[1] and
    IsLongWhite(length)[1] and
    IsLongBlack(length) and
    open < close[1] and
    open > open[1] and
    close < open[1];
plot BearishPlot = if bearish then (high) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “ONE BLACK CROW”, Alert.BAR, Sound.Bell);
###################################################
############ Three Candlesticks ##################
###################################################
##Morning Star - Bullish Reversal, Red Triangle Under ##
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
def BodyHeight = BodyHeight();
def IsShort = BodyHeight < bodyFactor * Average(BodyHeight, length);
def Bullish = IsDescending(close, trendSetup)[2] and
    IsLongBlack(length)[2] and
    IsShort[1] and
    high[1] < low[2] and
    open < close and
    close > MidBodyVal()[2];
plot BullishPlot = if Bullish then (low) else Double.NAN;
BullishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BullishPlot.SetDefaultColor(color.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “MORNING STAR", Alert.BAR, Sound.Bell);
##Evening Star - Bearish Reversal, Red Triangle Above ##
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
def BodyHeight = BodyHeight();
def IsShort = BodyHeight < bodyFactor * Average(BodyHeight, length);
def Bearish = IsAscending(close, trendSetup)[2] and
    IsLongWhite(length)[2] and
    IsShort[1] and
    low[1] > high[2] and
    open > close and
    close < MidBodyVal()[2];
plot BearishPlot = if Bearish then (high) else Double.NAN;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “EVENING STAR", Alert.BAR, Sound.Bell);
##Morning Doji Star - Bullish Reversal, Red Triangle Under ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bullish = IsDescending(close, trendSetup)[2] and
    IsLongBlack(length)[2] and
    IsDoji(length)[1] and
    high[1] < low[2] and
    open < close and
    close > MidBodyVal()[2];
plot BullishPlot = if Bullish then (low) else Double.NAN;
BullishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BullishPlot.SetDefaultColor(color.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “MORNING DOJI STAR", Alert.BAR, Sound.Bell);
##Evening Doji Star - Bearish Reversal, Red Triangle Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bearish = IsAscending(close, trendSetup)[2] and
    IsLongWhite(length)[2] and
    IsDoji(length)[1] and
    low[1] > high[2] and
    open > close and
    close < MidBodyVal()[2];
plot BearishPlot = if Bearish then (high) else Double.NAN;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “EVENING DOJI STAR", Alert.BAR, Sound.Bell);
##Three White Soldiers - Bullish Reversal, Red Triangle Under ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def IsLongWhite = IsLongWhite(length);
def IsOpenWithinBody = open > open[1] and
    open < close[1];
def IsCloseHigher = close > close[1];
def Bullish = IsDescending(open, trendSetup)[2] and
    IsLongWhite[2] and
    IsLongWhite[1] and
    IsLongWhite and
    IsCloseHigher[1] and
    IsCloseHigher and
    IsOpenWithinBody[1] and
    IsOpenWithinBody;
plot BullishPlot = if Bullish then (low) else Double.NAN;
BullishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BullishPlot.SetDefaultColor(color.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “THREE WHITE SOLDIERS”, Alert.BAR, Sound.Bell);
##Three Black Crows - Bearish Reversal, Red Triangle Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def IsLongBlack = IsLongBlack(length);
def IsOpenWithinBody = open > close[1] and
    open < open[1];
def IsCloseLower = close < close[1];
def Bearish = IsAscending(open, trendSetup)[2] and
    IsLongBlack[2] and
    IsLongBlack[1] and
    IsLongBlack and
    IsCloseLower[1] and
    IsCloseLower and
    IsOpenWithinBody[1] and
    IsOpenWithinBody;
plot BearishPlot = if Bearish then (high) else Double.NAN;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “THREE BLACK CROWS", Alert.BAR, Sound.Bell);
##Three Inside Up - Bullish Reversal, Red Triangle Under ##
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
def Bullish = Harami(length, trendSetup, bodyFactor).Bullish[1] and
    open < close and
    close > close[1];
plot BullishPlot = if Bullish then (low) else Double.NAN;
BullishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BullishPlot.SetDefaultColor(color.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “THREE INSIDE UP”, Alert.BAR, Sound.Bell);
##Three Inside Down - Bearish Reversal, Red Triangle Above ##
input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input TurnAlertOff = yes;
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
def Bearish = Harami(length, trendSetup, bodyFactor).Bearish[1] and
    open > close and
    close < close[1];
plot BearishPlot = if Bearish then (high) else Double.NAN;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “THREE INSIDE DOWN", Alert.BAR, Sound.Bell);
##Three Outside Up - Bullish Reversal, Red Triangle Under ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bullish = Engulfing(length, trendSetup).Bullish[1] and
    open < close and
    close > close[1];
plot BullishPlot = if Bullish then (low) else Double.NAN;
BullishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BullishPlot.SetDefaultColor(color.light_red);
BullishPlot.SetLineWeight(2);
BullishPlot.hidebubble();
BullishPlot.hidetitle();
Alert(Bullish && !TurnAlertOff, “THREE OUTSIDE UP”, Alert.BAR, Sound.Bell);
##Three Outside Down - Bearish Reversal, Red Triangle Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def Bearish = Engulfing(length, trendSetup).Bearish[1] and
    open > close and
    close < close[1];
plot BearishPlot = if Bearish then (high) else Double.NAN;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “THREE OUTSIDE DOWN", Alert.BAR, Sound.Bell);
##Identical Three Crows - Bearish Reversal, Red Triangle Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def ErrMargin = 0.05 * Average(BodyHeight(), length);
def IsLongBlack = IsLongBlack(length);
def IsCloseLower = close < close[1];
def IsOpenPrevClose = AbsValue(close[1] - open) <= ErrMargin;
def Bearish = IsAscending(open, trendSetup)[2] and
    IsLongBlack[2] and
    IsLongBlack[1] and
    IsLongBlack and
    IsCloseLower[1] and
    IsCloseLower and
    IsOpenPrevClose[1] and
    IsOpenPrevClose;
plot BearishPlot = if Bearish then (high + 0.1) else Double.NAN;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.light_red);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “IDENTICAL THREE CROWS", Alert.BAR, Sound.Bell);
##Stick Sandwich - Bearish Continuation, Cyan Triangle Above ##
input length = 20;
input trendSetup = 3;
input TurnAlertOff = yes;
def ErrMargin = 0.05 * Average(BodyHeight(), length);
def IsBlack = open > close;
def Bearish = IsDescending(close, trendSetup)[2] and
    IsBlack[2] and
    close[2] < open[1] and
    open[1] < close[1] and
    IsBlack and
    AbsValue(close - close[2]) <= ErrMargin;
plot BearishPlot = if bearish then (high) else Double.Nan;
BearishPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
BearishPlot.SetDefaultColor(color.cyan);
BearishPlot.SetLineWeight(2);
BearishPlot.hidebubble();
BearishPlot.hidetitle();
Alert(Bearish && !TurnAlertOff, “STICK SANDWICH", Alert.BAR, Sound.Bell); 
				 
						 
 
		 
 
		