-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtfb_strategy.pine
More file actions
43 lines (37 loc) · 1.95 KB
/
tfb_strategy.pine
File metadata and controls
43 lines (37 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//@version=4
study("Etiqueta de Oportunidad de Venta", overlay = true)
// Declarations for trend analysis
emaPeriod = input(100, title="Periodo de EMA")
ema = ema(close, emaPeriod)
slope = (ema - ema[1]) * 100
tendencia_bajista = (slope < -0.02)
// Declarations for candle analysis
bearishCandle = (close[3] < open[3])
baseBody = (abs(close[3] - open[3]) / syminfo.mintick)
threshold = 0.0015
threshold_level = close[3] * (1 - threshold)
bgcolor( tendencia_bajista ? color.red : na, transp=80)
if tendencia_bajista and bearishCandle
biggestCandle = true
for i = 1 to 3
nextCandleBody = (abs(close[i] - open[i]) / syminfo.mintick)
// Check if any follow-up candle is bigger or closes below the threshold
if nextCandleBody > baseBody or close[i] < threshold_level
biggestCandle := false
break
if biggestCandle
count = 0
// Iterate through each follow-up candle
for i = 0 to 3
currentCandle = (abs(close[i] - open[i]) / syminfo.mintick)
// Ensure the base candle is bigger than each follow-up candle
if baseBody > currentCandle
label.new(bar_index[i], high[i], tostring(count) + "\n" + tostring(currentCandle), style=label.style_label_up, yloc = yloc.belowbar, textcolor = color.white, color = color.black)
count := count + 1
else
biggestCandle := false // Invalidate if any follow-up candle is bigger
// If all checks are passed, then place the "TFB" label
label.new(bar_index[3], high[3], tostring(baseBody), yloc = yloc.abovebar, color = color.green)
label.new(bar_index, high, "TFB" + "\n" + tostring((abs(close[0] - open[0]) / syminfo.mintick)), yloc = yloc.price, color = color.red, textcolor = color.white)
// Draw the threshold line
line.new(x1 = bar_index[3], y1 = threshold_level, x2 = bar_index, y2 = threshold_level, color=color.red, width = 1)