Combining into an All-in-One Candlesticks Script?

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:
  1. Hammer
  2. Shooting Star
  3. Doji
  4. Long-Legged Doji
  5. Bullish Engulfing
  6. Bearish Engulfing
  7. Bullish Piercing
  8. Dark Cloud Cover
  9. Two Crows
  10. In Neck
  11. On Neck
  12. One White Soldier
  13. One Black Crow
  14. Morning Star
  15. Evening Star
  16. Morning Doji Star
  17. Evening Doji Star
  18. Three White Soldiers
  19. Three Black Crows
  20. Three Inside Up
  21. Three Inside Down
  22. Three Outside Up
  23. Three Outside Down
  24. Identical Three Crows
  25. 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);
 
Solution
Take note I'm a learner too - my coding kung fu is not there yet. However, I'm pretty sure you cannot reuse the same inputs/def (variables) name for each indicator. If all the indicators use "input length = 20" then you can make it global (put at beginning) and remove it from the indicator. However, if was different, then you'd have to define it again with a different name, ie "input length_doji = 10". Then all the calc statements would have to be updated to "length_doji" Take sections Hammer and Doji for example - the editor didn't complain when I made these changes for these two indicators:

Code:
###################################################

############ One Candlestick ##################...
Take note I'm a learner too - my coding kung fu is not there yet. However, I'm pretty sure you cannot reuse the same inputs/def (variables) name for each indicator. If all the indicators use "input length = 20" then you can make it global (put at beginning) and remove it from the indicator. However, if was different, then you'd have to define it again with a different name, ie "input length_doji = 10". Then all the calc statements would have to be updated to "length_doji" Take sections Hammer and Doji for example - the editor didn't complain when I made these changes for these two indicators:

Code:
###################################################

############ One Candlestick ##################

###################################################

input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input shadowFactor = 2.0;
input TurnAlertOff = yes;

##Hammer - Bullish Reversal, Red Circle Under ##
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 ##
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);
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 bodyFactor_doji = 0.05;
assert(bodyFactor_doji >= 0, "'body factor' must not be negative: " + bodyFactor_doji);
plot Doji = IsDoji(length, bodyFactor_doji);
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);

## End Code

So either go through the whole script by hand and make unique changes as needed, or use a text editor with some RexEX /ReplaceALL wizardry.

Edit - Why not just have the each 25 indicator in the study? Save it as a style if you need it on multiple charts.
 
Last edited:
Solution
Take note I'm a learner too - my coding kung fu is not there yet. However, I'm pretty sure you cannot reuse the same inputs/def (variables) name for each indicator. If all the indicators use "input length = 20" then you can make it global (put at beginning) and remove it from the indicator. However, if was different, then you'd have to define it again with a different name, ie "input length_doji = 10". Then all the calc statements would have to be updated to "length_doji" Take sections Hammer and Doji for example - the editor didn't complain when I made these changes for these two indicators:

Code:
###################################################

############ One Candlestick ##################

###################################################

input length = 20;
input trendSetup = 3;
input bodyFactor = 0.3;
input shadowFactor = 2.0;
input TurnAlertOff = yes;

##Hammer - Bullish Reversal, Red Circle Under ##
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 ##
assert(bodyFactor >= 0, "'body factor' must not be negative: " + bodyFactor);
assert(shadowFactor >= 0, "'shadow factor' must not be negative: " + shadowFactor);
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 bodyFactor_doji = 0.05;
assert(bodyFactor_doji >= 0, "'body factor' must not be negative: " + bodyFactor_doji);
plot Doji = IsDoji(length, bodyFactor_doji);
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);

## End Code

So either go through the whole script by hand and make unique changes as needed, or use a text editor with some RexEX /ReplaceALL wizardry.

Edit - Why not just have the each 25 indicator in the study? Save it as a style if you need it on multiple charts.
Thank you @Iceman1205us! I’ll give it a spin with the unique changes as noted in your above adjustments. Got each of the 25 saved as a set in the meantime for multiple charts.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
334 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top