Nothing Special   »   [go: up one dir, main page]

Bursa

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// � BURSATRENDBANDCHART

//@version=5
indicator(title = 'TrendBand PriceVolume', shorttitle = 'TrendBandPriceVol', format
= format.volume)

// Function to get sector only from bs.getSector()


f_strRightOf(_str, _of) =>
// string _str: string to separate.
// string _op : separator character.
string[] _chars = str.split(_str, "")
int _len = array.size(_chars)
int _ofPos = array.indexof(_chars, _of)
string[] _substr = array.new_string(0)
if _ofPos >= 0 and _ofPos < _len - 1
_substr := array.slice(_chars, _ofPos + 1, _len)
string _return = array.join(_substr, "")

// ����� Function returning the sub-string of `_str` to the left of the `_of`
separating character.
f_strLeftOf(_str, _of) =>
// string _str: string to separate.
// string _op : separator character.
string[] _chars = str.split(_str, "")
int _len = array.size(_chars)
int _ofPos = array.indexof(_chars, _of)
string[] _substr = array.new_string(0)
if _ofPos > 0 and _ofPos <= _len - 1
_substr := array.slice(_chars, 0, _ofPos)
string _return = array.join(_substr, "")

// Shariah Status
import BURSATRENDBANDCHART/bursamalaysianonshariah/7 as s
shariah = s.status()
status_text =
shariah == 0 ? syminfo.ticker + " [S]" :
shariah == 1 ? syminfo.ticker + " [NS]" :
syminfo.ticker

// Sector for ticker


import Lanzhu0506/Bursa_Sector/11 as bs
sector = bs.getSector()

// User input
var string GP2 = 'Display Panel'
i_tableoption = input.bool(true, 'Horizontal', inline = '10', group = GP2)
sector_input = input.bool(true, 'Sector', inline = '10', group = GP2)
string i_tablepos = input.string(
position.top_right, title = 'Position', inline = '11',
options = [
position.bottom_center, position.bottom_left, position.bottom_right,
position.middle_center,position.middle_left, position.middle_right,
position.top_center,position.top_left,position.top_right
],
group = GP2)
string i_textsize = input.string(
size.small, 'Size', inline = '11',
options = [size.auto, size.tiny, size.small, size.normal],
group = GP2)
texts = input.color(color.new(color.green, 0), 'Shariah', group = 'Text Color',
inline = '2')
textns = input.color(color.new(color.red, 0), 'Non-Shariah', group = 'Text Color',
inline = '2')
textna = input.color(color.new(#9598a1, 0), 'Rest of the world', group = 'Text
Color', inline = '2')
showMA = input.bool(true, group = 'PV INPUT', inline = '1')
Value = input.int(30, group = 'PV INPUT', inline = '1')
barColorsOnPrevClose = input.bool(title = 'Color bars based on previous close',
defval = false, group = 'PV INPUT', inline = '1')

// Calculation
avdt = close * volume
sma_1 = ta.sma(avdt, Value)
spike = avdt > ta.highest(avdt, 5)[1] and high > high[1] and close > ta.sma(close,
5) and close > open // and avdt > ta.sma(avdt, 30)
supply = avdt > avdt[1] and close < open and high > ta.ema(close, 8) and
ta.ema(close, 8) > ta.ema(close, 21)
palette =
spike? color.new(#06f806, 50) :
supply? color.new(#d1d4dc, 50) :
barColorsOnPrevClose? close[1] > close? color.new(color.red, 50) :
color.new(color.green, 50) :
open > close ? color.new(color.red, 50) :
color.new(color.green, 50)

// Plot circle
plot(showMA ? sma_1 : na, style = plot.style_line, color = color.new(color.purple,
55), title = 'Volume MA')
plot(avdt, color=palette, title = 'Volume Bar', style = plot.style_columns)
plot(spike ? avdt / 2 : na, title = 'bullish', style = plot.style_circles,
linewidth = 3, color = color.new(color.blue, 0))
plot(supply ? avdt / 2 : na, title = 'bearish', style = plot.style_circles,
linewidth = 3, color = color.new(color.black, 0))

// Get financial data


fadata = syminfo.type == 'stock'? syminfo.tickerid : 'BATS:MSFT'
r = request.financial(fadata, 'TOTAL_REVENUE', 'FQ')
f = request.financial(fadata, 'NET_INCOME', 'FQ')
g = request.financial(fadata, 'NET_INCOME_MGN_ONE_YEAR_GROWTH', 'FQ')
mc = request.financial(fadata, 'TOTAL_SHARES_OUTSTANDING', 'FY')
currency = syminfo.currency

// Unfortunately, this library does not return correct sector for warrant
warrant = na(f_strLeftOf(syminfo.ticker,'-'))

// Array for table contents


av = array.new_string()
array.push(av, status_text)
if warrant and sector_input and shariah != 2
array.push(av, f_strRightOf(sector, ':'))
array.push(av, "MCAP : " + currency + " " + str.tostring(mc * close,format.volume))
array.push(av, "REV : " + currency + " " + str.tostring(r, format.volume))
array.push(av, "NP : " + str.tostring(g,format.percent))

// Plot table - horizontal or vertical


if barstate.islast and i_tableoption and syminfo.type == 'stock'
table panelnote1 = table.new(position = i_tablepos , rows = 1, columns =
array.size(av), bgcolor = na, border_width = 0, frame_width = 0)
for x = 0 to array.size(av)-1
table.cell(
panelnote1, x, 0,
array.get(av,x), bgcolor = na, text_halign = text.align_center,
text_size = i_textsize, text_color = x != 4 and shariah == 0 ? texts: x !=
4 and shariah == 1 ? textns : x != 3 and shariah == 2 ? textna :
g < 0 and x == 4 or g < 0 and x == 3 ? color.red : g > 0 and x == 4 or g >
0 and x == 3? color.green :
textna
)

if barstate.islast and not i_tableoption and syminfo.type == 'stock'


table panelnote2 = table.new(position = i_tablepos , rows = array.size(av),
columns = 1, bgcolor = na, border_width = 0, border_color = color.black,
frame_width = 0)
for x = 0 to array.size(av)-1
table.cell(
panelnote2, 0, x,
array.get(av,x), bgcolor = na, text_halign = text.align_left,
text_size = i_textsize, text_color = x != 4 and shariah == 0 ? texts: x !=
4 and shariah == 1 ? textns : x != 3 and shariah == 2 ? textna :
g < 0 and x == 4 or g < 0 and x == 3 ? color.red : g > 0 and x == 4 or g >
0 and x == 3? color.green :
textna
)

//Send alert if condition is true


if spike
alertspike = syminfo.tickerid + '\nVolume increase! Look for possible bullish
signal'
alert(message = alertspike, freq = alert.freq_once_per_bar)
if supply
alertsupply = syminfo.tickerid + '\nVolume increase! Look for possible bullish
signal'
alert(message = alertsupply, freq = alert.freq_once_per_bar)

//Send alert by individual


alertcondition(spike, title = '1. Bullish Signal', message = '{{ticker}}, Volume
increase! Look for possible bullish signal')
alertcondition(supply, title = '2. Bearish Signal', message = '{{ticker}}, Volume
increase! Look for possible bearish signal')

You might also like