-
Notifications
You must be signed in to change notification settings - Fork 45
/
alert-options-trading-spy.txt
114 lines (82 loc) · 4.06 KB
/
alert-options-trading-spy.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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © binancash
//@version=5
strategy("SPY Options Trading - Alert", overlay=true, pyramiding=1, default_qty_type = strategy.fixed, default_qty_value = 1 )
//****************************************************************//
// please set up alert in 5M to controll options trading on SPY //
//****************************************************************//
stopPerCall = input(0.09, title='Stop Loss Call %') / 100
float takePerCall = input(0.02, title='Stop Loss Call %') / 100
stopPerPut = input(0.07, title='Stop Loss Put %') / 100
takePerPut = input(0.02, title='Take Profit Put %') / 100
longStop = strategy.position_avg_price * (1 - stopPerCall)
shortStop = strategy.position_avg_price * (1 + stopPerPut)
shortTake = strategy.position_avg_price * (1 - takePerPut)
longTake = strategy.position_avg_price * (1 + takePerCall)
//Inputs
ma_length = input(3)
//Three Bar High/Low Moving Average
ma_high = ta.sma(high, ma_length)
ma_low = ta.sma(low, ma_length)
plot(ma_high, linewidth = 1)
plot(ma_low, linewidth = 1)
//Trend Reversal - Up
trend_reversal_up = low[2] > low[1] and low[1] < low and high > high[1]
plotshape(trend_reversal_up ? 1: na, color = color.orange, location = location.belowbar, style = shape.arrowup, text = 'U')
//Trend Reversal - Down
trend_reversal_down = high[2] < high[1] and high[1] > high and low < low[1]
plotshape(trend_reversal_down ? -1: na, color = color.navy, location = location.abovebar, style = shape.arrowdown, text = 'D')
//Short Term Low
short_term_low = low[2] > low[1] and low[1] < low and high[1] < high[2] and high > high[1]
plotshape(short_term_low ? 1: na, color = #00EEEE, location = location.belowbar, style = shape.arrowup)
//Short Term High
short_term_high = high[2] < high[1] and high[1] > high and low[1] > low[2] and low < low[1]
plotshape(short_term_high ? -1: na, color = #00EEEE, location = location.abovebar, style = shape.arrowdown)
//Trend Change Point - Up
float trend_change_up = na
trend_change_up := high > high[1] ? 1 : na
line1 = short_term_low and trend_change_up
color_up = #FFEB3B
color up = na
up := trend_change_up ? color_up : na
//plot(line1 ? high[1] : na, color = up, linewidth = 2)
//plotshape(line1 ? low : na, title="Buy", text="Buy", style=shape.triangleup, location=location.belowbar, color=color.white, size=size.normal)
//Trend Change Point - Down
float trend_change_down = na
trend_change_down := low < low[1] ? 1 : na
float trend_open_up = na
trend_open_up := low[3] < low[2] and low[1] < low ? 1 : na
//plotshape(trend_open_up, 'UP', style = shape.triangleup)
line2 = short_term_high and trend_change_down
color_down = #E040FB
color down = na
down := trend_change_down ? color_down : na
//plot(line2 ? low[1] : na, color=down, linewidth = 2)
//plotshape(line2 ? high : na, title="Sell", text="Sell", style=shape.triangledown, location=location.abovebar, color=color.blue, size=size.normal)
//Bar Color Trend Change
coloryellow = #FFEB3B
colorfuchsia = #E040FB
barcolor(line1 ? coloryellow : line2 ? colorfuchsia : na)
is_call = 0
is_put = 0
if trend_reversal_up and time>timestamp(2023, 08, 01, 09, 30)
strategy.entry("call", strategy.long)
is_call := 1
if trend_reversal_down and time>timestamp(2023, 08, 01, 09, 30)
strategy.entry("put", strategy.short)
is_put := 1
if(strategy.position_size > 0 and trend_change_down) and time>timestamp(2023, 08, 01, 09, 30)
strategy.close(id="call")
is_call := 2
if(strategy.position_size < 0 and trend_change_up) and time>timestamp(2023, 08, 01, 09, 30)
strategy.close(id="put")
is_put := 2
if(strategy.position_size > 0) and time>timestamp(2023, 08, 01, 09, 30)
strategy.exit(id='call', limit=longTake,stop = longStop)
//call_price := 0.0
is_call := 2
if(strategy.position_size < 0) and time>timestamp(2023, 08, 01, 09, 30)
strategy.exit(id='put', limit=shortTake,stop = shortStop)
is_put := 2
if is_call > 0 or is_put > 0
alert('{"call":'+str.tostring(is_call)+',"put":'+str.tostring(is_put)+'}', alert.freq_once_per_bar)