ajiim

🎁

Nov 1st, 2026
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.65 KB | None | 0 0
  1. //@version=6
  2. indicator("Reversal Strategy (Trade Your Edge)", shorttitle = "Reversal Strategy (Trade Your Edge)", overlay = true, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500, max_bars_back = 500)
  3.  
  4. string GRP_PB = "Power Bars"
  5. float sensitivityInput = input.float(1.0, "Sensitivity", minval = 0.1, step = 0.1, group = GRP_PB, tooltip = "Minimum body size as a multiple of ATR. Higher values produce stricter detection and fewer Power Bars; lower values produce more frequent detection.")
  6. float bodyPctInput = input.float(75.0, "Body %", minval = 1.0, maxval = 100.0, step = 1.0, group = GRP_PB, tooltip = "Minimum percentage of the candle or sequence range that must be formed by the body. Controls how much wick activity is tolerated in a Power Bar.")
  7. bool singlePBInput = input.bool(true, "Power Bar Setups", group = GRP_PB, tooltip = "Toggle single candle Power Bar detection.")
  8. bool twoPBInput = input.bool(true, "2 Candle Power Bar Setups", group = GRP_PB, tooltip = "Toggle two candle Power Bar detection.")
  9. bool threePBInput = input.bool(true, "3 Candle Power Bar Setups", group = GRP_PB, tooltip = "Toggle three candle Power Bar detection.")
  10.  
  11. string GRP_CZ = "Consolidation Zones"
  12. int consLengthInput = input.int(1, "Consolidation Length", minval = 0, group = GRP_CZ, tooltip = "Waiting period between zone creation and a valid breakout signal. The breakout bar must occur after the zone creation bar plus this value. Default 1 means the immediate next bar after zone creation cannot trigger the signal.")
  13.  
  14. string GRP_SIG = "Signals"
  15. bool longSignalsInput = input.bool(true, "Long Signals", inline = "long", group = GRP_SIG, tooltip = "Enable or disable long signal generation and long trade tracking.")
  16. color longColorInput = input.color(#4CAF50, "", inline = "long", group = GRP_SIG)
  17. bool shortSignalsInput = input.bool(true, "Short Signals", inline = "short", group = GRP_SIG, tooltip = "Enable or disable short signal generation and short trade tracking.")
  18. color shortColorInput = input.color(#F23645, "", inline = "short", group = GRP_SIG)
  19.  
  20. string GRP_TPSL = "Stop Loss & Take Profit"
  21. bool showTpLevelsInput = input.bool(true, "Take Profit Levels", inline = "tpl", group = GRP_TPSL, tooltip = "Toggle the dashed TP lines and right-side TP price labels.")
  22. color tpColorInput = input.color(#22AB94, "", inline = "tpl", group = GRP_TPSL)
  23. bool showTpLabelsInput = input.bool(true, "Take Profit Labels", inline = "tpm", group = GRP_TPSL, tooltip = "Toggle the TP outcome markers plotted on candles when TP levels are hit.")
  24. color tpMarkerColorInput = input.color(#2962FF, "", inline = "tpm", group = GRP_TPSL)
  25. bool showSlLevelsInput = input.bool(true, "Stop Loss Levels", inline = "sll", group = GRP_TPSL, tooltip = "Toggle the dashed SL line and right-side SL price label.")
  26. color slColorInput = input.color(#F23645, "", inline = "sll", group = GRP_TPSL)
  27. bool showSlLabelsInput = input.bool(true, "Stop Loss Labels", inline = "slm", group = GRP_TPSL, tooltip = "Toggle the SL outcome marker plotted on the candle when SL is hit.")
  28. color slMarkerColorInput = input.color(#F23645, "", inline = "slm", group = GRP_TPSL)
  29.  
  30. string GRP_VIS = "Visualization"
  31. int smaLengthInput = input.int(20, "SMA Length", minval = 1, group = GRP_VIS, tooltip = "Period of the SMA used for trend classification and Power Bar gating. Also controls the plotted SMA when enabled.")
  32. bool showSmaInput = input.bool(true, "Enable SMA", inline = "sma", group = GRP_VIS, tooltip = "Toggle display of the SMA line on the chart.")
  33. color smaColorInput = input.color(color.aqua, "", inline = "sma", group = GRP_VIS)
  34. bool showPBColorInput = input.bool(true, "Power Bar Color", inline = "pbc", group = GRP_VIS, tooltip = "Toggle and customize the bar coloring for single candle Power Bars (bullish / bearish).")
  35. color pbBullColorInput = input.color(#00E676, "", inline = "pbc", group = GRP_VIS)
  36. color pbBearColorInput = input.color(#FF1744, "", inline = "pbc", group = GRP_VIS)
  37. bool showMultiColorInput = input.bool(true, "Multi-Candle Power Bar Color", inline = "mpc", group = GRP_VIS, tooltip = "Toggle and customize the bar coloring for two and three candle Power Bars (bullish / bearish).")
  38. color multiBullColorInput = input.color(#FF9800, "", inline = "mpc", group = GRP_VIS)
  39. color multiBearColorInput = input.color(#E91E63, "", inline = "mpc", group = GRP_VIS)
  40. bool showZonesInput = input.bool(true, "Consolidation Zones", group = GRP_VIS, tooltip = "Toggle the display of the Consolidation Zone boxes.")
  41. color bullZoneColorInput = input.color(color.new(#00E676, 85), "Bull Zone Color", group = GRP_VIS)
  42. color bearZoneColorInput = input.color(color.new(#FF1744, 85), "Bear Zone Color", group = GRP_VIS)
  43.  
  44. string GRP_AL = "Alerts"
  45. bool alertLongInput = input.bool(true, "Long Signal", inline = "al1", group = GRP_AL, tooltip = "Toggle alerts for new long / short entries.")
  46. bool alertShortInput = input.bool(true, "Short Signal", inline = "al1", group = GRP_AL)
  47. bool alertTp1Input = input.bool(true, "TP 1", inline = "al2", group = GRP_AL, tooltip = "Toggle alerts for each respective TP level.")
  48. bool alertTp2Input = input.bool(true, "TP 2", inline = "al2", group = GRP_AL)
  49. bool alertTp3Input = input.bool(true, "TP 3", inline = "al2", group = GRP_AL)
  50. bool alertSlInput = input.bool(true, "SL", group = GRP_AL, tooltip = "Toggle alerts for Stop Loss hits.")
  51.  
  52. int ATR_LENGTH = 14
  53. int REGIME_LOOKBACK = 10
  54. float REGIME_RATIO = 0.6
  55. float TWO_CANDLE_SCALE = 1.5
  56. float THREE_CANDLE_SCALE = 2.0
  57. float TP1_R = 1.0
  58. float TP2_R = 1.5
  59. float TP3_R = 2.0
  60. int LINE_EXT = 25
  61. color SIGNAL_TEXT_COLOR = color.white
  62. color MARKER_TEXT_COLOR = color.white
  63. color LABEL_BG_COLOR = color.new(color.black, 100)
  64. string CHECK_MARK = " ✅"
  65.  
  66. type Zone
  67. box bx
  68. float top
  69. float bottom
  70. float sl
  71. int createdBar
  72. bool active = false
  73.  
  74. type Trade
  75. int dir = 0
  76. int entryBar
  77. float sl
  78. float tp1
  79. float tp2
  80. float tp3
  81. bool hit1 = false
  82. bool hit2 = false
  83. bool hit3 = false
  84. bool active = false
  85. line slLine
  86. line tp1Line
  87. line tp2Line
  88. line tp3Line
  89. label slLabel
  90. label tp1Label
  91. label tp2Label
  92. label tp3Label
  93.  
  94. f_price(float p) =>
  95. str.tostring(math.round_to_mintick(p))
  96.  
  97. f_tpText(float p, bool hit) =>
  98. "TP " + f_price(p) + (hit ? CHECK_MARK : "")
  99.  
  100. f_regime(float smaV, int len) =>
  101. int ups = int(nz(math.sum(smaV > smaV[1] ? 1 : 0, len)))
  102. int downs = int(nz(math.sum(smaV < smaV[1] ? 1 : 0, len)))
  103. float net = smaV - smaV[len]
  104. int need = math.ceil(len * REGIME_RATIO)
  105. int result = 0
  106. if not na(net)
  107. if net > 0 and ups >= need
  108. result := 1
  109. else if net < 0 and downs >= need
  110. result := -1
  111. result
  112.  
  113. f_singlePB(bool isBull, float smaV, float atrV) =>
  114. float body = math.abs(close - open)
  115. float rng = high - low
  116. bool dirOk = isBull ? close > open : close < open
  117. bool sizeOk = not na(atrV) and body >= sensitivityInput * atrV
  118. bool ratioOk = rng > 0 and body / rng * 100.0 >= bodyPctInput
  119. bool crossOk = not na(smaV) and (isBull ? open < smaV and close > smaV : open > smaV and close < smaV)
  120. dirOk and sizeOk and ratioOk and crossOk
  121.  
  122. f_multiPB(int n, bool isBull, float smaV, float atrV, float scale) =>
  123. float hi = ta.highest(high, n)
  124. float lo = ta.lowest(low, n)
  125. bool sameColor = nz(math.sum(isBull ? (close > open ? 1 : 0) : (close < open ? 1 : 0), n)) == n
  126. float seqOpen = open[n - 1]
  127. float smaStart = smaV[n - 1]
  128. float body = math.abs(close - seqOpen)
  129. float rng = hi - lo
  130. bool sizeOk = not na(atrV) and body >= sensitivityInput * atrV * scale
  131. bool ratioOk = rng > 0 and body / rng * 100.0 >= bodyPctInput
  132. bool crossOk = not na(smaV) and not na(smaStart) and (isBull ? seqOpen < smaStart and close > smaV : seqOpen > smaStart and close < smaV)
  133. bar_index >= n and sameColor and sizeOk and ratioOk and crossOk
  134.  
  135. f_newZone(bool isBull, float top, float bottom, float sl, int startBar) =>
  136. box bx = na
  137. if showZonesInput
  138. color fillC = isBull ? bullZoneColorInput : bearZoneColorInput
  139. bx := box.new(left = startBar, top = top, right = bar_index, bottom = bottom, border_color = color.new(fillC, math.max(color.t(fillC) - 50, 0)), border_width = 1, xloc = xloc.bar_index, bgcolor = fillC)
  140. Zone.new(bx = bx, top = top, bottom = bottom, sl = sl, createdBar = bar_index, active = true)
  141.  
  142. method extendTo(Zone this, int x) =>
  143. if not na(this.bx)
  144. this.bx.set_right(x)
  145.  
  146. method remove(Zone this) =>
  147. box.delete(this.bx)
  148. this.active := false
  149.  
  150. f_levelLine(int x1, int x2, float y, color c, bool show) =>
  151. line ln = na
  152. if show
  153. ln := line.new(x1 = x1, y1 = y, x2 = x2, y2 = y, xloc = xloc.bar_index, extend = extend.none, color = c, style = line.style_dashed, width = 1)
  154. ln
  155.  
  156. f_levelLabel(int x, float y, string txt, color c, bool show) =>
  157. label lb = na
  158. if show
  159. lb := label.new(x = x, y = y, text = txt, xloc = xloc.bar_index, yloc = yloc.price, color = LABEL_BG_COLOR, style = label.style_label_left, textcolor = c, size = size.small, textalign = text.align_left)
  160. lb
  161.  
  162. f_newTrade(int dir, float entry, float sl) =>
  163. float risk = math.abs(entry - sl)
  164. float tp1 = entry + dir * risk * TP1_R
  165. float tp2 = entry + dir * risk * TP2_R
  166. float tp3 = entry + dir * risk * TP3_R
  167. int x1 = bar_index
  168. int x2 = bar_index + LINE_EXT
  169. line slL = f_levelLine(x1, x2, sl, slColorInput, showSlLevelsInput)
  170. line tp1L = f_levelLine(x1, x2, tp1, tpColorInput, showTpLevelsInput)
  171. line tp2L = f_levelLine(x1, x2, tp2, tpColorInput, showTpLevelsInput)
  172. line tp3L = f_levelLine(x1, x2, tp3, tpColorInput, showTpLevelsInput)
  173. label slB = f_levelLabel(x2, sl, "SL " + f_price(sl), slColorInput, showSlLevelsInput)
  174. label tp1B = f_levelLabel(x2, tp1, f_tpText(tp1, false), tpColorInput, showTpLevelsInput)
  175. label tp2B = f_levelLabel(x2, tp2, f_tpText(tp2, false), tpColorInput, showTpLevelsInput)
  176. label tp3B = f_levelLabel(x2, tp3, f_tpText(tp3, false), tpColorInput, showTpLevelsInput)
  177. Trade.new(dir = dir, entryBar = bar_index, sl = sl, tp1 = tp1, tp2 = tp2, tp3 = tp3, active = true, slLine = slL, tp1Line = tp1L, tp2Line = tp2L, tp3Line = tp3L, slLabel = slB, tp1Label = tp1B, tp2Label = tp2B, tp3Label = tp3B)
  178.  
  179. method deletePlan(Trade this) =>
  180. line.delete(this.slLine)
  181. line.delete(this.tp1Line)
  182. line.delete(this.tp2Line)
  183. line.delete(this.tp3Line)
  184. label.delete(this.slLabel)
  185. label.delete(this.tp1Label)
  186. label.delete(this.tp2Label)
  187. label.delete(this.tp3Label)
  188.  
  189. method setPlanEnd(Trade this, int x2) =>
  190. if not na(this.slLine)
  191. this.slLine.set_x2(x2)
  192. if not na(this.tp1Line)
  193. this.tp1Line.set_x2(x2)
  194. if not na(this.tp2Line)
  195. this.tp2Line.set_x2(x2)
  196. if not na(this.tp3Line)
  197. this.tp3Line.set_x2(x2)
  198. if not na(this.slLabel)
  199. this.slLabel.set_x(x2)
  200. if not na(this.tp1Label)
  201. this.tp1Label.set_x(x2)
  202. if not na(this.tp2Label)
  203. this.tp2Label.set_x(x2)
  204. if not na(this.tp3Label)
  205. this.tp3Label.set_x(x2)
  206.  
  207. method markTp(Trade this, int idx) =>
  208. if idx == 1
  209. this.hit1 := true
  210. if not na(this.tp1Label)
  211. this.tp1Label.set_text(f_tpText(this.tp1, true))
  212. else if idx == 2
  213. this.hit2 := true
  214. if not na(this.tp2Label)
  215. this.tp2Label.set_text(f_tpText(this.tp2, true))
  216. else
  217. this.hit3 := true
  218. if not na(this.tp3Label)
  219. this.tp3Label.set_text(f_tpText(this.tp3, true))
  220.  
  221. f_signalLabel(int dir) =>
  222. bool isLong = dir == 1
  223. label.new(x = bar_index, y = isLong ? low : high, text = isLong ? "Long" : "Short", xloc = xloc.bar_index, yloc = isLong ? yloc.belowbar : yloc.abovebar, color = isLong ? longColorInput : shortColorInput, style = isLong ? label.style_label_up : label.style_label_down, textcolor = SIGNAL_TEXT_COLOR, size = size.small)
  224.  
  225. float smaValue = ta.sma(close, smaLengthInput)
  226. float atrValue = ta.atr(ATR_LENGTH)
  227. int regimeRaw = f_regime(smaValue, REGIME_LOOKBACK)
  228.  
  229. bool bullSingleRaw = f_singlePB(true, smaValue, atrValue)
  230. bool bearSingleRaw = f_singlePB(false, smaValue, atrValue)
  231. bool bullTwoRaw = f_multiPB(2, true, smaValue, atrValue, TWO_CANDLE_SCALE)
  232. bool bearTwoRaw = f_multiPB(2, false, smaValue, atrValue, TWO_CANDLE_SCALE)
  233. bool bullThreeRaw = f_multiPB(3, true, smaValue, atrValue, THREE_CANDLE_SCALE)
  234. bool bearThreeRaw = f_multiPB(3, false, smaValue, atrValue, THREE_CANDLE_SCALE)
  235.  
  236. var int lastPBEnd = -1
  237. bool bullSingle = singlePBInput and bullSingleRaw
  238. bool bearSingle = singlePBInput and bearSingleRaw
  239. bool bullTwo = twoPBInput and bullTwoRaw and not bullSingle and bar_index - 1 > lastPBEnd
  240. bool bearTwo = twoPBInput and bearTwoRaw and not bearSingle and bar_index - 1 > lastPBEnd
  241. bool bullThree = threePBInput and bullThreeRaw and not bullSingle and not bullTwo and bar_index - 2 > lastPBEnd
  242. bool bearThree = threePBInput and bearThreeRaw and not bearSingle and not bearTwo and bar_index - 2 > lastPBEnd
  243. bool bullPB = bullSingle or bullTwo or bullThree
  244. bool bearPB = bearSingle or bearTwo or bearThree
  245.  
  246. int pbLen = bullSingle or bearSingle ? 1 : bullTwo or bearTwo ? 2 : bullThree or bearThree ? 3 : 0
  247. if bullPB or bearPB
  248. lastPBEnd := bar_index
  249.  
  250. float hi2 = math.max(high, high[1])
  251. float hi3 = math.max(hi2, high[2])
  252. float lo2 = math.min(low, low[1])
  253. float lo3 = math.min(lo2, low[2])
  254. float pbHigh = pbLen == 1 ? high : pbLen == 2 ? hi2 : pbLen == 3 ? hi3 : na
  255. float pbLow = pbLen == 1 ? low : pbLen == 2 ? lo2 : pbLen == 3 ? lo3 : na
  256. float pbMid = (pbHigh + pbLow) / 2.0
  257. float pbAnchorLow = pbLen == 1 ? low : pbLen == 2 ? low[1] : pbLen == 3 ? low[2] : na
  258. float pbAnchorHigh = pbLen == 1 ? high : pbLen == 2 ? high[1] : pbLen == 3 ? high[2] : na
  259. int pbStartBar = bar_index - math.max(pbLen, 1) + 1
  260.  
  261. int regimeAtPB = pbLen == 1 ? nz(regimeRaw[1]) : pbLen == 2 ? nz(regimeRaw[2]) : pbLen == 3 ? nz(regimeRaw[3]) : 0
  262.  
  263. bool bullSetup = bullPB and regimeAtPB == -1 and longSignalsInput and barstate.isconfirmed
  264. bool bearSetup = bearPB and regimeAtPB == 1 and shortSignalsInput and barstate.isconfirmed
  265.  
  266. color pbBarColor = showPBColorInput and bullSingle ? pbBullColorInput : showPBColorInput and bearSingle ? pbBearColorInput : showMultiColorInput and (bullTwo or bullThree) ? multiBullColorInput : showMultiColorInput and (bearTwo or bearThree) ? multiBearColorInput : na
  267. color pbPrevColor = showMultiColorInput and (bullTwo or bullThree) ? multiBullColorInput : showMultiColorInput and (bearTwo or bearThree) ? multiBearColorInput : na
  268. color pbPrev2Color = showMultiColorInput and bullThree ? multiBullColorInput : showMultiColorInput and bearThree ? multiBearColorInput : na
  269.  
  270. var Zone bullZone = Zone.new()
  271. var Zone bearZone = Zone.new()
  272. var Trade activeTrade = Trade.new()
  273.  
  274. bool tp1Hit = false
  275. bool tp2Hit = false
  276. bool tp3Hit = false
  277. bool slHit = false
  278. int eventDir = 0
  279. float tp1HitPx = na
  280. float tp2HitPx = na
  281. float tp3HitPx = na
  282. float slHitPx = na
  283.  
  284. if activeTrade.active and bar_index > activeTrade.entryBar
  285. bool isLong = activeTrade.dir == 1
  286. eventDir := activeTrade.dir
  287. bool slTouched = isLong ? low < activeTrade.sl : high > activeTrade.sl
  288. if slTouched
  289. slHit := true
  290. slHitPx := activeTrade.sl
  291. activeTrade.active := false
  292. activeTrade.setPlanEnd(bar_index)
  293. else
  294. if not activeTrade.hit1 and (isLong ? high > activeTrade.tp1 : low < activeTrade.tp1)
  295. activeTrade.markTp(1)
  296. tp1Hit := true
  297. tp1HitPx := activeTrade.tp1
  298. if not activeTrade.hit2 and (isLong ? high > activeTrade.tp2 : low < activeTrade.tp2)
  299. activeTrade.markTp(2)
  300. tp2Hit := true
  301. tp2HitPx := activeTrade.tp2
  302. if not activeTrade.hit3 and (isLong ? high > activeTrade.tp3 : low < activeTrade.tp3)
  303. activeTrade.markTp(3)
  304. tp3Hit := true
  305. tp3HitPx := activeTrade.tp3
  306. if activeTrade.hit3
  307. activeTrade.active := false
  308. activeTrade.setPlanEnd(bar_index)
  309. if activeTrade.active
  310. activeTrade.setPlanEnd(bar_index + LINE_EXT)
  311.  
  312. int tpHitCount = (tp1Hit ? 1 : 0) + (tp2Hit ? 1 : 0) + (tp3Hit ? 1 : 0)
  313.  
  314. bool longSignal = false
  315. bool shortSignal = false
  316. float signalStop = na
  317.  
  318. if barstate.isconfirmed
  319. if bullZone.active and bar_index > bullZone.createdBar
  320. if close < bullZone.bottom
  321. bullZone.remove()
  322. else if close > bullZone.top and bar_index > bullZone.createdBar + consLengthInput
  323. bullZone.active := false
  324. bullZone.extendTo(bar_index)
  325. if close > bullZone.sl
  326. longSignal := true
  327. signalStop := bullZone.sl
  328. else
  329. bullZone.extendTo(bar_index)
  330.  
  331. if bearZone.active and bar_index > bearZone.createdBar
  332. if close > bearZone.top
  333. bearZone.remove()
  334. else if close < bearZone.bottom and bar_index > bearZone.createdBar + consLengthInput
  335. bearZone.active := false
  336. bearZone.extendTo(bar_index)
  337. if close < bearZone.sl
  338. shortSignal := true
  339. signalStop := bearZone.sl
  340. else
  341. bearZone.extendTo(bar_index)
  342.  
  343. if longSignal and shortSignal
  344. shortSignal := false
  345. signalStop := bullZone.sl
  346.  
  347. if bullSetup
  348. if bullZone.active
  349. bullZone.remove()
  350. bullZone := f_newZone(true, pbHigh, pbMid, pbAnchorLow, pbStartBar)
  351. if bearSetup
  352. if bearZone.active
  353. bearZone.remove()
  354. bearZone := f_newZone(false, pbMid, pbLow, pbAnchorHigh, pbStartBar)
  355.  
  356. if longSignal or shortSignal
  357. int newDir = longSignal ? 1 : -1
  358. activeTrade.deletePlan()
  359. activeTrade := f_newTrade(newDir, close, signalStop)
  360. f_signalLabel(newDir)
  361.  
  362. barcolor(pbBarColor, title = "Power Bar Color")
  363. barcolor(pbPrevColor, offset = -1, title = "Multi-Candle Power Bar Color (2nd)")
  364. barcolor(pbPrev2Color, offset = -2, title = "Multi-Candle Power Bar Color (3rd)")
  365.  
  366. plot(showSmaInput ? smaValue : na, "SMA", color = smaColorInput, linewidth = 1)
  367.  
  368. plotshape(showTpLabelsInput and eventDir == 1 and tpHitCount == 1, "TP (Long)", shape.xcross, location.abovebar, tpMarkerColorInput, text = "TP", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  369. plotshape(showTpLabelsInput and eventDir == 1 and tpHitCount == 2, "TP x2 (Long)", shape.xcross, location.abovebar, tpMarkerColorInput, text = "TP x2", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  370. plotshape(showTpLabelsInput and eventDir == 1 and tpHitCount == 3, "TP x3 (Long)", shape.xcross, location.abovebar, tpMarkerColorInput, text = "TP x3", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  371.  
  372. plotshape(showTpLabelsInput and eventDir == -1 and tpHitCount == 1, "TP (Short)", shape.xcross, location.belowbar, tpMarkerColorInput, text = "TP", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  373. plotshape(showTpLabelsInput and eventDir == -1 and tpHitCount == 2, "TP x2 (Short)", shape.xcross, location.belowbar, tpMarkerColorInput, text = "TP x2", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  374. plotshape(showTpLabelsInput and eventDir == -1 and tpHitCount == 3, "TP x3 (Short)", shape.xcross, location.belowbar, tpMarkerColorInput, text = "TP x3", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  375.  
  376. plotshape(showSlLabelsInput and slHit and eventDir == 1, "SL (Long)", shape.circle, location.belowbar, slMarkerColorInput, text = "SL", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  377. plotshape(showSlLabelsInput and slHit and eventDir == -1, "SL (Short)", shape.circle, location.abovebar, slMarkerColorInput, text = "SL", textcolor = MARKER_TEXT_COLOR, size = size.tiny)
  378.  
  379. string ALERT_PREFIX = "Reversal Strategy (Trade Your Edge) | " + syminfo.ticker + " | "
  380.  
  381. if alertLongInput and longSignal
  382. alert(ALERT_PREFIX + "Long Signal @ " + f_price(close) + " | SL " + f_price(activeTrade.sl) + " | TP1 " + f_price(activeTrade.tp1) + " | TP2 " + f_price(activeTrade.tp2) + " | TP3 " + f_price(activeTrade.tp3), alert.freq_once_per_bar_close)
  383. if alertShortInput and shortSignal
  384. alert(ALERT_PREFIX + "Short Signal @ " + f_price(close) + " | SL " + f_price(activeTrade.sl) + " | TP1 " + f_price(activeTrade.tp1) + " | TP2 " + f_price(activeTrade.tp2) + " | TP3 " + f_price(activeTrade.tp3), alert.freq_once_per_bar_close)
  385. if alertTp1Input and tp1Hit
  386. alert(ALERT_PREFIX + "TP 1 Hit @ " + f_price(tp1HitPx), alert.freq_once_per_bar)
  387. if alertTp2Input and tp2Hit
  388. alert(ALERT_PREFIX + "TP 2 Hit @ " + f_price(tp2HitPx), alert.freq_once_per_bar)
  389. if alertTp3Input and tp3Hit
  390. alert(ALERT_PREFIX + "TP 3 Hit @ " + f_price(tp3HitPx), alert.freq_once_per_bar)
  391. if alertSlInput and slHit
  392. alert(ALERT_PREFIX + "SL Hit @ " + f_price(slHitPx), alert.freq_once_per_bar)
  393.  
  394.  
  395. alertcondition(alertLongInput and longSignal, "Long Signal", "Reversal Strategy (Trade Your Edge): Long Signal on {{ticker}} @ {{close}}")
  396. alertcondition(alertShortInput and shortSignal, "Short Signal", "Reversal Strategy (Trade Your Edge): Short Signal on {{ticker}} @ {{close}}")
  397. alertcondition(alertTp1Input and tp1Hit, "TP 1", "Reversal Strategy (Trade Your Edge): TP 1 Hit on {{ticker}}")
  398. alertcondition(alertTp2Input and tp2Hit, "TP 2", "Reversal Strategy (Trade Your Edge): TP 2 Hit on {{ticker}}")
  399. alertcondition(alertTp3Input and tp3Hit, "TP 3", "Reversal Strategy (Trade Your Edge): TP 3 Hit on {{ticker}}")
  400. alertcondition(alertSlInput and slHit, "SL", "Reversal Strategy (Trade Your Edge): SL Hit on {{ticker}}")
Advertisement
Add Comment
Please, Sign In to add comment