-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathspx-30m-options.txt
1685 lines (1288 loc) · 75.9 KB
/
spx-30m-options.txt
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @donald
//@version=5
indicator("SPX 30M - Trading Chart", shorttitle="SPX 30M - Trading Chart", overlay=true)
max_bars_back(time, 5000)
utc = "UTC-7"
import jdehorty/KernelFunctions/2 as kernels
/////////////////////////////////////////////////////////////
// Detect sideway start
highestHigh2 = kernels.rationalQuadratic(ta.highest(high, 3), 3, 8, 25)
lowestLow2 = kernels.rationalQuadratic(ta.lowest(low, 3), 3, 8, 25)
highestHighOutside2 = kernels.rationalQuadratic(ta.highest(high, 3), 3, 8, 25)
lowestLowOutside2 = kernels.rationalQuadratic(ta.lowest(low, 3), 3, 8, 25)
prd = input.int(defval=18, title='Loopback Period', minval=2, maxval=50)
conslen = input.int(defval=12, title='Min Consolidation Length', minval=2, maxval=20)
float hb2_ = ta.highestbars(prd) == 0 ? high : na
float lb2_ = ta.lowestbars(prd) == 0 ? low : na
var int dir = 0
float zz = na
float pp2 = na
iff_1 = lb2_ and na(hb2_) ? -1 : dir
dir := hb2_ and na(lb2_) ? 1 : iff_1
if hb2_ and lb2_
if dir == 1
zz := hb2_
zz
else
zz := lb2_
zz
else
iff_1 = lb2_ ? lb2_ : na
zz := hb2_ ? hb2_ : iff_1
zz
for x = 0 to 1000 by 1
if na(close) or dir != dir[x]
break
if zz[x]
if na(pp2)
pp2 := zz[x]
pp2
else
if dir[x] == 1 and zz[x] > pp2
pp2 := zz[x]
pp2
if dir[x] == -1 and zz[x] < pp2
pp2 := zz[x]
pp2
var int conscnt = 0
var float condhigh = na
var float condlow = na
float H_ = ta.highest(3) //highestHighOutside2
float L_ = ta.lowest(3) //lowestLowOutside2
var line upline = na
var line dnline = na
bool breakoutup = false
bool breakoutdown = false
if ta.change(pp2)
if conscnt > conslen
if pp2 > condhigh
breakoutup := true
breakoutup
if pp2 < condlow
breakoutdown := true
breakoutdown
if conscnt > 0 and pp2 <= condhigh and pp2 >= condlow
conscnt += 1
conscnt
else
conscnt := 0
conscnt
else
conscnt += 1
conscnt
if conscnt >= conslen
if conscnt == conslen
condhigh := H_
condlow := L_
condlow
else
line.delete(upline)
line.delete(dnline)
condhigh := math.max(condhigh, high)
condlow := math.min(condlow, low)
condlow
// sideway lines
// upline := line.new(bar_index, condhigh, bar_index - conscnt, condhigh, color=color.orange, style=line.style_solid, width = 2)
// dnline := line.new(bar_index, condlow, bar_index - conscnt, condlow, color=color.orange, style=line.style_solid, width = 2)
//line.delete(upline[1])
//line.delete(dnline[1])
dnline
// Detect sideway end
////////////////////////////////////////////////////////////
// ~~~~~~~~~~~ INSHORTS ~~~~~~~~~~~ //
showRegression = false //input.bool(false, "Show Regression", group="Momentum", tooltip="Sometimes it can be difficult to visualize the zones with signals enabled.")
zoneLengths = 50 //input.int(50, "Zone Inside Length", group="Momentum", tooltip="The Zone Inside is the Inner zone of the High and Low. This is the length used to create it.")
zoneOutsideLengths = 75 //input.int(75, "Zone Outside Length", group="Momentum", tooltip="The Zone Outside is the Outer zone of the High and Low. This is the length used to create it.")
smoothingLength = 14 //input.int(14, "Smoothing length", group="Momentum", tooltip="Smoothing length is the length used to smooth out our Bullish and Bearish signals, along with our Overly Bullish and Overly Bearish Signals.")
// Kernel Settings
lookbackWindow = 18 //input.int(18, "Lookback Window", tooltip="The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50", group="Kernel Settings")
relativeWeighting = 8 //input.float(8., "Relative Weighting", step=0.25, tooltip="Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25", group="Kernel Settings")
startBar = 25 //input.int(25, "Start Regression at Bar", tooltip="Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25", group="Kernel Settings")
// ~~~~~~~~~~~ CALCULATIONS ~~~~~~~~~~~ //
//Kernal Zones
high15 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=high, lookahead=barmerge.lookahead_on)
low15 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=low, lookahead=barmerge.lookahead_on)
close15 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=close, lookahead=barmerge.lookahead_on)
highestHigh = kernels.rationalQuadratic(ta.highest(high15, zoneLengths), lookbackWindow, relativeWeighting, startBar)
lowestLow = kernels.rationalQuadratic(ta.lowest(low15, zoneLengths), lookbackWindow, relativeWeighting, startBar)
highestHighOutside = kernels.rationalQuadratic(ta.highest(high15, zoneOutsideLengths), lookbackWindow, relativeWeighting, startBar)
lowestLowOutside = kernels.rationalQuadratic(ta.lowest(low15, zoneOutsideLengths), lookbackWindow, relativeWeighting, startBar)
kernClose = kernels.rationalQuadratic(close15, lookbackWindow, relativeWeighting, startBar)
zoneMid = math.avg(highestHigh, lowestLow)
//Bullish and bearish (these hold momentum and may be a safe way to know if the momentum is still going strong for the trend)
bullishBar = kernels.rationalQuadratic(close, lookbackWindow, relativeWeighting, startBar) > kernels.rationalQuadratic(ta.highest(ta.vwma(ohlc4, smoothingLength), smoothingLength), lookbackWindow, relativeWeighting, startBar)
bearishBar = kernels.rationalQuadratic(close, lookbackWindow, relativeWeighting, startBar) < kernels.rationalQuadratic(ta.lowest(ta.vwma(ohlc4, smoothingLength), smoothingLength), lookbackWindow, relativeWeighting, startBar)
//Very bullish and bearish (these may represent when the momentum is about to change as they are almost TOO Bullish and Bearish
rsi = kernels.rationalQuadratic(ta.rsi(close, smoothingLength), lookbackWindow, relativeWeighting, startBar)
vol = kernels.rationalQuadratic(volume, lookbackWindow, relativeWeighting, startBar)
rsi21 = ta.rsi(close, 21)
ema11 = ta.ema(close, 11)
ema21 = ta.ema(close, 21)
ema200 = ta.ema(close, 200)
//ema21_2 = kernels.rationalQuadratic(ta.ema(close, 21), lookbackWindow, relativeWeighting, startBar)
//Kernal Crossing Calculations
kern1 = kernels.rationalQuadratic(close15, lookbackWindow, relativeWeighting, startBar)
kern2 = kernels.gaussian(close15, lookbackWindow - 2, startBar)
// Kernel Crossovers
bool isBullishCross = ta.crossover(kern2, kern1)
bool isBearishCross = ta.crossunder(kern2, kern1)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//****************************************************************************************************************************************************//
lengthInput = 100 //input.int(100, title="Length", minval = 1, maxval = 5000)
sourceInput = close //input.source(close, title="Source")
group1 = "Channel Settings"
useUpperDevInput = true //input.bool(true, title="Upper Deviation", inline = "Upper Deviation", group = group1)
upperMultInput = 2.0 //input.float(2.0, title="", inline = "Upper Deviation", group = group1)
useLowerDevInput = true //input.bool(true, title="Lower Deviation", inline = "Lower Deviation", group = group1)
lowerMultInput = 2.0 //input.float(2.0, title="", inline = "Lower Deviation", group = group1)
group2 = "Display Settings"
showPearsonInput = true //input.bool(true, "Show Pearson's R", group = group2)
extendLeftInput = false //input.bool(false, "Extend Lines Left", group = group2)
extendRightInput = true //input.bool(true, "Extend Lines Right", group = group2)
extendStyle = switch
extendLeftInput and extendRightInput => extend.both
extendLeftInput => extend.left
extendRightInput => extend.right
=> extend.none
group3 = "Color Settings"
colorUpper = color.new(color.blue, 85) //input.color(color.new(color.blue, 85), "", inline = group3, group = group3)
colorLower = color.new(color.red, 85) //input.color(color.new(color.red, 85), "", inline = group3, group = group3)
calcSlope(source, length) =>
max_bars_back(source, 5000)
if not barstate.islast or length <= 1
[float(na), float(na), float(na)]
else
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 0 to length - 1 by 1
val = source[i]
per = i + 1.0
sumX += per
sumY += val
sumXSqr += per * per
sumXY += val * per
slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX)
average = sumY / length
intercept = average - slope * sumX / length + slope
[slope, average, intercept]
[s, avg, i] = calcSlope(sourceInput, lengthInput)
startPrice = i + s * (lengthInput - 1)
endPrice = i
var line baseLine = na
// if showRegression
// if na(baseLine) and not na(startPrice)
// baseLine := line.new(bar_index - lengthInput + 1, startPrice, bar_index, endPrice, width=1, extend=extendStyle, color=color.new(colorLower, 0))
// else
// line.set_xy1(baseLine, bar_index - lengthInput + 1, startPrice)
// line.set_xy2(baseLine, bar_index, endPrice)
// na
calcDev(source, length, slope, average, intercept) =>
upDev = 0.0
dnDev = 0.0
stdDevAcc = 0.0
dsxx = 0.0
dsyy = 0.0
dsxy = 0.0
periods = length - 1
daY = intercept + slope * periods / 2
val = intercept
for j = 0 to periods by 1
price = high[j] - val
if price > upDev
upDev := price
price := val - low[j]
if price > dnDev
dnDev := price
price := source[j]
dxt = price - average
dyt = val - daY
price -= val
stdDevAcc += price * price
dsxx += dxt * dxt
dsyy += dyt * dyt
dsxy += dxt * dyt
val += slope
stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
[stdDev, pearsonR, upDev, dnDev]
[stdDev, pearsonR, upDev, dnDev] = calcDev(sourceInput, lengthInput, s, avg, i)
upperStartPrice = startPrice + (useUpperDevInput ? upperMultInput * stdDev : upDev)
upperEndPrice = endPrice + (useUpperDevInput ? upperMultInput * stdDev : upDev)
var line upper = na
lowerStartPrice = startPrice + (useLowerDevInput ? -lowerMultInput * stdDev : -dnDev)
lowerEndPrice = endPrice + (useLowerDevInput ? -lowerMultInput * stdDev : -dnDev)
var float lowestEndPrice = 0.0
if lowerEndPrice
lowestEndPrice := lowerEndPrice
var float highestEndPrice = 0.0
if upperEndPrice
highestEndPrice := upperEndPrice
var line lower = na
// if showRegression
// if na(upper) and not na(upperStartPrice)
// upper := line.new(bar_index - lengthInput + 1, upperStartPrice, bar_index, upperEndPrice, width=1, extend=extendStyle, color=color.new(colorUpper, 0))
// else
// line.set_xy1(upper, bar_index - lengthInput + 1, upperStartPrice)
// line.set_xy2(upper, bar_index, upperEndPrice)
// na
// if na(lower) and not na(lowerStartPrice)
// lower := line.new(bar_index - lengthInput + 1, lowerStartPrice, bar_index, lowerEndPrice, width=1, extend=extendStyle, color=color.white)
// else
// line.set_xy1(lower, bar_index - lengthInput + 1, lowerStartPrice)
// line.set_xy2(lower, bar_index, lowerEndPrice)
// na
// linefill.new(upper, baseLine, color = colorUpper)
// linefill.new(baseLine, lower, color = colorLower)
float trend = math.sign(startPrice - endPrice)
//alertcondition(sourceInput > line.get_price(upper, bar_index) or sourceInput < line.get_price(lower, bar_index), title='Regression Channel Exited', message="The price movement has exited Regression Channel's bounds")
//alertcondition(trend[1] >= 0 and trend < 0, title='Switched to Uptrend', message='The Regression Channel trend switched from Downtrend to Uptrend')
//alertcondition(trend[1] <= 0 and trend > 0, title='Switched to Downtrend', message='The Regression Channel trend switched from Uptrend to Downtrend')
// Pearson's R
var label r = na
// label.delete(r[1])
// if showPearsonInput and not na(pearsonR)
// r := label.new(bar_index - lengthInput + 1, lowerStartPrice, str.tostring(pearsonR, "#.################"), color = color.new(color.white, 100), textcolor=color.new(colorUpper, 0), size=size.normal, style=label.style_label_up)
//****************************************************************************************************************************************************//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// spx 13m - 16
//
param25 = input.float(25, title = "Default - Param trailing 25*2 ***", group = "Default")
param19 = input.float(19, title = "Default - Param trailing 19 ***", group = "Default")
param18 = input.float(18, title = "Default - Param trailing 18 ***", group = "Default")
if str.tostring(timeframe.period) == '3'
param25 := 20
param19 := 22
param18 := 18
if str.tostring(timeframe.period) == '10'
param25 := input.float(20, title = "10m - Param trailing 20 ***", group = "10M")
param19 := input.float(23, title = "10m - Param trailing 23 ***", group = "10M")
param18 := input.float(19, title = "10m - Param trailing 19 ***", group = "10M")
// if syminfo.ticker == 'ESU2024'
// param25 := 16
// param19 := 27
// param18 := 18
if str.tostring(timeframe.period) == '13'
param25 := input.float(18, title = "13m - Param trailing 18 ***", group = "13M")
param19 := input.float(25, title = "13m - Param trailing 25 ***", group = "13M")
param18 := input.float(15, title = "13m - Param trailing 15 ***", group = "13M")
if str.tostring(timeframe.period) == '15'
param25 := input.float(16, title = "15m - Param trailing 20 ***", group = "15M")
param19 := input.float(21, title = "15m - Param trailing 22 ***", group = "15M")
param18 := input.float(21, title = "15m - Param trailing 21 ***", group = "15M")
if str.tostring(timeframe.period) == '18'
param25 := 20
param19 := 20
param18 := 17
if str.tostring(timeframe.period) == '30'
param25 := 20
param19 := 22
param18 := 21
if syminfo.ticker == 'SPY'
param25 := param25/10
param19 := param19/10
param18 := param19/10
// param28 = input.float(32, title = "Param trailing exit long 28", group = "Exit Long")
// param10 = input.float(9, title = "Param trailing exit long 10", group = "Exit Long")
// param16 = input.float(12, title = "Param trailing exit long 16", group = "Exit Long")
// param11 = input.float(20, title = "Param trailing exit short 10", group = "Exit Short")
// param15 = input.float(11, title = "Param trailing exit short 15", group = "Exit Short")
// param29 = input.float(28, title = "Param trailing exit short 28", group = "Exit Short")
param5 = 5 //input.float(5, title = "Param trailing 5")
param3 = 3 //input.float(3, title = "Param trailing 3")
param9 = 9 //input.float(9, title = "Param trailing 9")
param40 = 40 //input.float(40, title = "Param trailing 40")
param20 = 20 //input.float(20, title = "Param trailing 20")
param17 = 17 //input.float(17, title = "Param trailing 17")
param27 = 27 //input.float(27, title = "Param trailing 27")
param30 = 30 //input.float(30, title = "Param trailing 30")
startSession = timestamp("GMT-7", year, month, dayofmonth, 06, 45)
endSession = timestamp("GMT-7", year, month, dayofmonth, 11, 30)
extendedStartSession = timestamp("GMT-7", year, month, dayofmonth, 06, 45)
extendedEndSession = timestamp("GMT-7", year, month, dayofmonth, 16, 00)
atr = kernels.rationalQuadratic(ta.atr(21), lookbackWindow, relativeWeighting, startBar)
sma20 = kernels.rationalQuadratic(ta.wma(atr, 20), lookbackWindow, relativeWeighting, startBar)
volatilityFilter = atr > sma20
isTradeWindow = (time >= startSession and time <= endSession) //and volatilityFilter
//isTradeWindow = hour(time_close, utc) == 6 and minute(time_close, utc) >=30 or hour(time_close, utc) > 6 and hour(time_close, utc) < 13
float pull_back = 2
if str.format("{0}", timeframe.period) == '2'
pull_back := 1.4
if str.format("{0}", timeframe.period) == '5'
pull_back := 1
leftBars = 5
rightBars = 3
// Make sure length and lengthSmooth settings match your COG indicator
length = 9
lengthSmooth = 3
COG = ta.cog(close, length)
sCOG = ta.rma(COG, lengthSmooth)
ph = ta.pivothigh(sCOG, leftBars, rightBars)
pl = ta.pivotlow(sCOG, leftBars, rightBars)
phvalue1 = ta.valuewhen(ph, high[rightBars], 0)
phbar1 = ta.valuewhen(ph, bar_index[rightBars], 0), phv1low = ta.valuewhen(ph, close[rightBars]>open[rightBars] ? close[rightBars] : open[rightBars], 0)
phvalue2 = ta.valuewhen(ph, high[rightBars], 1)
phbar2 = ta.valuewhen(ph, bar_index[rightBars], 1), phv2low = ta.valuewhen(ph, close[rightBars]>open[rightBars] ? close[rightBars] : open[rightBars], 1)
plvalue1 = ta.valuewhen(pl, low[rightBars], 0)
plbar1 = ta.valuewhen(pl, bar_index[rightBars], 0), plv1low = ta.valuewhen(pl, close[rightBars]<open[rightBars] ? close[rightBars] : open[rightBars], 0)
plvalue2 = ta.valuewhen(pl, low[rightBars], 1)
plbar2 = ta.valuewhen(pl, bar_index[rightBars], 1)
// Initialize variables for use in findPreviousHighsAndLows function
if_pl = not na(pl) ? -1 : na
hl = not na(ph) ? 1 : if_pl
if_pl_value = not na(pl) ? pl : na
if_ph_value = not na(ph) ? ph : if_pl_value
valuewhen_1 = ta.valuewhen(hl, hl, 1)
valuewhen_2 = ta.valuewhen(if_ph_value, if_ph_value, 1)
if_ph_value := not na(pl) and hl == -1 and valuewhen_1 == -1 and pl > valuewhen_2 ? na : if_ph_value
valuewhen_3 = ta.valuewhen(hl, hl, 1)
valuewhen_4 = ta.valuewhen(if_ph_value, if_ph_value, 1)
if_ph_value := not na(ph) and hl == 1 and valuewhen_3 == 1 and ph < valuewhen_4 ? na : if_ph_value
valuewhen_5 = ta.valuewhen(hl, hl, 1)
valuewhen_6 = ta.valuewhen(if_ph_value, if_ph_value, 1)
hl := hl == -1 and valuewhen_5 == 1 and if_ph_value > valuewhen_6 ? na : hl
valuewhen_7 = ta.valuewhen(hl, hl, 1)
valuewhen_8 = ta.valuewhen(if_ph_value, if_ph_value, 1)
hl := hl == 1 and valuewhen_7 == -1 and if_ph_value < valuewhen_8 ? na : hl
if_ph_value := na(hl) ? na : if_ph_value
// Finds previous three points (b, c, d, e)
findPreviousHighsAndLows() =>
ehl = hl == 1 ? -1 : 1
loc1 = 0.0
loc2 = 0.0
loc3 = 0.0
loc4 = 0.0
xx = 0
for x = 1 to 1000 by 1
if hl[x] == ehl and not na(if_ph_value[x])
loc1 := if_ph_value[x]
xx := x + 1
break
ehl := hl
for x = xx to 1000 by 1
if hl[x] == ehl and not na(if_ph_value[x])
loc2 := if_ph_value[x]
xx := x + 1
break
ehl := hl == 1 ? -1 : 1
for x = xx to 1000 by 1
if hl[x] == ehl and not na(if_ph_value[x])
loc3 := if_ph_value[x]
xx := x + 1
break
ehl := hl
for x = xx to 1000 by 1
if hl[x] == ehl and not na(if_ph_value[x])
loc4 := if_ph_value[x]
break
[loc1, loc2, loc3, loc4]
float a = na
float b = na
float c = na
float d = na
float e = na
if not na(hl)
[loc1, loc2, loc3, loc4] = findPreviousHighsAndLows()
a := if_ph_value
b := loc1
c := loc2
d := loc3
e := loc4
e
_hl = not na(if_ph_value) and (a >= c and b > c and b > d and d > c and d > e or a < b and a > c and b < d)
_lh = not na(if_ph_value) and (a <= c and b < c and b < d and d < c and d < e or a > b and a < c and b > d)
// If we also wanted higher highs and lower lows, we could use the following:
_hh = not na(if_ph_value) and a > b and a > c and c > b and c > d
_ll = not na(if_pl_value) and a < b and a < c and c < b and c < d
extend_fibo = 5
extend_sup_res = 5
var float high_point = 0
var float low_point = 0
if _ll
// line.new(bar_index, high, bar_index+8, high, style=line.style_solid, color=color.yellow, width = 1)
high_point := high
if _hh and isTradeWindow
// line.new(bar_index, low, bar_index+8, low, style=line.style_solid, color=color.white, width = 1)
low_point := low
//plotshape(_hh, text='HL', title='Higher Low', style=shape.labelup, color=color.new(color.green, 50), textcolor=color.new(color.white, 0), location=location.belowbar, size=size.normal)
//plotshape(_ll, text='LH', title='Lower High', style=shape.labeldown, color=color.new(color.red, 50), textcolor=color.new(color.white, 0), location=location.abovebar, size=size.normal)
// distance_x = timenow + math.round(ta.change(time) * 12)
// distance_x2 = timenow + math.round(ta.change(time)/5)
///////////////////////////////////////
var float Open5M_HighPrice = 0.0
var float Open5M_LowPrice = 0.0
var float Open5M_ClosePrice = 0.0
var float Next5M_ClosePrice = 0.0
var float Open_6h30 = 0.0
if hour(time_close, utc) == 6 and minute(time_close, utc) == 30 and second(time_close, utc) == 0
Open_6h30 := open
if hour(time_close, utc) == 6 and minute(time_close, utc) == 35 and second(time_close, utc) == 0
Open5M_HighPrice := high
Open5M_LowPrice := low
Open5M_ClosePrice := close
Open_6h30 := open
if hour(time_close, utc) == 6 and minute(time_close, utc) == 45 and second(time_close, utc) == 0
Next5M_ClosePrice := close
// var string message = ''
// var string market_trend = ''
// if Next5M_ClosePrice < Open5M_ClosePrice
// message := str.format("Marketing is trending SHORT today. Look for Up Candle. ENTER SHORT", Open5M_HighPrice + 3)
// market_trend := 'Bearish'
// if Next5M_ClosePrice > Open5M_ClosePrice
// message := str.format("Marketing is trending Call today. Look for Down Candle. ENTER LONG", Open5M_HighPrice - 3)
// market_trend := 'Bullish'
// flash_message = ''
// if close >= Open5M_HighPrice + param25
// flash_message := 'S-LONG'
// if close < Open5M_LowPrice - param25
// flash_message := 'S-SHORT'
var int barindex = na
if minute(time_close, utc) == 45 and hour(time_close, utc) == 6
barindex := bar_index
// if market_trend != '' and not na(barindex)
// if flash_message != ''
// label lbl_f = na
// label.delete(lbl_f)
// lbl_f := label.new(na, na, "", color = #212223, style = label.style_label_center, textcolor = color.yellow)
// label.set_xy(lbl_f, barindex, Open5M_HighPrice)
// label.set_text(lbl_f, flash_message)
// label lbl_t = na
// label.delete(lbl_t)
// lbl_t := label.new(na, na, "", color = #077280, style = label.style_label_center, textcolor = color.white)
// label.set_xy(lbl_t, barindex, Open5M_HighPrice - 5)
// label.set_text(lbl_t, '1st Trend: '+market_trend)
Previous_Close = request.security(symbol=syminfo.tickerid, timeframe="D", expression=close[1], lookahead=barmerge.lookahead_on)
DailyGain = close - Previous_Close
Below_OpenLow = Open5M_LowPrice - param5
Above_OpenHigh = Open5M_HighPrice + param5
var float Next_Down_Target = na
var float Next_Up_Target = na
if close < Below_OpenLow and DailyGain > param3
Next_Down_Target := Open5M_LowPrice - param18
if close > Above_OpenHigh and DailyGain < param3
Next_Up_Target := Open5M_HighPrice + param18
var float point_entry_long = param18
var float point_exit_long = param20
var float point_entry_short = param19
var float point_exit_short = param17
if (Open5M_HighPrice - Open5M_LowPrice) >= param9 and math.abs(Open5M_ClosePrice - Previous_Close) >= param40
point_entry_long := param27
point_entry_short := param27
point_exit_long := param30
point_exit_short := param27
if (Open5M_HighPrice - Open5M_LowPrice) < param9 and math.abs(Open5M_ClosePrice - Previous_Close) < param40
point_entry_long := param17
point_entry_short := param17
point_exit_long := param20
point_exit_short := param17
// Logic detect start
nzVolume = nz(vol)
i_vSMA = kernels.rationalQuadratic(ta.vwma(vol, smoothingLength), lookbackWindow, relativeWeighting, startBar)
risingVol = nzVolume >= nzVolume[1]
bullCandle = close > open
bearCandle = close < open
rising = false
if bullCandle and bullCandle[1] and bullCandle[2] and nzVolume > i_vSMA and risingVol and risingVol[1]
if isBullishCross
rising := true
isBullishCross := false
falling = false
if bearCandle and bearCandle[1] and bearCandle[2] and nzVolume > i_vSMA and risingVol and risingVol[1]
if isBearishCross
falling := true
isBearishCross := false
// Logic detect end_time
// Logic call put now stat
var float detect_short_point = 0
var float detect_long_point = 0
var float enter_long_price = 0.0
var float enter_short_price = 0.0
var float trailing_short_point = 0.0
var float trailing_long_point = 0.0
// var float High_Track = 0.0
// var float Low_Track = 0.0
// if minute(time_close, utc) <= 45 and hour(time_close, utc) == 6 or hour(time_close, utc) < 6
// High_Track := 0.0
// Low_Track := 0.0
// if High_Track == 0.0 or High_Track < high
// High_Track := high
// if Low_Track == 0.0 or Low_Track > low
// Low_Track := low
// var float High_Track = 0.0
// if minute(time_close, utc) == 45 and hour(time_close, utc) == 6 and Open5M_HighPrice != 0.0
// High_Track := Open5M_HighPrice
// var float Low_Track = 0.0
// if minute(time_close, utc) == 45 and hour(time_close, utc) == 6 and Open5M_LowPrice != 0.0
// Low_Track := Open5M_LowPrice
var float High_Track = 0.0
var float Low_Track = 0.0
if minute(time_close, utc) == 0 and hour(time_close, utc) == 0 //or hour(time_close, utc) < 6
High_Track := 0.0
Low_Track := 0.0
if minute(time_close, utc) >= 0 //and minute(time_close, utc) < 45 and hour(time_close, utc) == 6
if High_Track == 0.0 or High_Track < high
High_Track := high
if Low_Track == 0.0 or Low_Track > low
Low_Track := low
if minute(time_close, utc) == 45 and hour(time_close, utc) == 6 and Open5M_LowPrice != 0.0
Low_Track := Open5M_LowPrice
if minute(time_close, utc) == 45 and hour(time_close, utc) == 6 and Open5M_HighPrice != 0.0
High_Track := Open5M_HighPrice
// trailing put point start ===============
// if price > high open then check trend up to SHORT back
if High_Track != 0.0 and close > High_Track
if trailing_short_point == 0.0 or trailing_short_point != 0.0 and trailing_short_point < close - Low_Track
trailing_short_point := close - Low_Track
var float track_trailing_short_point = 0
if trailing_short_point > point_entry_short
track_trailing_short_point := trailing_short_point
trailing_short_ok = false
var int barindex_short = 0
if (track_trailing_short_point > 0 and (close - Low_Track) <= (track_trailing_short_point - pull_back))
if High_Track != 0.0
High_Track := 0.0
barindex_short := bar_index
trailing_short_point := 0.0
track_trailing_short_point := 0.0
trailing_short_ok := true
if High_Track == 0.0 and barindex_short == bar_index + 1
High_Track := high// > high_point ? high : high_point
Low_Track := low
barindex_short := 0
// trailing put point end ==============
// trailing call point start ===============
// if price < low open then check trend down to LONG back
if Low_Track != 0.0 and close < Low_Track
if trailing_long_point == 0.0 or trailing_long_point != 0.0 and trailing_long_point < High_Track - close
trailing_long_point := High_Track - close
var float track_trailing_long_point = 0
if trailing_long_point > point_entry_long
track_trailing_long_point := trailing_long_point
trailing_long_ok = false
var int barindex_long = 0
if (track_trailing_long_point > 0 and (High_Track - close) <= (track_trailing_long_point - pull_back))
if Low_Track != 0.0
Low_Track := 0.0
barindex_long := bar_index
trailing_long_point := 0.0
track_trailing_long_point := 0.0
trailing_long_ok := true
if Low_Track == 0.0 and barindex_long == bar_index + 1
Low_Track := low// < low_point ? low : low_point
High_Track := high
barindex_long := 0
// trailing call point end ==============
// //=================logic detect call put start
// if high_point - low > point_entry_long
// detect_long_point := high_point - low
// detect_long_now = false
// if (detect_long_point > 0 and (high_point - close) <= (detect_long_point - pull_back)) or (close > open and close > close[1] and market_trend == 'Bullish' and ta.crossover(low, Open5M_HighPrice))
// detect_long_point := 0
// detect_long_now := true
// if high - low_point > point_entry_short
// detect_short_point := high - low_point
// detect_short_now = false
// if (detect_short_point > 0 and (close - low_point) <= (detect_short_point - pull_back)) or (close < open and close < close[1] and market_trend == 'Bearish' and ta.crossunder(high, Open5M_LowPrice))
// detect_short_point := 0
// detect_short_now := true
//is_long = isTradeWindow and (detect_long_now or trailing_long_ok) and barstate.isconfirmed
is_exit_long = false
is_exit_short = false
int call_logic = 0
int put_logic = 0
int exit_long_logic = 0
int exit_short_logic = 0
var float call_entry_price = 0.0
var float trailing_long_entry_price = 0.0
var float put_entry_price = 0.0
var float trailing_short_entry_price = 0.0
is_long = isTradeWindow and trailing_long_ok and barstate.isconfirmed
call_color = #f1807e
var bool trend_long = false
if is_long
enter_long_price := close
enter_short_price := na
trend_long := true
call_logic := 1 // trailing Lowest Price
//is_short = isTradeWindow and (detect_short_now or trailing_short_ok) and barstate.isconfirmed
is_short = isTradeWindow and trailing_short_ok and barstate.isconfirmed
put_color = #ef0e0a
var bool trend_short = false
if is_short
enter_long_price := na
enter_short_price := close
trend_short := true
put_logic := 1 // trailing Highest Price
//=================logic detect call put end
only_long = false
only_long_color = #90EE90
continue_long = enter_long_price > 0 and close > open and close > close[1] and (rising or isBullishCross or ta.crossover(high, Below_OpenLow) or ta.crossover(high, Above_OpenHigh)) and barstate.isconfirmed
if trend_long and continue_long
only_long := true
trend_long := false
only_short = false
only_short_color = #ffcccb
continue_short = enter_short_price > 0 and close < open and close < close[1] and (falling or isBearishCross or ta.crossunder(low, Below_OpenLow) or ta.crossunder(low, Above_OpenHigh)) and barstate.isconfirmed
if trend_short and continue_short
only_short := true
trend_short := false
// logic exit
// // logic trailing exit
// var float gain_long = 0.0
// var float gain_short = 0.0
// if enter_long_price != 0.0
// if gain_long == 0.0 or gain_long < close - enter_long_price
// gain_long := close - enter_long_price
// is_exit_long = false
// if not continue_long and (gain_long >= 13 and (close - enter_long_price) <= (gain_long - 2)) or (gain_long >= 8 and (close - enter_long_price) <= (gain_long - 3))
// is_exit_long := true
// enter_long_price := 0.0
// trend_long := false
// gain_long := 0.0
// if enter_short_price != 0.0
// if gain_short == 0.0 or gain_short < close - enter_long_price
// gain_short := close - enter_long_price
// is_exit_short = false
// if not continue_short and (gain_short >= 13 and (close - enter_short_price) <= (gain_short - 2)) or (gain_short >= 8 and (close - enter_short_price) <= (gain_short - 5))
// is_exit_short := true
// enter_short_price := 0.0
// trend_short := false
// gain_short := 0.0
// // logic call put end
interval = time + math.round(ta.change(time) * 8)
interval2 = time + math.round(ta.change(time) * 2)
////////////////////////////////////strong call start
var int call_strong_int = 0
var int put_strong_int = 0
var int cnt_bottom = 0
var int cnt_top = 0
var float LowPrice = 0.0
var float HighPrice = 0.0
var int bar_index_high = 0
var int bar_index_low = 0
if minute(time_close, utc) == 0 and hour(time_close, utc) == 0 //or hour(time_close, utc) < 6
HighPrice := 0.0
LowPrice := 0.0
call_strong_int := 0
put_strong_int := 0
cnt_bottom := 0
cnt_top := 0
bar_index_high := 0
bar_index_low := 0
strong_long_index = 0
is_strong_long = false
if LowPrice == 0.0 or LowPrice > low
LowPrice := low
call_strong_int := 0
//bar_index_low := bar_index
if not is_short and LowPrice > 0 and close - LowPrice >= param25
call_strong_int := call_strong_int + 1
if call_strong_int < 2
strong_long_index := bar_index
is_strong_long := true
// if strong_long_index > 0
// var label label_sc = na
// label.delete(label_sc)
// label_sc := label.new(x=interval2, y=LowPrice+27, text=str.format("{0} LONG STRONG - NO SHORT", LowPrice+param25), color=color.new(#000000, 100), textcolor = color.rgb(243, 242, 245), size=size.normal, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
// line.new(strong_long_index, LowPrice+param25, strong_long_index+12, LowPrice+param25, style=line.style_dotted, color=color.blue, width = 4)
if call_strong_int > 0
is_short := false
////////////////////////////////////strong call end
////////////////////////////////////strong put start
if HighPrice == 0.0 or high > HighPrice
HighPrice := high
put_strong_int := 0
//bar_index_high := bar_index
strong_short_index = 0
is_strong_short = false
if not is_long and HighPrice != 0.0 and HighPrice - close >= param25
put_strong_int := put_strong_int + 1
if put_strong_int < 2
strong_short_index := bar_index
is_strong_short := true
// if strong_short_index > 0
// var label label_sc = na
// label.delete(label_sc)
// label_sc := label.new(x=interval2, y=HighPrice-27, text=str.format("{0} SHORT STRONG - NO LONG", HighPrice-param25), color=color.new(#000000, 100), textcolor = color.rgb(243, 242, 245), size=size.normal, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
// line.new(strong_short_index, HighPrice-param25, strong_short_index+12, HighPrice-param25, style=line.style_dotted, color=color.yellow, width = 4)
if put_strong_int > 0
is_long := false
////////////////////////////////////strong put end
////////////////////////////////////signal call put start
// var bool has_signal_long = false
// is_signal_long = low_point > 0 and (close > low_point and math.round(low) == math.round(low_point)) and low > Below_OpenLow
// //plotshape(isTradeWindow and is_signal_long and not has_signal_long? low : na, style=shape.triangleup, size = size.tiny, location=location.belowbar, color=color.yellow, textcolor = #ffffff, text='LONG', offset=0)
// if is_signal_long and isTradeWindow
// has_signal_long := true
// if is_short
// has_signal_long := false
// if _ll
// has_signal_long := false
// if put_strong_int > 0
// is_signal_long := false
var bool has_signal_short = false
is_signal_short = high_point > 0 and (close < high_point and math.round(high) == math.round(high_point)) and high < Above_OpenHigh
//plotshape(isTradeWindow and is_signal_short and not has_signal_short? high : na, style=shape.triangledown, size = size.tiny, location=location.abovebar, color=color.white, textcolor = #ffffff, text='SHORT', offset=0)
if is_signal_short and isTradeWindow
has_signal_short := true
if is_long
has_signal_short := false
if _hh
has_signal_short := false
if call_strong_int > 0
is_signal_short := false
//=============================================//
// track call put confirm start
confirm_short = false
confirm_long = false
if call_entry_price == 0.0 and _hh[4] and close <= high_point and close[1] <= high_point and close[2] <= high_point and close[3] <= high_point and barstate.isconfirmed
confirm_short := true
if put_entry_price == 0.0 and _ll[4] and close >= low_point and close[1] >= low_point and close[2] >= low_point and close[3] >= low_point and barstate.isconfirmed
confirm_long := true
// if confirm_long and isTradeWindow
// label.new(bar_index, low15, str.format("{0} {1}", ema21, close))
//(math.round(close[1]) < math.round(ema21) or math.round(close) < math.round(ema21)) and
// plotshape(confirm_long and isTradeWindow? low15 : na, style=shape.labelup, size = size.tiny, location=location.absolute, color=#7808ef, textcolor = #ffffff, text='U', offset=0)
// plotshape(confirm_short and isTradeWindow? high15 : na, style=shape.labeldown, size = size.tiny, location=location.absolute, color=#ef0e0a, textcolor = #ffffff, text='D', offset=0)
// track call put confirm end
//=============================================//
////////////////////////////////////signal call put end
/////////////////////////////////
// Logic cross box high
// if call_entry_price == 0.0 and (ta.crossover(close[1], Open5M_HighPrice)) and (close > Open5M_HighPrice or high > Open5M_HighPrice) and isTradeWindow and barstate.isconfirmed
// is_long := true
// call_color := color.new(call_color, 80)
// call_logic := 2 // Cross Up Open High
if call_entry_price == 0.0 and ((ta.crossover(close[1], Above_OpenHigh)) and (close > Above_OpenHigh or high > Above_OpenHigh) or ta.crossover(close[1], Below_OpenLow) and (close > Below_OpenLow or high > Below_OpenLow)) and isTradeWindow and barstate.isconfirmed
is_long := true
call_color := color.new(call_color, 60)
call_logic := 3 // Cross Up Above Open High
if trend_short and ta.crossunder(close[1], Open5M_HighPrice) and close < Open5M_HighPrice
only_short := true
only_short_color := color.new(#ffcccb, 80)
if trend_short and ta.crossunder(close[1], Above_OpenHigh) and close < Above_OpenHigh
only_short := true
only_short_color := color.new(#ffcccb, 60)
// Logic cross box low
// if put_entry_price == 0.0 and ta.crossunder(close[1], Open5M_LowPrice) and (close < Open5M_LowPrice or low < Open5M_LowPrice ) and isTradeWindow and barstate.isconfirmed
// is_short := true
// put_color := color.new(#ef0e0a, 80)
// put_logic := 2 // Cross Down Open Low
// if put_entry_price == 0.0 and (ta.crossunder(close[1], Below_OpenLow) and (close < Below_OpenLow or low < Below_OpenLow) or ta.crossunder(close[1], Above_OpenHigh) and (close < Above_OpenHigh or low < Above_OpenHigh) )and isTradeWindow and barstate.isconfirmed
// is_short := true
// put_color := color.new(#ef0e0a, 60)
// put_logic := 3 // Cross Down Below Open Low
// if trend_long and ta.crossover(close[1], Open5M_LowPrice) and close > Open5M_LowPrice
// only_long := true
// only_long_color := color.new(#90EE90, 80)
// if trend_long and ta.crossover(close[1], Below_OpenLow) and close > Below_OpenLow
// only_long := true
// only_long_color := color.new(#90EE90, 60)
//plotshape(is_exit_long? low : na, style=shape.labelup, size = size.tiny, location=location.belowbar, color=#f1807e, textcolor = #ffffff, text='EXIT LONG', offset=0)
//plotshape(is_exit_short? high : na, style=shape.labeldown, size = size.tiny, location=location.abovebar, color=#ef0e0a, textcolor = #ffffff, text='EXIT SHORT', offset=0)
///////////
//Logic only call put start
//Logic only call put end