// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ThiagoSchmitz // Description // This indicator is based on the 123 Pattern price continuation // it will place entry, stop loss and take profit prices for reference // The Take Profit Multiplicator parameter will be aplied at the distance between the first and second point. // Stop Loss vlaue will always be the distance between first and second point // The other configuration is the High/Low length. The same way you can find it on Zig-zag indicator, // it will be the range used on the calculation. The last paramter will be an option to show long/short orders //@version=5 indicator("123 Trend Continuation Pattern", overlay=true, max_bars_back=1000) // Inputs float tp = input.float(0.5, "Take Profit Multiplicator") int length = input.int(5, "High/Low length") string tradetype = input.string("Long and Short", "Show Orders", ["Long and Short", "Long", "Short"]) // Declarations float h = ta.highest(high, length * 2 + 1) float l = ta.lowest(low, length * 2 + 1) f_isMin(len) => l == low[len] f_isMax(len) => h == high[len] bool recentTouch = false // Variables var bool dirUp = false var float lastLow = high * 100 var float lastHigh = 0.0 var int timeLow = bar_index var int timeHigh = bar_index var line li = na bool isMin = f_isMin(length) bool isMax = f_isMax(length) // Functions f_drawLine() => line.new(timeHigh - length, lastHigh, timeLow - length, lastLow, xloc.bar_index, color=color.gray, width=1 ) // Direction if dirUp if isMin and low[length] < lastLow lastLow := low[length] timeLow := bar_index line.delete(li) li := f_drawLine() if isMax and high[length] > lastLow lastHigh := high[length] timeHigh := bar_index dirUp := false li := f_drawLine() if not dirUp if isMax and high[length] > lastHigh lastHigh := high[length] timeHigh := bar_index line.delete(li) li := f_drawLine() if isMin and low[length] < lastHigh lastLow := low[length] timeLow := bar_index dirUp := true li := f_drawLine() if (isMax and high[length] > lastLow) lastHigh := high[length] timeHigh := bar_index dirUp := false li := f_drawLine() // Checkers for int i = 1 to 10 if (low[i] <= lastLow[i] and low[i + 1] > lastLow[i + 1]) or (high[i] >= lastHigh[i] and high[i + 1] < lastHigh[i + 1]) recentTouch := true break // Conditions Definiitions longCondition = high >= lastHigh and high[1] < lastHigh[1] and not recentTouch and (tradetype == "Long and Short" or tradetype == "Long") shortCondition = low <= lastLow and low[1] > lastLow[1] and not recentTouch and (tradetype == "Long and Short" or tradetype == "Short") // Plots plotarrow(shortCondition and not longCondition ? -1 : 0, maxheight=20) plotarrow(longCondition and not shortCondition ? 1 : 0, maxheight=20) alertcondition(shortCondition and not longCondition, "123 Trend Continuation Short", "Short") alertcondition(longCondition and not shortCondition, "123 Trend Continuation Long", "Long") if shortCondition label.new(bar_index - 2, lastLow + syminfo.mintick * 2, "Entry Short", xloc.bar_index, yloc.price, color.red, label.style_none, color.red) label.new(bar_index - 2, lastLow - (lastHigh - lastLow) * tp, "Take Profit", xloc.bar_index, yloc.price, color.red, label.style_none, color.red) label.new(bar_index - 2, lastHigh, "Stop Loss", xloc.bar_index, yloc.price, color.red, label.style_none, color.red) line.new(timeLow - length, lastLow, bar_index, lastLow, xloc.bar_index, color=color.red, width=2) line.new(timeHigh - length, lastHigh, bar_index, lastHigh, xloc.bar_index, color=color.red, width=1, style=line.style_dotted) line.new(timeLow - length, lastLow - (lastHigh - lastLow) * tp, bar_index, lastLow - (lastHigh - lastLow) * tp, xloc.bar_index, color=color.red, width=1, style=line.style_dashed) if longCondition and not shortCondition line.new(timeHigh - length, lastHigh, bar_index, lastHigh, xloc.bar_index, color=color.green, width=2) line.new(timeLow - length, lastLow, bar_index, lastLow, xloc.bar_index, color=color.green, width=1, style=line.style_dotted) line.new(timeHigh - length, lastHigh + (lastHigh - lastLow) * tp, bar_index, lastHigh + (lastHigh - lastLow) * tp, xloc.bar_index, color=color.green, width=1, style=line.style_dashed) label.new(bar_index - 2, lastHigh + syminfo.mintick, "Entry Long", xloc.bar_index, yloc.price, color.green, label.style_none, color.green) label.new(bar_index - 2, lastLow, "Stop Loss", xloc.bar_index, yloc.price, color.green, label.style_none, color.green) label.new(bar_index - 2, lastHigh + (lastHigh - lastLow) * tp, "Take Profit", xloc.bar_index, yloc.price, color.green, label.style_none, color.green)