Aura.superalgo
Aura.superalgo
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//===== VWAP =====
showVWAP = input.bool(title = "Show VWAP", defval=false, group =
"██████VWAP██████")
VWAPSource = input.source(title="VWAP Source", defval=hl2, group = "VWAP")
VWAPrice = ta.vwap(VWAPSource)
plot(showVWAP ? VWAPrice : na, color= color.blue , title="VWAP", linewidth = 2)
// Inputs
disable_repeating_signals_param = input.bool(false, 'Disable Repeating Signals',
group='Technical')
useRes = input(true, 'Use Alternate Signals',group='Technical')
intRes = input(8, 'Multiplier for Alternate Signals',group='Technical')
basisType = input.string('ALMA', 'MA Type: ', options=['HullMA',
'ALMA'],group='Technical')
basisLen = input.int(2, 'MA Period', minval=1,group='Technical')
offsetSigma = input.int(5, 'Offset for LSMA / Sigma for ALMA',
minval=0,group='Technical')
offsetALMA = input.float(0.85,'Offset for ALMA', minval=0,
step=0.01,group='Technical')
tradeType = input.string('BOTH', 'What trades should be taken : ', options=['LONG',
'SHORT', 'BOTH', 'NONE'],group='Technical')
// Timeframe resolution
stratRes = timeframe.ismonthly ? str.tostring(timeframe.multiplier * intRes,
'###M') :
timeframe.isweekly ? str.tostring(timeframe.multiplier * intRes, '###W')
:
timeframe.isdaily ? str.tostring(timeframe.multiplier * intRes,
'###D') :
timeframe.isintraday ? str.tostring(timeframe.multiplier * intRes,
'####') :
'60'
// Global elements
var target_bullf = 0.
var target_bearf = 0.
// Colours
green100 = #008000FF
red100 = #FF0000FF
// Base Functions
variant(type, src, len, offSig, offALMA) =>
v1 = ta.sma(src, len) // Simple MA
v2 = ta.ema(src, len) // Exponential MA
v8 = ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len),
math.round(math.sqrt(len))) // Hull MA
v10 = ta.alma(src, len, offALMA, offSig) // ALMA
switch type
'ALMA' => v10
'HullMA' => v2
=> v1
// Security wrapper
reso(exp, use, res) =>
security_1 = request.security(syminfo.tickerid, res, exp,
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
use ? security_1 : exp
// Series Setup
closeSeries = variant(basisType, close, basisLen, offsetSigma, offsetALMA)
openSeries = variant(basisType, open, basisLen, offsetSigma, offsetALMA)
closeSeriesAlt = reso(closeSeries, useRes, stratRes)
openSeriesAlt = reso(openSeries, useRes, stratRes)
// Alert conditions
leTrigger = ta.crossover(closeSeriesAlt, openSeriesAlt)
seTrigger = ta.crossunder(closeSeriesAlt, openSeriesAlt)
i_src = close
// Entry & Exit Levels
var float condition = 0.0
var float slLine = 0.0
var float entryLine = 0.0
buylbl = #388e3c
selllbl = #b22833
txtcl = color.rgb(0, 0, 0, 100)
last_signal := 'buy'
last_signal := 'sell'
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
var g_EMAS = "██████Moving Average (RMA, SMA, EMA, VWMA)██████"
LenghtBool1 = input.bool(false ,'',group=g_EMAS,inline='len1')
len1 = input.int(15, title='MA 1',group=g_EMAS,inline='len1')
string ma_1_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA',
'EMA','VWMA'], inline='len1',group=g_EMAS)
color ma_1_colour = input.color(color.rgb(51, 199, 15), '',
inline='len1',group=g_EMAS)
LenghtBool2 = input.bool(false,'',group=g_EMAS,inline='len2')
len2 = input.int(30, minval=1, title='MA 2',group=g_EMAS,inline='len2')
string ma_2_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA',
'EMA','VWMA'], inline='len2',group=g_EMAS)
color ma_2_colour = input.color(color.rgb(255, 94, 0), '',
inline='len2',group=g_EMAS)
LenghtBool3 = input.bool(false,'',group=g_EMAS,inline='len3')
len3 = input.int(55, minval=1, title='MA 3',group=g_EMAS,inline='len3')
string ma_3_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA',
'EMA','VWMA'], inline='len3',group=g_EMAS)
color ma_3_colour = input.color(color.new(color.aqua, 0), '',
inline='len3',group=g_EMAS)
LenghtBool4 = input.bool(false,'',group=g_EMAS,inline='len4')
len4 = input.int(200, minval=1, title='MA 4',group=g_EMAS,inline='len4')
string ma_4_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA',
'EMA','VWMA'], inline='len4',group=g_EMAS)
color ma_4_colour = input.color(color.black, '', inline='len4',group=g_EMAS)
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////
if buySignal
hasBuySignal := true
hasSellSignal := false
if sellSignal
hasSellSignal := true
hasBuySignal := false
///////////////////////////////////////////////////////////////////////////////////
/////////////////////
// //@version=5
// indicator("HTF Candle Projections", overlay = true, max_bars_back = 500,
max_boxes_count = 500)
type Candle
box body
line upperWick
line lowerWick
line o
line h
line l
label labelO
label labelH
label labelL
label labelC
determineAutoTimeframe() =>
if tf_2lvs
getAutoTimeframe('5', '15', '60', '240', '1D', '1W', '1M', '3M', '12M',
'12M')
else
getAutoTimeframe('1', '5', '15', '60', '240', '1D', '1W', '1M', '3M',
'12M')
getSizeMultiplier() =>
result = switch size
"Small" => 1
"Medium" => 2
"Large" => 3
result
getLineStyle(style) =>
result = switch style
"Solid" => line.style_solid
"Dotted" => line.style_dotted
"Dashed" => line.style_dashed
result
getLabelSize() =>
result = switch ohlc_size
"Auto" => size.auto
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
result
ohlc() =>
[htf_o, htf_h, htf_l, htf_c] = request.security(syminfo.tickerid, curr_tf,
[open, high, low, close], lookahead=barmerge.lookahead_on)
var o = 0.
var h = 0.
var l = 0.
c = close
if newCandle
o := open
h := high
l := low
else
h := math.max(high, h)
l := math.min(low , l)
getCandlePostion(l_pos) =>
m_pos = l_pos + sizeMultiplier
r_pos = l_pos + (sizeMultiplier * 2)
[m_pos, r_pos]
createLabel(r_pos, s) =>
label.new(r_pos, s, str.tostring(s, format.mintick), style =
label.style_label_left, color = color.new(color.black,100), textcolor = ohlc_col,
size = getLabelSize())
if o_enabled
candle.o := line.new(b_o, o_o, m_pos, o_o, style = getLineStyle(o_style),
color = o_col, width = o_width)
if hl_enabled
candle.h := line.new(b_h, o_h, m_pos, o_h, style = getLineStyle(hl_style),
color = hl_col, width = hl_width)
candle.l := line.new(b_l, o_l, m_pos, o_l, style = getLineStyle(hl_style),
color = hl_col, width = hl_width)
getCandleProperties(o, h, l, c) =>
h_body = math.max(o,c)
l_body = math.min(o,c)
body_col = o > c ? down_col : up_col
wick_col = o > c ? down_col_wick : up_col_wick
border_col = o > c ? down_col_border : up_col_border
[h_body, l_body, body_col, wick_col, border_col]
createCandle(l_pos, o, h, l, c) =>
[m_pos, r_pos] = getCandlePostion(l_pos)
[h_body, l_body, body_col, wick_col, border_col] = getCandleProperties(o, h, l,
c)
candle = Candle.new()
candle.body := box.new(l_pos, h_body, r_pos, l_body, border_col, bgcolor =
body_col)
candle.upperWick := line.new(m_pos, h_body, m_pos, h, color = wick_col)
candle.lowerWick := line.new(m_pos, l_body, m_pos, l, color = wick_col)
candle
if useHtfData
curr_o := htf_o
curr_h := htf_h
curr_l := htf_l
curr_c := htf_c
candle_o = curr_o
candle_h = curr_h
candle_l = curr_l
candle_c = curr_c
if newCandle
oldCandle = candles.shift()
deleteCandle(oldCandle)
pos = bar_index + offset + maxIndex * (3 + sizeMultiplier)
candle = createCandle(pos, candle_o, candle_h, candle_l, candle_c)
createProjections(candle, o, h, l, curr_o, curr_h, curr_l, htf_o, htf_h, htf_l,
pos)
createLabels(candle, curr_o, curr_h, curr_l, curr_c, pos)
candles.push(candle)
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////
//////// Zonas de Supply/Demand POI
//////////////////////////////////////////////////
POIswitch = input.bool (true, "Supply/Demand Zones", group='¦¦¦¦¦¦Switch panel
(Overlay indicators)¦¦¦¦¦¦', inline='S3')
G_POI = '¦¦¦¦¦¦Config of Supply/Demand POI zones¦¦¦¦¦¦'
POIATR = ta.atr(50)
ColorSupply = input.color(color.rgb(204, 17, 92, 50), title = 'Supply', group =
G_POI, inline = 'POI3')
ColorSupplyOutline = input.color(#11010100, title = 'Supply Edges - POI', group =
G_POI, inline = 'POI3')
ColorDemand = input.color(color.rgb(0, 138, 153, 50), title = 'Demand', group =
G_POI, inline = 'POI4')
ColorDemandOutline = input.color(#1a010100, title = 'Demand Edges - POI', group =
G_POI, inline = 'POI4')
SwingLength = input.int(4, title = 'High/Low Swing Length', group = G_POI, minval =
1, maxval = 50, inline= 'POI1')
HistoryDemandKepp = input.int(2, title = 'History to maintain', minval = 1, maxval
= 50, group = G_POI, inline= 'POI1')
BoxWidth = input.float(4, title = 'Supply/Demand Box Width', group = G_POI, minval
= 1, maxval = 10, step = 0.5, inline= 'POI2')
ColorLabelPOI = input.color(#bdbdbd, title = 'POI label', group = G_POI, inline =
'POI2')
MaxExtention = input.bool(false, title = "Extend", group = G_POI, inline = 'POI2')
atr_threshold = POIATR * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
okay_to_draw = CheckOverlappingF(poi, box_array, POIATR)
//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw and POIswitch
box.delete( array.get(box_array, array.size(box_array) - 1) )
ArrayAddPopF(box_array, box.new( left = box_left, top = box_top, right =
box_right, bottom = box_bottom, border_color = ColorSupplyOutline,
bgcolor = ColorSupply, extend=MaxExtention?extend.right:extend.none,
text = 'Supply', text_halign = text.align_center, text_valign = text.align_center,
text_color = ColorLabelPOI, text_size = size.small, xloc = xloc.bar_index))
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 90)
BoxExtendEndPointF(SupplyBoxCurrent)
BoxExtendEndPointF(DemandBoxCurrent)
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////
// indicator('Volume Delta [hapharmonic]', max_bars_back=5000,
max_labels_count=500,overlay = true)
//------------------------------------------
// Settings |
//------------------------------------------
// Inputs Table
FV = format.volume,FP = format.percent
bool usecandle = input.bool(false,title = 'Volume on Candles')
color C_Up = input.color(#12cef8,title = 'Volume Buy', inline = ' ',group =
"Style")
color C_Down = input.color(#fe3f00,title = 'Volume Sell', inline = ' ',group =
"Style")
bool MAV = input.bool(false,title = 'EMA',group = "EMA")
string volumeOption = input.string("Use Volume Confirmation", title="Volume
Option", options=["none", "Use Volume Confirmation"], group="EMA")
bool useVolumeConfirmation = volumeOption == 'none' ?false:true
int emaFastLength = input(9, title="Fast EMA Length",group = "EMA")
int emaSlowLength = input(15, title="Slow EMA Length",group = "EMA")
//------------------------------------------
// UDT_identifier |
//------------------------------------------
// Define User Defined Type (UDT) for OHLCV data with default values
type OHLCV
float O = open
float H = high
float L = low
float C = close
float V = volume
//------------------------------------------
// Calculate volumes and percentages |
//------------------------------------------
calcVolumes(OHLCV ohlcv) =>
var VolumeData data = VolumeData.new()
data.buyVol := ohlcv.V * (ohlcv.C - ohlcv.L) / (ohlcv.H - ohlcv.L) //
Calculate buy volume using the formula: volume * (close - low) / (high - low)
data.sellVol := ohlcv.V - data.buyVol //
Calculate sell volume by subtracting buy volume from total volume
data.pcBuy := data.buyVol / ohlcv.V * 100 //
Calculate the percentage of buy volume
data.pcSell := 100 - data.pcBuy //
Calculate the percentage of sell volume (100% - buy percentage)
data.isBuyGreater := data.buyVol > data.sellVol //
Determine if buy volume is greater than sell volume
data.higherVol := data.isBuyGreater ? data.buyVol : data.sellVol //
Assign the higher volume value based on the comparison
data.lowerVol := data.isBuyGreater ? data.sellVol : data.buyVol //
Assign the lower volume value based on the comparison
data.higherCol := data.isBuyGreater ? C_Up : C_Down //
Assign the color for the higher volume bar based on the comparison
data.lowerCol := data.isBuyGreater ? C_Down : C_Up //
Assign the color for the lower volume bar based on the comparison
data
//------------------------------------------
// Get volume data |
//------------------------------------------
// Instantiate OHLCV without explicit values (uses defaults)
ohlcv = OHLCV.new()
volData = calcVolumes(ohlcv)
//------------------------------------------
// Draw volume levels on the candlesticks |
//------------------------------------------
// Define base and value for gradient candles
float base = na,float value = na
bool uc = usecandle and sup
// Calculate base and value based on buy/sell volume and open/close relationship
if volData.isBuyGreater
base := math.min(ohlcv.O, ohlcv.C) // Start from the lower of open/close for
buy
value := base + math.abs(ohlcv.O - ohlcv.C) * (volData.pcBuy / 100) // Extend
to the percentage of buy volume
else
base := math.max(ohlcv.O, ohlcv.C) // Start from the higher of open/close for
sell
value := base - math.abs(ohlcv.O - ohlcv.C) * (volData.pcSell / 100) // Extend
to the percentage of sell volume
//---------------------------------------------------------------------------------
------------------------------------}
// Settings
//---------------------------------------------------------------------------------
------------------------------------{
pcTP = 'displays the price level of the highest traded activity/money flow or the
changes of the price levels with the highest traded activity/money flow'
rpPC = input.string('Last(Zone)', ' Level of Significance', options =
['Developing', 'Last(Line)', 'Last(Zone)', 'None'], inline='PoC', group = othGR,
tooltip = pcTP, display = disp)
spTT = 'displays the price zone of the highest bullish or bearish sentiment zone'
spPC = input.bool(false, 'Highest Sentiment Zone', inline = 'spP', group = othGR,
tooltip = spTT)
rpNR = input.int(25, ' Number of Rows' , minval = 10, maxval = 100 ,step = 5,
group = otGR, tooltip = 'option range [10-100]', display = disp)
rpW = input.int(10, ' Profile Width %', minval = 10, maxval = 50, group = otGR,
tooltip = 'option range [10-50]', display = disp) / 100
vpLS = input.string('Auto', " Profile Text Size", options=['Auto', 'Tiny',
'Small'], group = otGR, display = disp)
vpHO = input.int(05, ' Profile Horizontal Offset', group = otGR, tooltip =
'option allows negative numbers as well, in case of a use the profiles will overlap
with the price chart', display = disp)
//---------------------------------------------------------------------------------
------------------------------------}
// User Defined Types
//---------------------------------------------------------------------------------
------------------------------------{
type bar
float o = open
float h = high
float l = low
float c = close
float v = volume
int i = bar_index
int n = bar_index
int t = time
//---------------------------------------------------------------------------------
------------------------------------}
// Variables
//---------------------------------------------------------------------------------
------------------------------------{
bar b = bar.new()
//---------------------------------------------------------------------------------
------------------------------------}
// Functions/Methods
//---------------------------------------------------------------------------------
------------------------------------{