0% found this document useful (0 votes)
111 views4 pages

Gladiator

This document contains source code for a technical analysis indicator called the Viswanath Trend Detector. It uses calculations like RSI, CMO, pivots, and ATR to identify support and resistance levels and plot them as colored lines on the chart. It also includes code for additional indicators like Elder Ray Index, Candle Meter, and fast/slow crossover signals to help determine market momentum and trends. Global variables can be used to customize inputs for calculations like moving average periods and indicator display options.

Uploaded by

Viswanath Palyam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views4 pages

Gladiator

This document contains source code for a technical analysis indicator called the Viswanath Trend Detector. It uses calculations like RSI, CMO, pivots, and ATR to identify support and resistance levels and plot them as colored lines on the chart. It also includes code for additional indicators like Elder Ray Index, Candle Meter, and fast/slow crossover signals to help determine market momentum and trends. Global variables can be used to customize inputs for calculations like moving average periods and indicator display options.

Uploaded by

Viswanath Palyam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

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

0 at
https://mo2i!la.org/MPL/2.0/
// � CRYPTO WITH VISWANATH
//@version=4
study("VISWANATH TREND DITECTOR", shorttitle="VISWANATH TREND DITECTOR",
overlay=true, scale = scale.right, linktoseries = true)
line_width = input(4, type = input.integer, title="SR Level line Width")
level_min_lengh = input(4, type = input.integer, title="Set minimum number of bars
from level start to qualify a level")
y = input("Orange", "Line Color", options=["Red", "Lime", "Orange", "Teal",
"Yellow", "White", "Black"])
line_extend = input(false, type = input.bool, title = "Extend Level line Right") ?
extend.right : extend.none
sr_tf = input("", type = input.resolution, title="SR Timeframe (Beta)")

//color function
colour(z) => z=="Red"?color.red:z=="Lime"?color.lime:z=="Orange"?
color.orange:z=="Teal"?
color.teal:z=="Yellow"?color.yellow:z=="Black"?color.black:color.white

//Legacy RSI calc


rsi_src = close, len = 9
up1 = rma(max(change(rsi_src), 0), len)
down1 = rma(-min(change(rsi_src), 0), len)
legacy_rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))

//CMO based on HMA


length = 1
src1 = hma(open, 5)[1] // legacy hma(5) calculation gives a resul with one candel
shift, thus use hma()[1]
src2 = hma(close, 12)
momm1 = change(src1)
momm2 = change(src2)
f1(m, n) => m >= n ? m : 0.0
f2(m, n) => m >= n ? 0.0 : -m
m1 = f1(momm1, momm2)
m2 = f2(momm1, momm2)
sm1 = sum(m1, length)
sm2 = sum(m2, length)
percent(nom, div) => 100 * nom / div
cmo_new = percent(sm1-sm2, sm1+sm2)

//Legacy Close Pivots calcs.


len5 = 2
h = highest(len5)
h1 = dev(h, len5) ? na : h
hpivot = fixnan(h1)
l = lowest(len5)
l1 = dev(l, len5) ? na : l
lpivot = fixnan(l1)

//Calc Values

rsi_new = rsi(close,9)
lpivot_new = lpivot // use legacy pivots calculation as integrated
pivotlow/pivothigh functions give very different result
hpivot_new = hpivot

sup = rsi_new < 25 and cmo_new > 50 and lpivot_new


res = rsi_new > 75 and cmo_new < -50 and hpivot_new
calcXup() =>
var xup = 0.0
xup := sup ? low : xup[1]
calcXdown() =>
var xdown = 0.0
xdown := res ? high : xdown[1]

//Lines drawing variables


tf1 = security(syminfo.tickerid, sr_tf, calcXup(), lookahead=barmerge.lookahead_on)
tf2 = security(syminfo.tickerid, sr_tf, calcXdown(),
lookahead=barmerge.lookahead_on)

//SR Line plotting


var tf1_line = line.new(0, 0, 0, 0)
var tf1_bi_start = 0
var tf1_bi_end = 0
tf1_bi_start := change(tf1) ? bar_index : tf1_bi_start[1]
tf1_bi_end := change(tf1) ? tf1_bi_start : bar_index
if change(tf1)
if (line.get_x2(tf1_line) - line.get_x1(tf1_line)) < level_min_lengh
line.delete(tf1_line)
tf1_line := line.new(tf1_bi_start, tf1, tf1_bi_end, tf1, color = colour(y),
width = line_width, extend = line_extend)
line.set_x2(tf1_line, tf1_bi_end)

var tf2_line = line.new(0, 0, 0, 0)


var tf2_bi_start = 0
var tf2_bi_end = 0
tf2_bi_start := change(tf2) ? bar_index : tf2_bi_start[1]
tf2_bi_end := change(tf2) ? tf2_bi_start : bar_index
if change(tf2)
if (line.get_x2(tf2_line) - line.get_x1(tf2_line)) < level_min_lengh
line.delete(tf2_line)
tf2_line := line.new(tf2_bi_start, tf2, tf2_bi_end, tf2, color = colour(y),
width = line_width, extend = line_extend)
line.set_x2(tf2_line, tf2_bi_end)

