-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindicator.pine
More file actions
558 lines (466 loc) · 22.1 KB
/
Copy pathindicator.pine
File metadata and controls
558 lines (466 loc) · 22.1 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
//@version=5
indicator("1m Scalper + Order Block (OB SL + TP1/TP2 + Partial) + Reaction Avg Target [FIXED]", overlay=true, max_labels_count=500, max_boxes_count=50, max_lines_count=500)
//====================
// INPUTS
//====================
grpSig = "Sinyal"
emaFastLen = input.int(9, "EMA Fast", group=grpSig, minval=1)
emaSlowLen = input.int(21, "EMA Slow", group=grpSig, minval=1)
rsiLen = input.int(14, "RSI Len", group=grpSig, minval=1)
rsiLongMin = input.int(52, "RSI Long Min", group=grpSig, minval=1, maxval=99)
rsiShortMax= input.int(48, "RSI Short Max", group=grpSig, minval=1, maxval=99)
pullbackATR= input.float(0.35, "VWAP'e Yakınlık (ATR x)", group=grpSig, step=0.05)
useOBFilter= input.bool(true, "OB Filtresi (sinyal OB ile uyumlu olsun)", group=grpSig)
grpOB = "Order Block"
pivotLen = input.int(3, "Swing Pivot Len", group=grpOB, minval=1)
obLookback = input.int(20, "OB Arama Lookback", group=grpOB, minval=5, maxval=100)
obExtend = input.int(120, "OB Uzatma (bar)", group=grpOB, minval=10, maxval=500)
grpRisk = "SL/TP (OB tabanlı)"
atrLen = input.int(14, "ATR Len", group=grpRisk, minval=1)
obBufATR = input.float(0.15, "OB Buffer (ATR x)", group=grpRisk, step=0.05)
tp1Mode = input.string("SWING", "TP1 Mode", options=["SWING","RR"], group=grpRisk)
tp1RR = input.float(1.0, "TP1 RR (TP1 Mode=RR)", group=grpRisk, step=0.1)
tp2RR = input.float(1.8, "TP2 RR", group=grpRisk, step=0.1)
partial1 = input.int(50, "TP1 Partial %", group=grpRisk, minval=1, maxval=99)
// --- Reaction-based levels
grpReact = "Reaction Target/Stop (Pivot kümeleri)"
useReactionLevels = input.bool(true, "TP1/SL'yi reaksiyon kümelerinden hesapla", group=grpReact)
reactLookback = input.int(300, "Reaksiyon Lookback (bar)", group=grpReact, minval=50, maxval=2000)
reactK = input.int(4, "Ortalama için nokta sayısı (3-4)", group=grpReact, minval=3, maxval=4)
reactTolATR = input.float(0.35, "Küme toleransı (ATR x)", group=grpReact, step=0.05)
reactMinTouches = input.int(2, "Min tepki sayısı (touch)", group=grpReact, minval=1, maxval=10)
grpUI = "Görsel"
showVWAP = input.bool(true, "VWAP Göster", group=grpUI)
showEMAs = input.bool(true, "EMAlar Göster", group=grpUI)
showOB = input.bool(true, "Order Block Göster", group=grpUI)
showLevels = input.bool(true, "SL/TP Çizgileri Göster", group=grpUI)
//====================
// CORE CALCS
//====================
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
vwapVal = ta.vwap(hlc3)
rsiVal = ta.rsi(close, rsiLen)
atrVal = ta.atr(atrLen)
minTick = syminfo.mintick
bullTrend = emaFast > emaSlow
bearTrend = emaFast < emaSlow
nearVWAP = math.abs(close - vwapVal) <= atrVal * pullbackATR
momLong = rsiVal >= rsiLongMin
momShort = rsiVal <= rsiShortMax
//====================
// SWINGS
//====================
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var float lastSwingHigh = na
var float lastSwingLow = na
if not na(ph)
lastSwingHigh := ph
if not na(pl)
lastSwingLow := pl
//====================
// ORDER BLOCK (BOS based)
//====================
var float lastStructHigh = na
var float lastStructLow = na
if not na(ph)
lastStructHigh := ph
if not na(pl)
lastStructLow := pl
// FIX: BOS sadece gerçek kırılımda tetiklensin
bosUp = not na(lastStructHigh) and ta.crossover(close, lastStructHigh)
bosDown = not na(lastStructLow) and ta.crossunder(close, lastStructLow)
var box bullOB = na
var box bearOB = na
var float bullOBTop = na
var float bullOBBot = na
var float bearOBTop = na
var float bearOBBot = na
if showOB and bosUp
int foundUp = na
for i = 1 to obLookback
if close[i] < open[i]
foundUp := i
break
if not na(foundUp)
if not na(bullOB)
box.delete(bullOB)
bullOBTop := open[foundUp]
bullOBBot := low[foundUp]
bullOB := box.new(bar_index - foundUp, bullOBTop, bar_index + obExtend, bullOBBot, bgcolor=color.new(color.green, 85), border_color=color.new(color.green, 20))
if showOB and bosDown
int foundDn = na
for i = 1 to obLookback
if close[i] > open[i]
foundDn := i
break
if not na(foundDn)
if not na(bearOB)
box.delete(bearOB)
bearOBTop := high[foundDn]
bearOBBot := open[foundDn]
bearOB := box.new(bar_index - foundDn, bearOBTop, bar_index + obExtend, bearOBBot, bgcolor=color.new(color.red, 85), border_color=color.new(color.red, 20))
hasBullOB = not na(bullOBTop) and not na(bullOBBot)
hasBearOB = not na(bearOBTop) and not na(bearOBBot)
inBullOB = hasBullOB and close >= bullOBBot and close <= bullOBTop
aboveBullOB = hasBullOB and close > bullOBTop
inBearOB = hasBearOB and close <= bearOBTop and close >= bearOBBot
belowBearOB = hasBearOB and close < bearOBBot
longOBok = (not useOBFilter) or inBullOB or aboveBullOB
shortOBok = (not useOBFilter) or inBearOB or belowBearOB
//====================
// SIGNALS
//====================
longSignal = bullTrend and nearVWAP and close > open and momLong and longOBok
shortSignal = bearTrend and nearVWAP and close < open and momShort and shortOBok
//====================
// PLOTS
//====================
plot(showEMAs ? emaFast : na, "EMA Fast", color=color.new(color.aqua, 0), linewidth=2)
plot(showEMAs ? emaSlow : na, "EMA Slow", color=color.new(color.orange, 0), linewidth=2)
plot(showVWAP ? vwapVal : na, "VWAP", color=color.new(color.fuchsia, 0), linewidth=2)
plotshape(longSignal, title="LONG", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), text="LONG", textcolor=color.white, size=size.tiny)
plotshape(shortSignal, title="SHORT", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), text="SHORT", textcolor=color.white, size=size.tiny)
//====================
// HELPERS
//====================
f_safe_risk(_entry, _sl, _isLong) =>
float slOut = _sl
if _isLong and (na(slOut) or slOut >= _entry)
slOut := _entry - math.max(atrVal * 0.5, minTick)
if (not _isLong) and (na(slOut) or slOut <= _entry)
slOut := _entry + math.max(atrVal * 0.5, minTick)
slOut
f_safe_tp(_entry, _tp, _isLong, _fallbackR, _rrMult) =>
float tpOut = _tp
if _isLong and (na(tpOut) or tpOut <= _entry)
tpOut := _entry + _fallbackR * _rrMult
if (not _isLong) and (na(tpOut) or tpOut >= _entry)
tpOut := _entry - _fallbackR * _rrMult
tpOut
//====================
// REACTION CLUSTERING HELPERS
//====================
f_reaction_avg(_useHigh, _needAboveEntry, _entry, _k, _lookback, _tol, _minTouches) =>
float entry = _entry
float tolAbs = atrVal * _tol
float[] cLevel = array.new_float()
int[] cCount = array.new_int()
for i = 0 to _lookback - 1
float pv = na
pv := _useHigh ? ph[i] : pl[i]
if not na(pv)
bool clustered = false
int n = array.size(cLevel)
if n > 0
for j = 0 to n - 1
float lv = array.get(cLevel, j)
if math.abs(pv - lv) <= tolAbs
int cc = array.get(cCount, j)
float newLv = (lv * cc + pv) / (cc + 1)
array.set(cLevel, j, newLv)
array.set(cCount, j, cc + 1)
clustered := true
break
if not clustered
array.push(cLevel, pv)
array.push(cCount, 1)
int n2 = array.size(cLevel)
if n2 == 0
na
else
float sumPicked = 0.0
int cntPicked = 0
bool[] picked = array.new_bool(n2, false)
for pick = 0 to _k - 1
int bestIdx = na
int bestCnt = -1
for j = 0 to n2 - 1
if not array.get(picked, j)
float lv = array.get(cLevel, j)
int cc = array.get(cCount, j)
bool sideOk = _needAboveEntry ? (lv > entry) : (lv < entry)
bool touchOk = cc >= _minTouches
if sideOk and touchOk and cc > bestCnt
bestCnt := cc
bestIdx := j
if not na(bestIdx)
array.set(picked, bestIdx, true)
sumPicked += array.get(cLevel, bestIdx)
cntPicked += 1
cntPicked > 0 ? (sumPicked / cntPicked) : na
//====================
// OB-BASED SL / TP1 / TP2
//====================
var line slLine = na
var line tp1Line = na
var line tp2Line = na
var label slLab = na
var label tp1Lab = na
var label tp2Lab = na
f_clear_drawings() =>
if not na(slLine)
line.delete(slLine)
if not na(tp1Line)
line.delete(tp1Line)
if not na(tp2Line)
line.delete(tp2Line)
if not na(slLab)
label.delete(slLab)
if not na(tp1Lab)
label.delete(tp1Lab)
if not na(tp2Lab)
label.delete(tp2Lab)
f_calc_levels(_isLong) =>
float entry = close
float buffer = atrVal * obBufATR
float sl = na
float tp1 = na
float tp2 = na
if _isLong
float slReact = useReactionLevels ? f_reaction_avg(false, false, entry, reactK, reactLookback, reactTolATR, reactMinTouches) : na
float tpReact = useReactionLevels ? f_reaction_avg(true, true, entry, reactK, reactLookback, reactTolATR, reactMinTouches) : na
sl := not na(slReact) ? (slReact - buffer) : (hasBullOB ? (bullOBBot - buffer) : (entry - atrVal))
sl := f_safe_risk(entry, sl, true)
float R = math.max(entry - sl, minTick)
float tp1_rr = entry + R * tp1RR
float tp1_swing = not na(lastSwingHigh) ? lastSwingHigh : tp1_rr
tp1 := not na(tpReact) ? tpReact : ((tp1Mode == "RR") ? tp1_rr : tp1_swing)
tp1 := f_safe_tp(entry, tp1, true, R, tp1RR)
tp2 := entry + R * tp2RR
tp2 := f_safe_tp(entry, tp2, true, R, tp2RR)
else
float slReact = useReactionLevels ? f_reaction_avg(true, true, entry, reactK, reactLookback, reactTolATR, reactMinTouches) : na
float tpReact = useReactionLevels ? f_reaction_avg(false, false, entry, reactK, reactLookback, reactTolATR, reactMinTouches) : na
sl := not na(slReact) ? (slReact + buffer) : (hasBearOB ? (bearOBTop + buffer) : (entry + atrVal))
sl := f_safe_risk(entry, sl, false)
float R = math.max(sl - entry, minTick)
float tp1_rr = entry - R * tp1RR
float tp1_swing = not na(lastSwingLow) ? lastSwingLow : tp1_rr
tp1 := not na(tpReact) ? tpReact : ((tp1Mode == "RR") ? tp1_rr : tp1_swing)
tp1 := f_safe_tp(entry, tp1, false, R, tp1RR)
tp2 := entry - R * tp2RR
tp2 := f_safe_tp(entry, tp2, false, R, tp2RR)
[entry, sl, tp1, tp2]
[entryL, slL, tp1L, tp2L] = f_calc_levels(true)
[entryS, slS, tp1S, tp2S] = f_calc_levels(false)
if showLevels and (longSignal or shortSignal)
f_clear_drawings()
bool isLong = longSignal
float slP = isLong ? slL : slS
float tp1P = isLong ? tp1L : tp1S
float tp2P = isLong ? tp2L : tp2S
slLine := line.new(bar_index, slP, bar_index + 120, slP, extend=extend.right, color=color.new(color.red, 0), width=2)
tp1Line := line.new(bar_index, tp1P, bar_index + 120, tp1P, extend=extend.right, color=color.new(color.green, 0), width=2, style=line.style_dashed)
tp2Line := line.new(bar_index, tp2P, bar_index + 120, tp2P, extend=extend.right, color=color.new(color.green, 0), width=2)
int p1 = partial1
int p2 = 100 - partial1
string slTxt = useReactionLevels ? "SL (dip ort.)" : "SL (OB arkası)"
string tp1Txt = useReactionLevels ? "HEDEF (tepe ort.)" : "TP1"
slLab := label.new(bar_index, slP, slTxt, style=label.style_label_left, textcolor=color.white, color=color.new(color.red, 0), size=size.tiny)
tp1Lab := label.new(bar_index, tp1P, tp1Txt + " (" + str.tostring(p1) + "%)", style=label.style_label_left, textcolor=color.white, color=color.new(color.green, 0), size=size.tiny)
tp2Lab := label.new(bar_index, tp2P, "TP2 (" + str.tostring(p2) + "%)", style=label.style_label_left, textcolor=color.white, color=color.new(color.green, 0), size=size.tiny)
//====================
// ALERTS
//====================
alertcondition(longSignal, title="1m LONG", message="1m Scalper LONG: EMA trend + VWAP yakın + RSI + OB | Reaction TP1/SL aktif (varsa), TP2 RR")
alertcondition(shortSignal, title="1m SHORT", message="1m Scalper SHORT: EMA trend + VWAP yakın + RSI + OB | Reaction TP1/SL aktif (varsa), TP2 RR")
//====================
// DEBUG / LOGGING
//====================
grpDbg = "Debug / Log"
dbgEnabled = input.bool(true, "Debug aktif", group=grpDbg)
dbgOnSignals = input.bool(true, "Sadece sinyalde logla", group=grpDbg)
dbgMaxLogs = input.int(30, "Maks log (label) sayısı", group=grpDbg, minval=5, maxval=200)
dbgShowTable = input.bool(true, "Debug table göster", group=grpDbg)
dbgTableRows = input.int(12, "Table satır sayısı", group=grpDbg, minval=5, maxval=40)
dbgCompact = input.bool(true, "Kompakt metin", group=grpDbg)
var label[] dbgLabels = array.new_label()
var string[] dbgRows = array.new_string()
var table dbgTbl = na
if dbgEnabled and dbgShowTable and na(dbgTbl)
dbgTbl := table.new(position.top_right, 1, dbgTableRows + 1, border_width=1)
f_bool(_b) => _b ? "1" : "0"
f_reason(_isLong) =>
string dir = _isLong ? "L" : "S"
string tr = _isLong ? (bullTrend ? "trend" : "NOTtrend") : (bearTrend ? "trend" : "NOTtrend")
string vwp = nearVWAP ? "vwap" : "noVwap"
string mom = _isLong ? (momLong ? "rsi" : "noRsi") : (momShort ? "rsi" : "noRsi")
string obok = _isLong ? (longOBok ? "obOK" : "obNO") : (shortOBok ? "obOK" : "obNO")
dir + "|" + tr + "|" + vwp + "|" + mom + "|" + obok
f_tbl_render() =>
if dbgEnabled and dbgShowTable and not na(dbgTbl)
table.clear(dbgTbl, 0, 0)
table.cell(dbgTbl, 0, 0, "DEBUG LOG (en yeni en üstte)", text_size=size.small)
int n = array.size(dbgRows)
int lim = math.min(n, dbgTableRows)
for i = 0 to lim - 1
table.cell(dbgTbl, 0, i + 1, array.get(dbgRows, i), text_size=size.tiny)
f_tbl_push(_text) =>
if dbgEnabled and dbgShowTable and not na(dbgTbl)
array.unshift(dbgRows, _text)
if array.size(dbgRows) > dbgTableRows
array.pop(dbgRows)
f_tbl_render()
f_debug_emit(_isLong, _entry, _sl, _tp1, _tp2) =>
if not dbgEnabled
na
else
float R = _isLong ? math.max(_entry - _sl, minTick) : math.max(_sl - _entry, minTick)
float RR1 = _isLong ? ((_tp1 - _entry) / R) : ((_entry - _tp1) / R)
float RR2 = _isLong ? ((_tp2 - _entry) / R) : ((_entry - _tp2) / R)
string id = "bar=" + str.tostring(bar_index) + " t=" + str.tostring(time)
string rs = f_reason(_isLong)
string txt = ""
if dbgCompact
txt := "#" + id + " " + (_isLong ? "LONG" : "SHORT") +
" | " + rs +
" | RSI=" + str.tostring(rsiVal, format.mintick) +
" | dVWAP=" + str.tostring(math.abs(close - vwapVal), format.mintick) +
" | ATR=" + str.tostring(atrVal, format.mintick) +
" | E=" + str.tostring(_entry, format.mintick) +
" SL=" + str.tostring(_sl, format.mintick) +
" TP1=" + str.tostring(_tp1, format.mintick) +
" TP2=" + str.tostring(_tp2, format.mintick) +
" | RR1=" + str.tostring(RR1, "#.##") +
" RR2=" + str.tostring(RR2, "#.##")
else
txt := "ID: " + id + "\n" +
"DIR: " + (_isLong ? "LONG" : "SHORT") + " | " + rs + "\n" +
"trend(bull/bear): " + f_bool(bullTrend) + "/" + f_bool(bearTrend) + "\n" +
"nearVWAP: " + f_bool(nearVWAP) + " (|C-VWAP|=" + str.tostring(math.abs(close - vwapVal), format.mintick) + ")\n" +
"RSI: " + str.tostring(rsiVal, format.mintick) + " | momL/momS: " + f_bool(momLong) + "/" + f_bool(momShort) + "\n" +
"OB: hasBull/hasBear=" + f_bool(hasBullOB) + "/" + f_bool(hasBearOB) +
" inBull/inBear=" + f_bool(inBullOB) + "/" + f_bool(inBearOB) + "\n" +
"ENTRY=" + str.tostring(_entry, format.mintick) +
" SL=" + str.tostring(_sl, format.mintick) +
" TP1=" + str.tostring(_tp1, format.mintick) +
" TP2=" + str.tostring(_tp2, format.mintick) + "\n" +
"R=" + str.tostring(R, format.mintick) +
" RR1=" + str.tostring(RR1, "#.##") +
" RR2=" + str.tostring(RR2, "#.##")
float lbY = _isLong ? low : high
label lb = label.new(bar_index, lbY, txt)
label.set_style(lb, _isLong ? label.style_label_up : label.style_label_down)
label.set_textcolor(lb, color.white)
label.set_color(lb, _isLong ? color.new(color.green, 0) : color.new(color.red, 0))
label.set_size(lb, size.tiny)
array.push(dbgLabels, lb)
int sz = array.size(dbgLabels)
if sz > dbgMaxLogs
label old = array.shift(dbgLabels)
if not na(old)
label.delete(old)
f_tbl_push(txt)
// FIX: sinyal yokken isLong=false diye SHORT loglama hatası giderildi
bool dbgShouldLog = dbgEnabled and (dbgOnSignals ? (longSignal or shortSignal) : true)
if dbgShouldLog
bool hasSig = longSignal or shortSignal
bool isL = hasSig ? longSignal : bullTrend
float e = hasSig ? (isL ? entryL : entryS) : close
float sl = hasSig ? (isL ? slL : slS) : (isL ? close - atrVal : close + atrVal)
float t1 = hasSig ? (isL ? tp1L : tp1S) : (isL ? close + atrVal : close - atrVal)
float t2 = hasSig ? (isL ? tp2L : tp2S) : (isL ? close + atrVal * 2.0 : close - atrVal * 2.0)
f_debug_emit(isL, e, sl, t1, t2)
//====================
// OUTCOME TRACKER
//====================
grpOut = "Outcome Tracker"
outEnabled = input.bool(true, "TP/SL outcome log aktif", group=grpOut)
outMaxBars = input.int(250, "Trade max takip barı", group=grpOut, minval=20, maxval=5000)
outLabelHits = input.bool(true, "TP/SL vurunca label bas", group=grpOut)
var bool inTrade = false
var bool tIsLong = false
var float tEntry = na
var float tSL = na
var float tTP1 = na
var float tTP2 = na
var int tStartBar = na
var bool tHitTP1 = false
var int statTrades = 0
var int statSL = 0
var int statTP2 = 0
var int statTP1Touch = 0
var int statTimeout = 0
f_out_log(_txt) =>
if dbgEnabled and dbgShowTable
f_tbl_push(_txt)
f_hit_label(_y, _txt, _isGood) =>
if outLabelHits
label lb2 = label.new(bar_index, _y, _txt)
label.set_textcolor(lb2, color.white)
label.set_color(lb2, _isGood ? color.new(color.green, 0) : color.new(color.red, 0))
label.set_size(lb2, size.tiny)
label.set_style(lb2, _isGood ? label.style_label_up : label.style_label_down)
// FIX: açık trade varken yeni trade başlatma
if outEnabled and (longSignal or shortSignal) and not inTrade
inTrade := true
tIsLong := longSignal
tEntry := tIsLong ? entryL : entryS
tSL := tIsLong ? slL : slS
tTP1 := tIsLong ? tp1L : tp1S
tTP2 := tIsLong ? tp2L : tp2S
tStartBar := bar_index
tHitTP1 := false
statTrades += 1
string startTxt = "START " + (tIsLong ? "LONG" : "SHORT") +
" | bar=" + str.tostring(bar_index) +
" E=" + str.tostring(tEntry, format.mintick) +
" SL=" + str.tostring(tSL, format.mintick) +
" TP1=" + str.tostring(tTP1, format.mintick) +
" TP2=" + str.tostring(tTP2, format.mintick)
f_out_log(startTxt)
if outEnabled and inTrade
bool timeout = (bar_index - tStartBar) > outMaxBars
if tIsLong
bool slHit = low <= tSL
bool tp1Hit = high >= tTP1
bool tp2Hit = high >= tTP2
if slHit
statSL += 1
f_out_log("HIT SL | bar=" + str.tostring(bar_index) + " | E=" + str.tostring(tEntry, format.mintick) + " SL=" + str.tostring(tSL, format.mintick))
f_hit_label(tSL, "SL HIT", false)
inTrade := false
else
if (not tHitTP1) and tp1Hit
tHitTP1 := true
statTP1Touch += 1
f_out_log("HIT TP1 | bar=" + str.tostring(bar_index) + " | TP1=" + str.tostring(tTP1, format.mintick))
f_hit_label(tTP1, "TP1 HIT", true)
if tp2Hit
statTP2 += 1
f_out_log("HIT TP2 | bar=" + str.tostring(bar_index) + " | TP2=" + str.tostring(tTP2, format.mintick))
f_hit_label(tTP2, "TP2 HIT", true)
inTrade := false
if timeout
statTimeout += 1
f_out_log("TIMEOUT | bar=" + str.tostring(bar_index) + " | hitTP1=" + (tHitTP1 ? "1" : "0"))
inTrade := false
else
bool slHit = high >= tSL
bool tp1Hit = low <= tTP1
bool tp2Hit = low <= tTP2
if slHit
statSL += 1
f_out_log("HIT SL | bar=" + str.tostring(bar_index) + " | E=" + str.tostring(tEntry, format.mintick) + " SL=" + str.tostring(tSL, format.mintick))
f_hit_label(tSL, "SL HIT", false)
inTrade := false
else
if (not tHitTP1) and tp1Hit
tHitTP1 := true
statTP1Touch += 1
f_out_log("HIT TP1 | bar=" + str.tostring(bar_index) + " | TP1=" + str.tostring(tTP1, format.mintick))
f_hit_label(tTP1, "TP1 HIT", true)
if tp2Hit
statTP2 += 1
f_out_log("HIT TP2 | bar=" + str.tostring(bar_index) + " | TP2=" + str.tostring(tTP2, format.mintick))
f_hit_label(tTP2, "TP2 HIT", true)
inTrade := false
if timeout
statTimeout += 1
f_out_log("TIMEOUT | bar=" + str.tostring(bar_index) + " | hitTP1=" + (tHitTP1 ? "1" : "0"))
inTrade := false
if outEnabled and dbgEnabled and dbgShowTable and not na(dbgTbl)
string st = "STATS | trades=" + str.tostring(statTrades) + " sl=" + str.tostring(statSL) + " tp1Touch=" + str.tostring(statTP1Touch) + " tp2=" + str.tostring(statTP2) + " timeout=" + str.tostring(statTimeout)
table.cell(dbgTbl, 0, 0, st, text_size=size.small)