Future Algos
Future Algos
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
//Line Style function
get_line_style(style) =>
out = switch style
'???' => line.style_solid
'----' => line.style_dashed
'����' => line.style_dotted
float ob = na
array.unshift(ob_top, top)
array.unshift(ob_btm, btm)
array.unshift(ob_avg, avg)
array.unshift(ob_left, time[length])
ob := ob_val
array.remove(ob_top, idx)
array.remove(ob_btm, idx)
array.remove(ob_avg, idx)
array.remove(ob_left, idx)
mitigated
array.unshift(ob_lvl, line.new(na,na,na,na
, xloc = xloc.bar_time
, extend = extend.right
, color = lvl_css
, style = get_line_style(line_style)
, width = line_width))
//-----------------------------------------------------------------------------}
//Global elements
//-----------------------------------------------------------------------------{
var os = 0
var target_bull = 0.
var target_bear = 0.
n = bar_index
upper = ta.highest(length)
lower = ta.lowest(length)
if mitigation == 'Close'
target_bull := ta.lowest(close, length)
target_bear := ta.highest(close, length)
else
target_bull := lower
target_bear := upper
//-----------------------------------------------------------------------------}
//Get bullish/bearish order blocks coordinates
//-----------------------------------------------------------------------------{
[bull_top
, bull_btm
, bull_avg
, bull_left
, bull_ob] = get_coordinates(phv and os == 1, hl2[length], low[length],
low[length])
[bear_top
, bear_btm
, bear_avg
, bear_left
, bear_ob] = get_coordinates(phv and os == 0, high[length], hl2[length],
high[length])
//-----------------------------------------------------------------------------}
//Remove mitigated order blocks
//-----------------------------------------------------------------------------{
mitigated_bull = remove_mitigated(bull_top
, bull_btm
, bull_left
, bull_avg
, target_bull
, true)
mitigated_bear = remove_mitigated(bear_top
, bear_btm
, bear_left
, bear_avg
, target_bear
, false)
//-----------------------------------------------------------------------------}
//Display order blocks
//-----------------------------------------------------------------------------{
//Set bullish order blocks
set_order_blocks(bull_top
, bull_btm
, bull_left
, bull_avg
, bull_ext_last
, bg_bull_css
, bull_css
, bull_avg_css)
// ==================
// ==== Settings ====
// ==================
color1 = color.red
color2 = color.orange
color3 = color.yellow
color4 = color.lime
color5 = color.aqua
color6 = color.fuchsia
color7 = color.silver
// =======================
// ==== Dates & Times ====
// =======================
if barstate.islastconfirmedhistory
// ================
// ==== Legend ====
// ================
var tbl = table.new(position.top_right, columns=8, rows=8, frame_color=#151715,
frame_width=1, border_width=2, border_color=color.new(color.black, 100))
units = timeframe.isminutes ? "m" : ""
table.cell(tbl, 1, 0, syminfo.ticker + ' => ' + str.tostring(timeframe.period)+
units, text_halign=text.align_center, text_color=color.gray, text_size=size.small)
table.cell(tbl, 2, 0, 'FOMC Meeting', text_halign=text.align_center,
bgcolor=color.black, text_color=color1, text_size=size.small)
table.cell(tbl, 3, 0, 'FOMC Minutes', text_halign=text.align_center,
bgcolor=color.black, text_color=color2, text_size=size.small)
table.cell(tbl, 4, 0, 'Producer Price Index (PPI)',
text_halign=text.align_center, bgcolor=color.black, text_color=color3,
text_size=size.small)
table.cell(tbl, 1, 1, 'Consumer Price Index (CPI)',
text_halign=text.align_center, bgcolor=color.black, text_color=color4,
text_size=size.small)
table.cell(tbl, 2, 1, 'Consumer Sentiment Index (CSI)',
text_halign=text.align_center, bgcolor=color.black, text_color=color5,
text_size=size.small)
table.cell(tbl, 3, 1, 'Consumer Confidence Index (CCI)',
text_halign=text.align_center, bgcolor=color.black, text_color=color6,
text_size=size.small)
table.cell(tbl, 4, 1, 'Non-Farm Payrolls (NFP)', text_halign=text.align_center,
bgcolor=color.black, text_color=color7, text_size=size.small)
// =======================
// ==== CE And ===========
// =======================
f_MACDV(_close) =>
//-----Condition start
stringmacdv =(MACDV>150) ? "Wait Continue/Reversal" :(MACDV>50 and
MACDV<150 and MACDV>SignalV ) ? "Buy G0" :(MACDV>50 and MACDV<150 and MACDV<SignalV
) ? "Buy Retest":(MACDV<50) and (MACDV>-50) ? "Sideway" :(MACDV<-50 and MACDV>-150
and MACDV>SignalV ) ? "Short go":(MACDV<-50 and MACDV>-150 and MACDV<SignalV ) ?
"Short Retest":(MACDV<150) ? "Wait Continue/Reversal" :na
//momentum
stringmomentum =(CLS>MA1 and CLS>MA2 and MA1<MA2) ? "Accumulation:Stop Sell -
Setup Buy" :(CLS>MA1 and CLS>MA2 and MA1>MA2) ? "Runing Up: Buy Runing":(CLS<MA1
and CLS>MA2 and MA1>MA2) ? "Re-Acumulasi: Continue Up":(CLS<MA1 and CLS<MA2 and
MA1>MA2) ? "Distribution: Stop Buy-Setup Short":(CLS<MA1 and CLS<MA2 and MA1<MA2) ?
"Re-Distribusi: Continue Down":(CLS>MA1 and CLS<MA2 and MA1<MA2) ? "Accumulation-
Distribusi: Don't Trade Wait Break":na
//-----Condition end
// Return values
[CLS, MA1, MA2, RSI, MACDV, SignalV, stringmacdv, stringmomentum]
var t = table.new(table_position,15,math.abs(max-min)+2,
frame_color =color.new(#f1ff2a, 0),
frame_width =1,
border_color =color.new(#f1ff2a,0),
border_width =1)
//---- Table Position & Size code end ----//
table.cell(t,1,1,'TimeFrem',text_color=col_col,text_size=table_text_size,bgcolor=He
ader_col)
if showCls
table.cell(t,2,1,'L.Close',text_color=col_col,text_size=table_text_size,bgcolor=Hea
der_col)
if showMA01
table.cell(t,3,1,'MA01',text_color=col_col,text_size=table_text_size,bgcolor=Header
_col)
if showMA02
table.cell(t,4,1,'MA02',text_color=col_col,text_size=table_text_size,bgcolor=Header
_col)
if showMACross
table.cell(t,5,1,'Trend',text_color=col_col,text_size=table_text_size,bgcolor=Heade
r_col)
if showRSI
table.cell(t,6,1,'RSI',text_color=col_col,text_size=table_text_size,bgcolor=Header_
col)
if showMACDV
table.cell(t,7,1,'MACDV',text_color=col_col,text_size=table_text_size,bgcolor=Heade
r_col)
if showSignalV
table.cell(t,8,1,'SignalV',text_color=col_col,text_size=table_text_size,bgcolor=Hea
der_col)
if showMACDV_Status
table.cell(t,9,1,'Condition',text_color=col_col,text_size=table_text_size,bgcolor=H
eader_col)
if showmomentum
table.cell(t,10,1,'Phase
Market',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
table.cell(t,1,2, "Chart",text_color=color.white,text_size=table_text_size,
bgcolor=color.rgb(0, 68, 255))
if showCls
table.cell(t,2,2, str.tostring(CLS_chart,
'#.###'),text_color=color.new(CLS_chart >CLS_chart[2] ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(CLS_chart >CLS_chart[2] ?
cell_up : cell_dn ,cell_transp))
if showMA01
table.cell(t,3,2, str.tostring(MA1_chart,
'#.###'),text_color=color.new(MA1_chart >MA1_chart[1] ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MA1_chart >MA1_chart[1] ?
cell_up : cell_dn ,cell_transp))
if showMA02
table.cell(t,4,2, str.tostring(MA2_chart,
'#.###'),text_color=color.new(MA2_chart >MA2_chart[1] ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MA2_chart >MA2_chart[1] ?
cell_up : cell_dn ,cell_transp))
if showMACross
table.cell(t,5,2, MA1_chart > MA2_chart ? "Bullish" :
"Bearish",text_color=color.new(MA1_chart > MA2_chart ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MA1_chart > MA2_chart ?
cell_up : cell_dn ,cell_transp))
if showRSI
table.cell(t,6,2, str.tostring(RSI_chart,
'#.###'),text_color=color.new(RSI_chart > 50 ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(RSI_chart > 50 ? cell_up :
cell_dn ,cell_transp))
if showMACDV
table.cell(t,7,2,str.tostring(MACDV_chart,
'#.###'),text_color=color.new(MACDV_chart > MACDV_chart[1] ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MACDV_chart >
MACDV_chart[1] ? cell_up : cell_dn ,cell_transp))
if showSignalV
table.cell(t,8,2,str.tostring(SignalV_chart,
'#.###'),text_color=color.new(SignalV_chart > SignalV_chart[1] ? cell_up :
cell_dn ,0),text_size=table_text_size, bgcolor=color.new(SignalV_chart>
SignalV_chart[1] ? cell_up : cell_dn ,cell_transp))
if showMACDV_Status
table.cell(t,9,2,stringmacdv_chart,text_color=color.rgb(0, 0,
0),text_size=table_text_size, bgcolor=color.new(MACDV_chart>50 ?
cell_up :MACDV_chart<-50 ? cell_dn:cell_MACDV4 ,cell_transp))
if showmomentum
table.cell(t,10,2,stringmomentum_chart,text_color=color.rgb(2, 2,
2),text_size=table_text_size, bgcolor=color.new(CLS_chart>MA1_chart and
CLS_chart>MA2_chart and MA1_chart<MA2_chart ? cell_phase1 : (CLS_chart>MA1_chart
and CLS_chart>MA2_chart and MA1_chart>MA2_chart) ? cell_phase2 :
(CLS_chart<MA1_chart and CLS_chart>MA2_chart and MA1_chart>MA2_chart) ?
cell_phase3 :(CLS_chart<MA1_chart and CLS_chart<MA2_chart and
MA1_chart>MA2_chart) ? cell_phase4:(CLS_chart<MA1_chart and CLS_chart<MA2_chart and
MA1_chart<MA2_chart) ? cell_phase5:(CLS_chart>MA1_chart and CLS_chart<MA2_chart and
MA1_chart<MA2_chart) ? cell_phase6:col_col,cell_transp))
float ph = na
float pl = na
ph := ta.highestbars(high, nz(len, 1)) == 0 ? high : na
pl := ta.lowestbars(low, nz(len, 1)) == 0 ? low : na
var dir = 0
iff_1 = pl and na(ph) ? -1 : dir
dir := ph and na(pl) ? 1 : iff_1
var max_array_size = 50
var zigzag = array.new_float(0)
oldzigzag = array.copy(zigzag)
// set colors
array.set(fibo_colors, 0, color.lime)
array.set(fibo_colors, 1, color.silver)
array.set(fibo_colors, 2, color.gray)
array.set(fibo_colors, 3, color.red)
array.set(fibo_colors, 4, color.purple)
array.set(fibo_colors, 5, color.fuchsia)
array.set(fibo_colors, 6, color.olive)
array.set(fibo_colors, 7, color.navy)
array.set(fibo_colors, 8, color.teal)
array.set(fibo_colors, 9, color.orange)
a=super(high,len)
b=super(low,len)
c=(a-b)/2*mult
d=b+(a-b)/2
plotcolor = d>d[1]? up_col : dn_col
bullish_bearish = d>d[1]? true : false
plot(a+c, color=up_col)
plot(b-c, color=dn_col)
plot(showMiddle? d:na, color=plotcolor)
plotchar(ta.crossover(high,a+c),char = "??", location = location.abovebar, size =
size.tiny)
plotchar(ta.crossunder(low,b-c),char = "??",location = location.belowbar , size =
size.tiny)
// �������������������� Alerts
alertcondition(bullish_bearish == true ,title='Bearish Change', message='Nadaraya-
Watson: {{ticker}} ({{interval}}) turned Bearish ?')
alertcondition(bullish_bearish == false, title='Bullish Change', message='Nadaraya-
Watson: {{ticker}} ({{interval}}) turned Bullish ?')
alertcondition(ta.crossunder(high,a+c) , title='Price close under lower band',
message='Nadaraya-Watson: {{ticker}} ({{interval}}) crossed under lower band ??')
alertcondition(ta.crossover(low,b-c) , title='Price close above upper band',
message='Nadaraya-Watson: {{ticker}} ({{interval}}) Crossed above upper band ??')
//----
var tb = table.new(position.top_right, 1, 1
, bgcolor = #35202b)
// Alerts
alert01 = ta.crossover(ribbon1, ribbon2)
alert02 = bull
alert03 = wtDivBull
alert04 = wtDivBear
alert05 = bull or bear
alert06 = ta.crossover(wt1, wt2) and wt2 <= -53
alert07 = ta.crossunder(wt1, wt2) and wt2 >= 53
alert08 = ta.crossunder(ribbon1, ribbon2)
alert09 = rsiOb or rsiOs
alert10 = bear
alert11 = ta.cross(ribbon1, ribbon2)
alerts(sym) =>
if alert02 or alert03 or alert04 or alert06 or alert07 or alert10
alert_text = alert02 ? "Buy Signal EzAlgo" : alert03 ? "Strong Buy Signal
EzAlgo" : alert04 ? "Strong Sell Signal EzAlgo" : alert06 ? "Mild Buy Signal
EzAlgo" : alert07 ? "Mild Sell Signal EzAlgo" : "Sell Signal EzAlgo"
alert(alert_text, alert.freq_once_per_bar_close)
alerts(syminfo.tickerid)
alertcondition(alert01, "Blue Trend Ribbon Alert", "Blue Trend Ribbon,
TimeFrame={{interval}}")
alertcondition(alert02, "Buy Signal", "Buy Signal EzAlgo")
alertcondition(alert03, "Divergence Buy Alert", "Strong Buy Signal EzAlgo,
TimeFrame={{interval}}")
alertcondition(alert04, "Divergence Sell Alert", "Strong Sell Signal EzAlgo,
TimeFrame={{interval}}")
alertcondition(alert05, "Either Buy or Sell Signal", "EzAlgo Signal")
alertcondition(alert06, "Mild Buy Alert", "Mild Buy Signal EzAlgo,
TimeFrame={{interval}}")
alertcondition(alert07, "Mild Sell Alert", "Mild Sell Signal EzAlgo,
TimeFrame={{interval}}")
alertcondition(alert08, "Red Trend Ribbon Alert", "Red Trend Ribbon,
TimeFrame={{interval}}")
alertcondition(alert09, "Reversal Signal", "Reversal Signal")
alertcondition(alert10, "Sell Signal", "Sell Signal EzAlgo")
alertcondition(alert11, "Trend Ribbon Color Change Alert", "Trend Ribbon Color
Change, TimeFrame={{interval}}")