alertcondition(change(tf1) != 0 or change(tf2) != 0 , message = "New S/R line" )

CCI = input(50)
ATR = input(5)
Multiplierc=input(1,title='ATR Multiplier')
original=input(true,title='original coloring')
thisCCI = cci(close, CCI)
lastCCI = nz(thisCCI[1])
bufferDn= high + Multiplierc * sma(tr,ATR)
bufferUp= low - Multiplierc * sma(tr,ATR)
if (thisCCI >= 0 and lastCCI < 0)
bufferUp := bufferDn[1]
if (thisCCI <= 0 and lastCCI > 0)
bufferDn := bufferUp[1]

if (thisCCI >= 0)
if (bufferUp < bufferUp[1])
bufferUp := bufferUp[1]
else
if (thisCCI <= 0)
if (bufferDn > bufferDn[1])
bufferDn := bufferDn[1]
x=0.0
x:=thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]
swap=0.0

swap:=x>x[1]?1:x<x[1]?-1:swap[1]

swap2=swap==1?color.lime:color.red
swap3=thisCCI >=0 ?color.lime:color.red
swap4=original?swap3:swap2
plot(x,color=swap4,transp=0,linewidth=3)

//global input variables


bull_bear_power_standard_length = 13
bull_bear_power_smoothing_length = 1

total_power_fast_length = input(title="Fast MA Period", type=input.integer,


defval=12, minval=1)
total_power_slow_length = input(title="Slow MA Period", type=input.integer,
defval=50, minval=1)

display_box_last_label = input(title="Display boxes for last candle",


type=input.bool, defval=true)
display_crossover_signals = input(title="Display slow / fast crossover (o)",
type=input.bool, defval=true)

//
###################################################################################
#############################
//ELDER RAY INDEX INDICATOR
//
###################################################################################
#############################

average_price = ema(close, bull_bear_power_standard_length)


bull_power_raw = high - average_price
bear_power_raw = low - average_price

bull_power = ema( bull_power_raw, bull_bear_power_smoothing_length)


bear_power = ema( bear_power_raw, bull_bear_power_smoothing_length)

total_power_raw = bull_power + bear_power

//
###################################################################################
#############################
// CANDLE METER INDICATOR
//
###################################################################################
#############################

bulls_dominating = high >= average_price and low >= average_price


bears_dominating = high <= average_price and low <= average_price
bears_bulls_fighting = high >= average_price and low <= average_price

bull_power_absolute = ema( abs(bull_power_raw), bull_bear_power_smoothing_length)


bear_power_absolute = ema( abs(bear_power_raw), bull_bear_power_smoothing_length)
bull_power_percent = round(100 * bull_power_absolute / (bull_power_absolute +
bear_power_absolute))
bear_power_percent = 100 - bull_power_percent

total_power_fast = ema(total_power_raw, total_power_fast_length)


total_power_slow = ema(total_power_raw, total_power_slow_length)
crossover_fast_slow = crossover(total_power_fast, total_power_slow)
crossunder_fast_slow = crossunder(total_power_fast, total_power_slow)

bulls_winning = bull_power_percent >= 50


bears_winning = bear_power_percent >= 50
bulls_take_over = bulls_dominating and not bulls_dominating[1]
bears_take_over = bears_dominating and not bears_dominating[1]

//
###################################################################################
#############################
// PLOT CANDLE LABELS
//
###################################################################################
#############################

// init label variables


var label l_bear_candle = na
var label l_bull_candle = na

// variables for colors


bear_label_color = bears_winning ?color.red : color.silver

bull_label_color = bulls_winning ? color.blue : color.silver

// init label variables


var table top_boxes = table.new(position.top_right, 4, 2, border_width=3)

if barstate.islast and display_box_last_label

table.cell (table_id = top_boxes, column =0, row =0, text ="VISWANATH",


bgcolor=color.new(color.gray, 0), text_color=color.white, width=10, height=10)
table.cell(top_boxes, 1, 0, text="Bullish: "+tostring(bull_power_percent),
bgcolor=color.new(color.blue,0), text_color=color.white, width=8, height=10)
table.cell(top_boxes, 2, 0, text="Bearish:
"+tostring(bear_power_percent),bgcolor=color.new(color.red, 0),
text_color=color.white, width=8, height=10)

plotshape(display_crossover_signals and crossover_fast_slow, title="Buy signal",


style=shape.triangleup, location=location.belowbar, color=color.blue,
size=size.small)

plotshape(display_crossover_signals and crossunder_fast_slow, title="Sell signal",


style=shape.triangledown, location=location.abovebar, color=color.red,
size=size.small)

You might also like